Files
nix-stuff/common/package-set.nix
2024-09-14 14:40:20 -07:00

75 lines
1.6 KiB
Nix

{
config,
pkgs,
lib,
...
}:
let
inherit (lib) mkOption types;
pkgOptions = builtins.attrValues config.vacu.packages;
enabledOptions = builtins.filter (o: o.enable) pkgOptions;
enabledPkgs = builtins.map (o: o.package) enabledOptions;
packagesSetType = types.attrsOf (
types.submodule (
{
name,
...
}:
{
options = {
enable = mkOption {
type = types.bool;
description = "Will this package be installed (included in environment.systemPackages)";
};
package = mkOption {
type = types.package;
default = pkgs.${name};
defaultText = "pkgs.${name}";
};
};
}
)
);
packageListToSet = (
from:
let
keyvals = map (
val:
if builtins.isString val then
{
name = val;
value = {
package = pkgs."${val}";
enable = lib.mkDefault true;
};
}
else
{
name = val.pname or val.name;
value = {
package = lib.mkDefault val;
enable = lib.mkDefault true;
};
}
) from;
in
builtins.listToAttrs keyvals
);
in
{
options = {
vacu.packages = mkOption {
default = { };
type = types.coercedTo (types.listOf (
types.either types.str types.package
)) packageListToSet packagesSetType;
};
vacu.packageList = mkOption {
type = types.listOf types.package;
readOnly = true;
};
};
config.vacu.packageList = enabledPkgs;
}