New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make pkgs.nixos and pkgs.nixosTest pure wrt NIXOS_EXTRA_MODULE_PATH #51852
Conversation
This avoids the NIXOS_EXTRA_MODULE_PATH impurity in NixOS when Nixpkgs is invoked 'purely' via pkgs/top-level/default.nix, but passed the impurity along if invoked impurely via /default.nix or nixpkgs/top-level/impure.nix. pkgs.nixosTests is impure by necessity until a possible future optimization that will make it call pkgs.nixosTest, therefore inheriting its behavior.
@@ -6,7 +6,8 @@ | |||
# Nixpkgs, for qemu, lib and more | |||
, pkgs | |||
, # NixOS configuration to add to the VMs | |||
extraConfigurations ? [] | |||
extraConfigurations ? let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH"; | |||
in if e == "" then [] else [(import e)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm, a bit ugly to proliferate this code around. Are there nicer ways to accomplish this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can just not put it most places, and then see what breaks :D
@@ -72,15 +72,24 @@ in | |||
else overlays homeOverlaysDir | |||
else [] | |||
|
|||
# An impurity in NixOS to pass on when invoking pkgs.nixos, | |||
# pkgs.nixosTest, pkgs.nixosTests. | |||
, nixosExtraModules ? let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would maybe call this nixosTestExtraModules
so it doesn't just sound like some layer violation.
I completely agree with the reason for these changes, namely that you should be able to make your builds completely pure and that the choice should not be between impure and less impure, rather it should be between pure and impure. I do have two points of feedback though:
|
Are there any updates on this pull request, please? |
Thank you for your contributions.
|
This PR was too conservative. Nowaday's, we're moving toward a Nix that doesn't read environment variables by default, so we'll probably remove this feature completely at some point in the future. |
Motivation for this change
Includes #51850
This avoids the
NIXOS_EXTRA_MODULE_PATH
impurity in NixOS whenNixpkgs is invoked 'purely' via
pkgs/top-level/default.nix
, butpassed the impurity along if invoked impurely via
/default.nix
or
pkgs/top-level/impure.nix
.pkgs.nixosTests
remains impure by necessity until a possible futureoptimization that will make it call
pkgs.nixosTest
, thereforeinheriting its behavior.
This duplicates the default in a number of places because these files are potentially public interfaces.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)