poetry: add module

This commit is contained in:
Mirko Lenz 2024-02-24 17:39:35 +01:00 committed by Robert Helgesson
parent 2846d5230a
commit 670d9ecc3e
No known key found for this signature in database
GPG Key ID: 96E745BD17AA17ED
7 changed files with 113 additions and 0 deletions

View File

@ -1506,6 +1506,16 @@ in {
A new module is available: 'services.remmina'.
'';
}
{
time = "2024-04-21T20:53:09+00:00";
message = ''
A new module is available: 'programs.poetry'.
Poetry is a tool that helps you manage Python project dependencies and
packages. See https://python-poetry.org/ for more.
'';
}
];
};
}

View File

@ -186,6 +186,7 @@ let
./programs/pistol.nix
./programs/piston-cli.nix
./programs/pls.nix
./programs/poetry.nix
./programs/powerline-go.nix
./programs/pqiv.nix
./programs/pubs.nix

View File

@ -0,0 +1,55 @@
{ pkgs, config, lib, ... }:
let
inherit (lib) mkEnableOption mkPackageOption mkOption literalExpression;
tomlFormat = pkgs.formats.toml { };
configDir = if pkgs.stdenv.isDarwin then
"Library/Application Support"
else
config.xdg.configHome;
cfg = config.programs.poetry;
in {
meta.maintainers = with lib.maintainers; [ mirkolenz ];
options.programs.poetry = {
enable = mkEnableOption "poetry";
package = mkPackageOption pkgs "poetry" {
example = "pkgs.poetry.withPlugins (ps: with ps; [ poetry-plugin-up ])";
extraDescription = "May be used to install custom poetry plugins.";
};
settings = mkOption {
type = tomlFormat.type;
default = { };
example = literalExpression ''
{
virtualenvs.create = true;
virtualenvs.in-project = true;
}
'';
description = ''
Configuration written to
{file}`$XDG_CONFIG_HOME/pypoetry/config.toml` on Linux or
{file}`$HOME/Library/Application Support/pypoetry/config.toml` on Darwin.
See
<https://python-poetry.org/docs/configuration/>
for more information.
'';
};
};
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
home.file."${configDir}/pypoetry/config.toml" =
lib.mkIf (cfg.settings != { }) {
source = tomlFormat.generate "poetry-config" cfg.settings;
};
};
}

View File

@ -122,6 +122,7 @@ in import nmtSrc {
./modules/programs/pet
./modules/programs/pistol
./modules/programs/pls
./modules/programs/poetry
./modules/programs/powerline-go
./modules/programs/pubs
./modules/programs/pyenv

View File

@ -0,0 +1,27 @@
{ pkgs, ... }:
{
programs.poetry = {
enable = true;
settings = {
virtualenvs.create = true;
virtualenvs.in-project = true;
};
};
test.stubs.poetry = { };
nmt.script = let
expectedConfDir =
if pkgs.stdenv.isDarwin then "Library/Application Support" else ".config";
expectedConfigPath = "home-files/${expectedConfDir}/pypoetry/config.toml";
expectedConfigContent = pkgs.writeText "poetry.config-custom.expected" ''
[virtualenvs]
create = true
in-project = true
'';
in ''
assertFileExists "${expectedConfigPath}"
assertFileContent "${expectedConfigPath}" "${expectedConfigContent}"
'';
}

View File

@ -0,0 +1,15 @@
{ pkgs, ... }:
{
programs.poetry = { enable = true; };
test.stubs.poetry = { };
nmt.script = let
expectedConfDir =
if pkgs.stdenv.isDarwin then "Library/Application Support" else ".config";
expectedConfigPath = "home-files/${expectedConfDir}/pypoetry/config.toml";
in ''
assertPathNotExists "${expectedConfigPath}"
'';
}

View File

@ -0,0 +1,4 @@
{
poetry-default-settings = ./default-settings.nix;
poetry-custom-settings = ./custom-settings.nix;
}