mkRedundantOption

This commit is contained in:
greyweather committed 2026-09-01 18:32:37 +01:00
1 parent cd4a4c6198
commit c61e1c1778
1 file changed
+17 -7
+17 -7
View File
@@ -5,8 +5,10 @@
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
outputs = { self, nixpkgs }: rec {
mkIfElse = with nixpkgs.lib; p: yes: no: mkMerge [
outputs = { self, nixpkgs }: let
inherit (nixpkgs) lib;
in rec {
mkIfElse = with lib; p: yes: no: mkMerge [
(mkIf p yes)
(mkIf (!p) no)
];
@@ -20,9 +22,9 @@
fi
'';
attrByStrPath = strPath: set: nixpkgs.lib.attrByPath (nixpkgs.lib.strings.splitString "." strPath) null set;
attrByStrPath = strPath: set: lib.attrByPath (lib.strings.splitString "." strPath) null set;
setAttrByStrPath = strPath: value: nixpkgs.lib.setAttrByPath (nixpkgs.lib.strings.splitString "." strPath) value;
setAttrByStrPath = strPath: value: lib.setAttrByPath (lib.strings.splitString "." strPath) value;
homeFilesFromStringAttrs = { dir, attrs, exec ? false }: mergeListsToAttrs (map (x: "${dir}/${x}") (builtins.attrNames attrs)) (map (y: {
text = y;
@@ -37,11 +39,11 @@
exec = true;
};
mergeListsToAttrs = names: values: nixpkgs.lib.listToAttrs (nixpkgs.lib.zipListsWith (name: value: { inherit name value; }) names values);
mergeListsToAttrs = names: values: lib.listToAttrs (lib.zipListsWith (name: value: { inherit name value; }) names values);
mkEnumFromDirContents = dir: nixpkgs.lib.types.enum (map (name: nixpkgs.lib.removeSuffix ".nix" name) (builtins.attrNames (builtins.readDir dir)));
mkEnumFromDirContents = dir: lib.types.enum (map (name: lib.removeSuffix ".nix" name) (builtins.attrNames (builtins.readDir dir)));
mkOptionalListOfType = type: nixpkgs.lib.types.either (type) (nixpkgs.lib.types.listOf (type));
mkOptionalListOfType = type: lib.types.either (type) (lib.types.listOf (type));
mkMirroredModulesFlakeModule = moduleName: func: {
flake.nixosModules.${moduleName} = func;
@@ -50,5 +52,13 @@
};
mkRedundantOptionDescription = name: value: "The functionality of this option completely depends on `${name}` being `${value}`, and will not be evaluated otherwise.";
mkRedundantOption = name: value: attrs: lib.mkOption {
inherit (attrs) type default;
description = ''
${attrs.description}
${mkRedundantOptionDescription name value}
'';
};
};
}