Overlaying nix does not propagate up to NixOS systems definitions #1

Open
opened 2024-03-02 21:13:44 +00:00 by raito · 7 comments
Owner

Describe the bug

Overlaying nixVersions.stable does not propagate to NixOS tests/systems, hinting at nixpkgs reimportation happening somewhere in-between.

Steps To Reproduce

@pennae could you provide a reproducer?

Expected behavior

It should pass the overlayed nixVersions.stable to the systems.

**Describe the bug** Overlaying `nixVersions.stable` does not propagate to NixOS tests/systems, hinting at nixpkgs reimportation happening somewhere in-between. **Steps To Reproduce** @pennae could you provide a reproducer? **Expected behavior** It should pass the overlayed `nixVersions.stable` to the systems.
Owner
        nix-build '<nixpkgs>' --arg overlays '[ (final: prev: {
          nixVersions = prev.nixVersions.extend (final: prev: {
            stable = prev.stable.overrideAttrs (_: {
              src = /dev/null;
            });
          });
        }) ]' -A nixosTests.misc

should fail, but does not. building -A nix instead fails as expected

nix-build '<nixpkgs>' --arg overlays '[ (final: prev: { nixVersions = prev.nixVersions.extend (final: prev: { stable = prev.stable.overrideAttrs (_: { src = /dev/null; }); }); }) ]' -A nixosTests.misc should fail, but does not. building `-A nix` instead fails as expected
jade added the
testing
label 2024-03-11 20:01:20 +00:00
jade self-assigned this 2024-03-20 06:46:00 +00:00
Owner

Cause identified: 3794246066/nixos/modules/misc/nixpkgs.nix (L71-L94)

Now, what to do about it, that is a much harder question to answer :(

I spot a TODO though, and I think it is exactly the right spot to do it: b8698cd8d6/nixos/lib/testing/pkgs.nix (L11-L13)

Cause identified: https://github.com/nixos/nixpkgs/blob/3794246066409d7baac72e3fdfb0e4f66ef4a013/nixos/modules/misc/nixpkgs.nix#L71-L94 Now, what to do about it, that is a much harder question to answer :( I spot a TODO though, and I think it is exactly the right spot to do it: https://github.com/nixos/nixpkgs/blob/b8698cd8d62c42cf3e2b3a95224c57173b73e494/nixos/lib/testing/pkgs.nix#L11-L13
Member

I don't think there is a bug here (or in other words, I believe things are working as intended). The reason you don't get a build failure is because nixosTests.misc doesn't use nix at all. However, if you add the following change to ./nixos/tests/misc.nix:

diff --git a/nixos/tests/misc.nix b/nixos/tests/misc.nix
index e7842debba7a..ae2564444b69 100644
--- a/nixos/tests/misc.nix
+++ b/nixos/tests/misc.nix
@@ -10,6 +10,7 @@ in {
     { lib, ... }:
     { swapDevices = lib.mkOverride 0
         [ { device = "/root/swapfile"; size = 128; } ];
+      environment.defaultPackages = [ pkgs.nix ];
       environment.variables.EDITOR = lib.mkOverride 0 "emacs";
       documentation.nixos.enable = lib.mkOverride 0 true;
       systemd.tmpfiles.rules = [ "d /tmp 1777 root root 10d" ];

Then the reproduction now fails in the way you expected

I don't think there is a bug here (or in other words, I believe things are working as intended). The reason you don't get a build failure is because `nixosTests.misc` doesn't use `nix` at all. However, if you add the following change to `./nixos/tests/misc.nix`: ```diff diff --git a/nixos/tests/misc.nix b/nixos/tests/misc.nix index e7842debba7a..ae2564444b69 100644 --- a/nixos/tests/misc.nix +++ b/nixos/tests/misc.nix @@ -10,6 +10,7 @@ in { { lib, ... }: { swapDevices = lib.mkOverride 0 [ { device = "/root/swapfile"; size = 128; } ]; + environment.defaultPackages = [ pkgs.nix ]; environment.variables.EDITOR = lib.mkOverride 0 "emacs"; documentation.nixos.enable = lib.mkOverride 0 true; systemd.tmpfiles.rules = [ "d /tmp 1777 root root 10d" ]; ``` Then the reproduction now fails in the way you expected
Owner

Gabriella: i think that is somewhat plausible as well but I've found via debugger that it is reimporting nixpkgs at some point due to a clear cut case of the testing framework not stopping that so even if the test is using nix, it might not pick up the overlayed version? Unsure how our results fit together.

Gabriella: i think that is somewhat plausible as well but I've found via debugger that it is reimporting nixpkgs at some point due to a clear cut case of the testing framework not stopping that so even if the test is using nix, it might not pick up the overlayed version? Unsure how our results fit together.
Member

My best guess is that reason for the reimport of Nixpkgs is this:

4f7fd6dded/pkgs/build-support/testers/default.nix (L126)

The NixOS tests use pkgsLinux which (if you're on a non-Linux system) will reimport Nixpkgs but still with the same overlays as before just with a different system argument:

bc50837c0e/pkgs/top-level/stage.nix (L247-L255)

If you're already on a Linux system then I'm not sure why the second reimport of Nixpkgs is happening, but either way my intuition here is that the second reimport of Nixpkgs is probably still reusing the same set of overlays as the original import of Nixpkgs.

My best guess is that reason for the reimport of Nixpkgs is this: https://github.com/NixOS/nixpkgs/blob/4f7fd6ddede67066b8375700f3ef406eb73ea84e/pkgs/build-support/testers/default.nix#L126 The NixOS tests use `pkgsLinux` which (if you're on a non-Linux system) will reimport Nixpkgs *but still with the same overlays as before* just with a different `system` argument: https://github.com/NixOS/nixpkgs/blob/bc50837c0ef04954cdb89961042f11acafc43dd0/pkgs/top-level/stage.nix#L247-L255 If you're already on a Linux system then I'm not sure why the second reimport of Nixpkgs is happening, but either way my intuition here is that the second reimport of Nixpkgs is probably still reusing the same set of overlays as the original import of Nixpkgs.
Owner

huhhhh, that first module should surely be in there when running on Linux but is not working at least. weird.

huhhhh, that first module should surely be in there when running on Linux but is not working at least. weird.
Member

This issue was mentioned on Gerrit on the following CLs:

  • commit message in cl/1605 ("daemon: fix a crash bug "FATAL: exception not rethrown"")
<!-- GERRIT_LINKBOT: {"cls": [{"backlink": "https://gerrit.lix.systems/c/lix/+/1605", "number": 1605, "kind": "commit message"}], "cl_meta": {"1605": {"change_title": "daemon: fix a crash bug \"FATAL: exception not rethrown\""}}} --> This issue was mentioned on Gerrit on the following CLs: * commit message in [cl/1605](https://gerrit.lix.systems/c/lix/+/1605) ("daemon: fix a crash bug "FATAL: exception not rethrown"")
Sign in to join this conversation.
No milestone
No project
No assignees
5 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#1
No description provided.