:feat: add python packages option

nixos
Moritz Böhme 2022-09-01 11:11:11 +02:00
parent 9068cd341b
commit 7502fed241
1 changed files with 19 additions and 3 deletions

View File

@ -7,19 +7,35 @@
with lib; with lib;
let let
cfg = config.my.programs.python; cfg = config.my.programs.python;
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);
in in
{ {
options.my.programs.python = { options.my.programs.python = {
enable = mkEnableOption "python"; enable = mkEnableOption "python";
versions = mkOption { versions = mkOption {
default = [ "python310" ]; default = [ "python310" ];
type = with types; listOf str; type = with types; nonEmptyListOf (enum pythonVersions);
example = [ "python39" ]; example = [ "python39" ];
apply = builtins.map (version: pkgs.${version}.withPackages (packages: with packages; [ black pyflakes isort nose pytest python-lsp-server ])); };
packages = mkOption {
default = [ "isort" "pytest" "flake8" "python-lsp-server" ];
type = with types; listOf (enum commonPackages);
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home-manager.users.moritz.home.packages = cfg.versions; users.users.moritz.packages = map (mkPython cfg.packages) cfg.versions;
}; };
} }