summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2023-06-23 19:17:36 +0200
committerGitHub <noreply@github.com>2023-06-23 19:17:36 +0200
commitb1ad9cd27d9917747fdcd829c3728c760d35f61d (patch)
treed9edc136eb8dfb8199a894f6573addb46b46c930 /lib/modules.nix
parent47a95511d383dafa2f998ea4279844ef7fabdfbe (diff)
parent895ac176341606688b864bc84312140c065db741 (diff)
downloadnixpkgs-b1ad9cd27d9917747fdcd829c3728c760d35f61d.tar
nixpkgs-b1ad9cd27d9917747fdcd829c3728c760d35f61d.tar.gz
nixpkgs-b1ad9cd27d9917747fdcd829c3728c760d35f61d.tar.bz2
nixpkgs-b1ad9cd27d9917747fdcd829c3728c760d35f61d.tar.lz
nixpkgs-b1ad9cd27d9917747fdcd829c3728c760d35f61d.tar.xz
nixpkgs-b1ad9cd27d9917747fdcd829c3728c760d35f61d.tar.zst
nixpkgs-b1ad9cd27d9917747fdcd829c3728c760d35f61d.zip
Merge pull request #238136 from hercules-ci/nixos-nixpkgs-dont-check-when-_module.args.pkgs-is-set
`nixos/nixpkgs`: Don't check when `_module.args.pkgs` is set
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 6acd59aaf54..0bedd28e877 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -904,6 +904,40 @@ let
     else opt // { type = opt.type.substSubModules opt.options; options = []; };
 
 
+  /*
+    Merge an option's definitions in a way that preserves the priority of the
+    individual attributes in the option value.
+
+    This does not account for all option semantics, such as readOnly.
+
+    Type:
+      option -> attrsOf { highestPrio, value }
+  */
+  mergeAttrDefinitionsWithPrio = opt:
+        let
+            defsByAttr =
+              lib.zipAttrs (
+                lib.concatLists (
+                  lib.concatMap
+                    ({ value, ... }@def:
+                      map
+                        (lib.mapAttrsToList (k: value: { ${k} = def // { inherit value; }; }))
+                        (pushDownProperties value)
+                    )
+                    opt.definitionsWithLocations
+                )
+              );
+        in
+          assert opt.type.name == "attrsOf" || opt.type.name == "lazyAttrsOf";
+          lib.mapAttrs
+                (k: v:
+                  let merging = lib.mergeDefinitions (opt.loc ++ [k]) opt.type.nestedTypes.elemType v;
+                  in {
+                    value = merging.mergedValue;
+                    inherit (merging.defsFinal') highestPrio;
+                  })
+                defsByAttr;
+
   /* Properties. */
 
   mkIf = condition: content:
@@ -1245,6 +1279,7 @@ private //
     importJSON
     importTOML
     mergeDefinitions
+    mergeAttrDefinitionsWithPrio
     mergeOptionDecls  # should be private?
     mkAfter
     mkAliasAndWrapDefinitions