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 {
|
2022-10-15 20:00:09 +02:00
|
|
|
default = [
|
|
|
|
"flake8"
|
|
|
|
"isort"
|
|
|
|
"mypy"
|
|
|
|
"poetry"
|
|
|
|
"pytest"
|
|
|
|
"python-lsp-server"
|
|
|
|
];
|
2022-09-01 11:11:11 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
}
|