dotfiles/modules/programs/python.nix

59 lines
1.5 KiB
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
2023-01-26 10:55:47 +01:00
pythonVersions = map (version: "3${toString version}") (range 8 11);
enabledVersions = filterAttrs (_: value: value.enable) cfg.versions;
2022-09-01 11:11:11 +02:00
2023-01-26 10:55:47 +01:00
pythonPackages = version: attrNames pkgs."python${version}Packages";
2022-09-01 11:11:11 +02:00
2023-01-26 10:55:47 +01:00
commonPackages =
let
packageLists = map pythonPackages (attrNames enabledVersions);
in
foldl' intersectLists (head packageLists) (tail packageLists);
2022-09-01 11:11:11 +02:00
2023-01-26 10:55:47 +01:00
versionOpts = version: {
enable = mkEnableOption (toString version);
pythonPackages = mkOption {
default = [ ];
type = with types; listOf (enum (pythonPackages version));
};
};
2022-08-31 12:01:07 +02:00
in
{
options.my.programs.python = {
2023-01-26 10:55:47 +01:00
versions = genAttrs pythonVersions versionOpts;
defaultPackages = mkOption {
default = [ ];
type = with types; listOf (enum commonPackages);
2022-09-01 11:11:11 +02:00
};
2023-01-26 10:55:47 +01:00
extraPackages = mkOption {
default = [ ];
2023-01-26 10:55:47 +01:00
type = with types; listOf package;
2022-08-31 12:01:07 +02:00
};
};
2023-01-26 10:55:47 +01:00
config = {
users.users.moritz.packages =
(
let
mkPython = version:
let
package = pkgs."python${version}";
finalPythonPackages = cfg.versions.${version}.pythonPackages ++ cfg.defaultPackages;
getPythonPackages = ps: map (flip getAttr ps) finalPythonPackages;
in
package.withPackages getPythonPackages;
in
map mkPython (attrNames enabledVersions)
) ++ cfg.extraPackages;
2022-08-31 12:01:07 +02:00
};
}