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'. 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/pistol.nix
./programs/piston-cli.nix ./programs/piston-cli.nix
./programs/pls.nix ./programs/pls.nix
./programs/poetry.nix
./programs/powerline-go.nix ./programs/powerline-go.nix
./programs/pqiv.nix ./programs/pqiv.nix
./programs/pubs.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/pet
./modules/programs/pistol ./modules/programs/pistol
./modules/programs/pls ./modules/programs/pls
./modules/programs/poetry
./modules/programs/powerline-go ./modules/programs/powerline-go
./modules/programs/pubs ./modules/programs/pubs
./modules/programs/pyenv ./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;
}