From 26ebbf7ae154441847203b8f52d6c10741104f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Thu, 1 Sep 2022 11:11:11 +0200 Subject: [PATCH] :rocket: add python packages option --- modules/programs/python.nix | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/modules/programs/python.nix b/modules/programs/python.nix index 39fd7f2..7480cb5 100644 --- a/modules/programs/python.nix +++ b/modules/programs/python.nix @@ -7,19 +7,35 @@ with lib; let 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 { options.my.programs.python = { enable = mkEnableOption "python"; versions = mkOption { default = [ "python310" ]; - type = with types; listOf str; + type = with types; nonEmptyListOf (enum pythonVersions); 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 { - home-manager.users.moritz.home.packages = cfg.versions; + users.users.moritz.packages = map (mkPython cfg.packages) cfg.versions; }; }