dotfiles/modules/programs/python.nix

42 lines
946 B
Nix
Raw Normal View History

2022-08-31 12:01:07 +02:00
{ config
, lib
, pkgs
, ...
}:
with lib;
let
cfg = config.my.programs.python;
2022-09-01 11:11:11 +02:00
mkPython = packages: version: pkgs.${version}.withPackages (ps: map (flip getAttr ps) packages);
pythonVersions = [
"python311"
"python310"
"python39"
"python38"
];
packageLists = map (version: attrNames pkgs."${version}Packages") cfg.versions;
commonPackages = foldl' intersectLists (head packageLists) (tail packageLists);
2022-08-31 12:01:07 +02:00
in
{
options.my.programs.python = {
enable = mkEnableOption "python";
versions = mkOption {
default = [ "python310" ];
2022-09-01 11:11:11 +02:00
type = with types; nonEmptyListOf (enum pythonVersions);
2022-08-31 12:01:07 +02:00
example = [ "python39" ];
2022-09-01 11:11:11 +02:00
};
packages = mkOption {
default = [ "isort" "pytest" "flake8" "python-lsp-server" ];
type = with types; listOf (enum commonPackages);
2022-08-31 12:01:07 +02:00
};
};
config = mkIf cfg.enable {
2022-09-01 11:11:11 +02:00
users.users.moritz.packages = map (mkPython cfg.packages) cfg.versions;
2022-08-31 12:01:07 +02:00
};
}