about summary refs log tree commit diff
path: root/nixos/lib/eval-config.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2023-05-07 15:33:47 +0200
committerRobert Hensing <robert@roberthensing.nl>2023-05-10 15:55:09 +0200
commit693e2c32871dcea7fe2ef455ee77571d3a117499 (patch)
treecf278a78cffdabfb5607c0f18af184c63f11a6c7 /nixos/lib/eval-config.nix
parent6e594fedb353d8c75e0ee0527e2d821d30568c82 (diff)
nixos/eval-config: Remove statically known mkIf
mkIf is unnecessary when the condition is statically known - that is
knowable before entering the module evaluation.

By changing this to a precomputed module, we support changing the
defined options to readOnly options.
Diffstat (limited to 'nixos/lib/eval-config.nix')
-rw-r--r--nixos/lib/eval-config.nix24
1 files changed, 15 insertions, 9 deletions
diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix
index 1e086271e5236..058ab7280ccc3 100644
--- a/nixos/lib/eval-config.nix
+++ b/nixos/lib/eval-config.nix
@@ -38,6 +38,8 @@ let pkgs_ = pkgs;
 in
 
 let
+  inherit (lib) optional;
+
   evalModulesMinimal = (import ./default.nix {
     inherit lib;
     # Implicit use of feature is noted in implementation.
@@ -47,15 +49,19 @@ let
   pkgsModule = rec {
     _file = ./eval-config.nix;
     key = _file;
-    config = {
-      # Explicit `nixpkgs.system` or `nixpkgs.localSystem` should override
-      # this.  Since the latter defaults to the former, the former should
-      # default to the argument. That way this new default could propagate all
-      # they way through, but has the last priority behind everything else.
-      nixpkgs.system = lib.mkIf (system != null) (lib.mkDefault system);
-
-      _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_);
-    };
+    config = lib.mkMerge (
+      (optional (system != null) {
+        # Explicit `nixpkgs.system` or `nixpkgs.localSystem` should override
+        # this.  Since the latter defaults to the former, the former should
+        # default to the argument. That way this new default could propagate all
+        # they way through, but has the last priority behind everything else.
+        nixpkgs.system = lib.mkDefault system;
+      })
+      ++
+      (optional (pkgs_ != null) {
+        _module.args.pkgs = lib.mkForce pkgs_;
+      })
+    );
   };
 
   withWarnings = x: