Files
nix-stuff/common/package-set.nix
Shelvacu 9bad53f188 nix fmt
2025-04-19 13:17:36 -07:00

81 lines
2.0 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.finalPackage) enabledOptions;
packagesSetType = types.attrsOf (
types.submodule (
{ name, config, ... }:
{
options = {
enable = mkOption {
type = types.bool;
default = false;
description = "Will this package be installed (included in environment.systemPackages)";
};
package = mkOption {
type = types.package;
default = pkgs.${name};
defaultText = "pkgs.${name}";
};
overrides = mkOption {
type = types.nullOr (types.attrsOf types.anything);
default = null;
};
finalPackage = mkOption {
type = types.package;
readOnly = true;
};
};
config.finalPackage =
if config.overrides == null then config.package else config.package.override config.overrides;
}
)
);
packageListToSet = (
from:
let
enable = lib.mkOverride 900 true; # more important than mkDefault, less important than setting explicitly
keyvals = map (
val:
if builtins.isString val then
{
name = val;
value = { inherit enable; };
}
else
{
name = val.pname or val.name;
value = {
package = lib.mkDefault val;
inherit enable;
};
}
) 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;
}