From 1bd4da1848cb7b68858ebb2ca1f8b0e5fed46c58 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Fri, 20 Sep 2024 09:11:32 +0100 Subject: [PATCH 1/2] nixos/nixpkgs: fix `config` assertion text The assertion message should include the `nixpkgs.config` value, however it currently includes the entire `nixpkgs.config` _option_. This means the type, declarations, definitions, etc were all printed. --- nixos/modules/misc/nixpkgs.nix | 2 +- nixos/modules/misc/nixpkgs/test.nix | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index 44903a15c5ca0..f83ab9e59cf87 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -386,7 +386,7 @@ in `nixpkgs.config` options should be passed when creating the instance instead. Current value: - ${lib.generators.toPretty { multiline = true; } opt.config} + ${lib.generators.toPretty { multiline = true; } cfg.config} ''; } ]; diff --git a/nixos/modules/misc/nixpkgs/test.nix b/nixos/modules/misc/nixpkgs/test.nix index be9a88a077887..a2cb2f834776c 100644 --- a/nixos/modules/misc/nixpkgs/test.nix +++ b/nixos/modules/misc/nixpkgs/test.nix @@ -16,6 +16,10 @@ let nixpkgs.hostPlatform = "aarch64-linux"; nixpkgs.buildPlatform = "aarch64-linux"; }; + externalPkgsWithConfig = { + nixpkgs.pkgs = pkgs; + nixpkgs.config.allowUnfree = true; + }; ambiguous = { _file = "ambiguous.nix"; nixpkgs.hostPlatform = "aarch64-linux"; @@ -108,6 +112,17 @@ lib.recurseIntoAttrs { For a future proof system configuration, we recommend to remove the legacy definitions. '']; + assert builtins.trace (lib.head (getErrors externalPkgsWithConfig)) + getErrors externalPkgsWithConfig == + ['' + Your system configures nixpkgs with an externally created instance. + `nixpkgs.config` options should be passed when creating the instance instead. + + Current value: + { + allowUnfree = true; + } + '']; assert getErrors { nixpkgs.localSystem = pkgs.stdenv.hostPlatform; nixpkgs.hostPlatform = pkgs.stdenv.hostPlatform; From 6d9dfef94ffd59a327573eea7bc709a84c44b3d2 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Fri, 20 Sep 2024 09:25:37 +0100 Subject: [PATCH 2/2] nixos/nixpkgs: show definition files in `config` assertion --- nixos/modules/misc/nixpkgs.nix | 3 +++ nixos/modules/misc/nixpkgs/test.nix | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index f83ab9e59cf87..4048fd6857378 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -387,6 +387,9 @@ in Current value: ${lib.generators.toPretty { multiline = true; } cfg.config} + + Defined in: + ${lib.concatMapStringsSep "\n" (file: " - ${file}") opt.config.files} ''; } ]; diff --git a/nixos/modules/misc/nixpkgs/test.nix b/nixos/modules/misc/nixpkgs/test.nix index a2cb2f834776c..e70b7a12e8dd7 100644 --- a/nixos/modules/misc/nixpkgs/test.nix +++ b/nixos/modules/misc/nixpkgs/test.nix @@ -17,6 +17,7 @@ let nixpkgs.buildPlatform = "aarch64-linux"; }; externalPkgsWithConfig = { + _file = "ext-pkgs-config.nix"; nixpkgs.pkgs = pkgs; nixpkgs.config.allowUnfree = true; }; @@ -122,6 +123,9 @@ lib.recurseIntoAttrs { { allowUnfree = true; } + + Defined in: + - ext-pkgs-config.nix '']; assert getErrors { nixpkgs.localSystem = pkgs.stdenv.hostPlatform;