about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2023-12-30 11:26:21 +0100
committerGitHub <noreply@github.com>2023-12-30 11:26:21 +0100
commit1f1cd8303f9a063e06ba128a2c63fe856b560584 (patch)
tree10da5ff3a078f0119c93973e044ec03f89c6de92
parent8838f2f857e0193df058d8104f883b0d70763dbd (diff)
parent47d6b21930a651faf1fd9f217423281c5332dc9f (diff)
Merge pull request #273942 from r-vdp/nixos_system_lib_arg
flake: allow specifying the lib argument to nixosSystem
-rw-r--r--flake.nix28
1 files changed, 25 insertions, 3 deletions
diff --git a/flake.nix b/flake.nix
index f16bc7d05fce2..580f572ff32c6 100644
--- a/flake.nix
+++ b/flake.nix
@@ -21,16 +21,38 @@
 
         nixosSystem = args:
           import ./nixos/lib/eval-config.nix (
-            args // { inherit (self) lib; } // lib.optionalAttrs (! args?system) {
+            {
+              lib = final;
               # Allow system to be set modularly in nixpkgs.system.
               # We set it to null, to remove the "legacy" entrypoint's
               # non-hermetic default.
               system = null;
-            }
+            } // args
           );
       });
 
-      checks.x86_64-linux.tarball = jobs.tarball;
+      checks.x86_64-linux = {
+        tarball = jobs.tarball;
+        # Test that ensures that the nixosSystem function can accept a lib argument
+        # Note: prefer not to extend or modify `lib`, especially if you want to share reusable modules
+        #       alternatives include: `import` a file, or put a custom library in an option or in `_module.args.<libname>`
+        nixosSystemAcceptsLib = (self.lib.nixosSystem {
+          lib = self.lib.extend (final: prev: {
+            ifThisFunctionIsMissingTheTestFails = final.id;
+          });
+          modules = [
+            ./nixos/modules/profiles/minimal.nix
+            ({ lib, ... }: lib.ifThisFunctionIsMissingTheTestFails {
+              # Define a minimal config without eval warnings
+              nixpkgs.hostPlatform = "x86_64-linux";
+              boot.loader.grub.enable = false;
+              fileSystems."/".device = "nodev";
+              # See https://search.nixos.org/options?show=system.stateVersion&query=stateversion
+              system.stateVersion = lib.versions.majorMinor lib.version; # DON'T do this in real configs!
+            })
+          ];
+        }).config.system.build.toplevel;
+      };
 
       htmlDocs = {
         nixpkgsManual = jobs.manual;