Skip to content
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

nixpkgs: backports from upstream #1318

Merged
merged 12 commits into from
Feb 5, 2025
Merged

Conversation

emilazy
Copy link
Collaborator

@emilazy emilazy commented Feb 3, 2025

Should fix the module after recent Nixpkgs changes.

@cixel
Copy link

cixel commented Feb 3, 2025

This might be redundant with the logs in the failing checks, but when I update my flake input I now get the following:

building the system configuration...
error:
       … while evaluating the attribute 'config.system.build.toplevel'
         at /nix/store/32dh0g41x5w9zkqxqka3rj7h18blqhyh-source/lib/modules.nix:334:9:
          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          335|         _module = checked (config._module);

       … while calling the 'seq' builtin
         at /nix/store/32dh0g41x5w9zkqxqka3rj7h18blqhyh-source/lib/modules.nix:334:18:
          333|         options = checked options;
          334|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          335|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: undefined variable 'darwinExpectedSystem'
       at /nix/store/f8vkfbnn50yf02ijxcf9rapw70bziv39-source/modules/nix/nixpkgs.nix:288:177:
          287|           assertion = cfg.constructedByUs -> !hasPlatform -> cfg.system == pkgsSystem;
          288|           message = "The nix-darwin nixpkgs.pkgs option was set to a Nixpkgs invocation that compiles to target system ${pkgsSystem} but nix-darwin was configured for system ${darwinExpectedSystem} via nix-darwin option nixpkgs.system. The nix-darwin system settings must match the Nixpkgs target system.";
             |                                                                                                                                                                                 ^
          289|         }

emilazy and others added 4 commits February 3, 2025 20:25
This got mangled in the backport a year and a half ago.

Fixes: e25eeff
… externally

This is a common footgun people hit often. Remove it.

Backport of Nixpkgs commit ce87196a00214a0062ece1c3e03a9a97f563580f.

Co-authored-by: K900 <[email protected]>
henrik-ch was also here :)

Backport of Nixpkgs commit 11406bdc0e5af9b3c8a8d597da23349238c65277.

Co-authored-by: Silvan Mosberger <[email protected]>
Co-Authored-By: Valentin Gagarin <[email protected]>
system and config shouldn't both be specified — each will be filled in
based on the other when the system is elaborated.

Backport of Nixpkgs commit a3ba0495452cd8e72735ebd4472838e96902a259.

Co-authored-by: Alyssa Ross <[email protected]>
@emilazy emilazy force-pushed the push-tmtstvpkwkow branch 2 times, most recently from 921dcde to fb70457 Compare February 3, 2025 20:29
@jwiegley
Copy link
Contributor

jwiegley commented Feb 3, 2025

Is it necessary for this PR to also reformat the entire file? It makes it very hard to see what the actual change is...

@emilazy
Copy link
Collaborator Author

emilazy commented Feb 3, 2025

Yes, since Nixpkgs upstream formatted it and it’s necessary to easily backport the changes after that point. We should do a treewide reformat but I’m holding out until Nixpkgs does the full treewide. I will add the reformatting commit to .git-blame-ignore-revs once I’ve gotten this actually working and no longer need to rebase it, though.

All the changes here are just backported from NixOS. If you want to review the backports I’d suggest going commit‐by‐commit, since otherwise you’re reading like ten upstream PRs at once.

emilazy and others added 8 commits February 3, 2025 20:44
Since the output of `lib.systems.elaborate` contains functions, an
equality check with `==` does not suffice, `lib.systems.equals` should
be used instead.

Backport of Nixpkgs commit 3794246066409d7baac72e3fdfb0e4f66ef4a013.

Co-authored-by: Jared Baur <[email protected]>
Backport of Nixpkgs commit e6057cfd59f278db3aeb058a4e1e0bcc24696267.

Co-authored-by: Valentin Gagarin <[email protected]>
Co-authored-by: Dominic Mills <[email protected]>
Backport of Nixpkgs commit 609e57485d1fa111e3a689498d9d338dc03a7bc5.

Co-authored-by: Felix Buehler <[email protected]>
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.

Backport of Nixpkgs commit 1bd4da1848cb7b68858ebb2ca1f8b0e5fed46c58.

Co-authored-by: Matt Sturgeon <[email protected]>
Backport of Nixpkgs commit 6d9dfef94ffd59a327573eea7bc709a84c44b3d2.

Co-authored-by: Matt Sturgeon <[email protected]>
The description for options.nixpkgs.system already hints at this:

  Neither ${opt.system} nor any other option in nixpkgs.* is meant
  to be read by modules and configurations.
  Use pkgs.stdenv.hostPlatform instead.

We can support this goal by not elaborating the systems anymore, forcing
users to go via pkgs.stdenv.

This will prevent problems when making the top-level package sets
composable in the next commit. For this to work, you should pass a fully
elaborated system to nixpkgs' localSystem or crossSystem options.

Backport of Nixpkgs commit 0a19371146130c0e2a402fd0c35f8283b0e81910.

Co-authored-by: Wolfgang Walther <[email protected]>
@ossareh
Copy link

ossareh commented Feb 3, 2025

Can confirm that as of 537056b I can now rebuild successfully. Thanks @emilazy!

@cixel
Copy link

cixel commented Feb 3, 2025

Can confirm that as of 537056b I can now rebuild successfully. Thanks @emilazy!

Ditto, but only if I have nixpkgs.linux-builder.enable = false.

If I set it true, I get the following:

error:
       … while evaluating the attribute 'value'
         at /nix/store/32dh0g41x5w9zkqxqka3rj7h18blqhyh-source/lib/modules.nix:846:9:
          845|     in warnDeprecation opt //
          846|       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          847|         inherit (res.defsFinal') highestPrio;

       … while evaluating the option `system.build':

       … while evaluating the attribute 'mergedValue'
         at /nix/store/32dh0g41x5w9zkqxqka3rj7h18blqhyh-source/lib/modules.nix:881:5:
          880|     # Type-check the remaining definitions, and merge them. Or throw if no definitions.
          881|     mergedValue =
             |     ^
          882|       if isDefined then

       … while evaluating definitions from `/nix/store/nl6r1g7n6jcn0pwjb3hikszf2lhn0163-source/modules/system':

       … while evaluating the option `nix.buildMachines."[definition 1-entry 1]".systems':

       … while evaluating definitions from `/nix/store/nl6r1g7n6jcn0pwjb3hikszf2lhn0163-source/modules/nix/linux-builder.nix':

       … while evaluating the option `nix.linux-builder.systems':

       … while evaluating definitions from `/nix/store/nl6r1g7n6jcn0pwjb3hikszf2lhn0163-source/modules/nix/linux-builder.nix':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: expected a set but found a string: "aarch64-linux"

This goes away if I manually set:

  nix.linux-builder.systems = [ pkgs.hostPlatform.system ];

It isn't obvious to me why the default isn't working.

@emilazy
Copy link
Collaborator Author

emilazy commented Feb 3, 2025

@wolfgangwalther Looks like darwin.linux-builder’s NixOS configuration is broken by your PR? I don’t think that’s something we can work around downstream since we need Hydra to build it (and I’m not sure how we’d stop reading nixpkgs.hostPlatform.system since it doesn’t seem like the package exposes its package set).

@emilazy
Copy link
Collaborator Author

emilazy commented Feb 3, 2025

Actually I guess we can do darwin.linux-builder.nixosConfig._module.args.pkgs.stdenv.hostPlatform.system. Though the darwin.linux-builder’s way of setting nixpkgs.hostPlatform still seems a bit questionable.

@emilazy
Copy link
Collaborator Author

emilazy commented Feb 3, 2025

@cixel #1319 should hopefully fix that; I’ve submitted it separately as it can be applied independently, but you’ll probably need to test with both.

@cixel
Copy link

cixel commented Feb 3, 2025

Thanks for the quick turnaround. I did the following:

  1. locally checked out emilazy:push-mmmkkprkuzzs (branch for linux-builder: don’t read nixpkgs.hostPlatform #1319)
  2. rebased it onto emilazy:push-tmtstvpkwkow
  3. set inputs.darwin.url = /path/to/local/repo
  4. darwin-rebuild switch --flake /path/to/flake

and I get the following:

building the system configuration...
these 17 derivations will be built:
  /nix/store/jdmim32yd0pbha4pf6frac3sqdil3dfa-options.json.drv
  /nix/store/y2q70ndn9l28y9qif5wb7sc40jjmsmww-options.json.drv
  /nix/store/6jhi1k3jfamf4l9j638lqrj25x5f4dpi-darwin-manual-html.drv
  /nix/store/m3446bhiqznii8idnz48g0kcy45wg40c-darwin-help.drv
  /nix/store/wqif2s887hhxrnra8knxpfbad7iyi2jm-darwin-manpages.drv
  /nix/store/91m9i060wm2jg0mf2d4jlqisq1k8xh65-system-applications.drv
  /nix/store/mrhgqvrv90qgs2zry28l5dpcfvnlr9zf-system-path.drv
  /nix/store/md8dp72hxw75251dicgih6jkm9xhlpnr-darwin-system-25.05.drv
  /nix/store/71k581g5bqfyx2icfqny84dgb4gnr5ln-darwin-uninstaller.drv
  /nix/store/bbny1dkiq4sn8was9l4wy286yqzf1gnq-options.json.drv
  /nix/store/iry0n6vaifbqp1lnp6hw385x8c677lm1-options.json.drv
  /nix/store/w2fam0w31ysk34dj7ggshk7g2m1xhgxz-darwin-manual-html.drv
  /nix/store/9cwji11dwgr2qqvn5qlny3g8f867jbis-darwin-help.drv
  /nix/store/bw5ha2gflszpazzh6jc3ccffbjh17acd-darwin-manpages.drv
  /nix/store/6lqrlh9r4rywhmil4m3i5xfdqjyklli1-system-applications.drv
  /nix/store/fkj92jsx127s4vzib7lqq1ngahl5qyyl-system-path.drv
  /nix/store/lgsbvkr7azb999f74wdwa06lqglpkpxs-darwin-system-25.05.c5afeba.drv
building '/nix/store/bbny1dkiq4sn8was9l4wy286yqzf1gnq-options.json.drv' on 'ssh-ng://builder@linux-builder'...
building '/nix/store/jdmim32yd0pbha4pf6frac3sqdil3dfa-options.json.drv' on 'ssh-ng://builder@linux-builder'...
copying 0 paths...
error: build of '/nix/store/bbny1dkiq4sn8was9l4wy286yqzf1gnq-options.json.drv' on 'ssh-ng://builder@linux-builder' failed: error: a 'aarch64-darwin' with features {} is required to build '/nix/store/bbny1dkiq4sn8was9l4wy286yqzf1gnq-options.json.drv', but I am a 'aarch64-linux' with features {benchmark, big-parallel, gccarch-armv8-a, kvm, nixos-test}
error: builder for '/nix/store/bbny1dkiq4sn8was9l4wy286yqzf1gnq-options.json.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/iry0n6vaifbqp1lnp6hw385x8c677lm1-options.json.drv' failed to build
error: 1 dependencies of derivation '/nix/store/bw5ha2gflszpazzh6jc3ccffbjh17acd-darwin-manpages.drv' failed to build
error: 1 dependencies of derivation '/nix/store/w2fam0w31ysk34dj7ggshk7g2m1xhgxz-darwin-manual-html.drv' failed to build
error: 1 dependencies of derivation '/nix/store/6lqrlh9r4rywhmil4m3i5xfdqjyklli1-system-applications.drv' failed to build
error: 1 dependencies of derivation '/nix/store/lgsbvkr7azb999f74wdwa06lqglpkpxs-darwin-system-25.05.c5afeba.drv' failed to build

am I doing something wrong?

@emilazy
Copy link
Collaborator Author

emilazy commented Feb 4, 2025

Not sure. Seems like the Linux builder is trying to build part of your nix-darwin configuration (I guess?) but I don’t know why.

@wolfgangwalther
Copy link
Contributor

Looks like darwin.linux-builder’s NixOS configuration is broken by your PR? I don’t think that’s something we can work around downstream since we need Hydra to build it (and I’m not sure how we’d stop reading nixpkgs.hostPlatform.system since it doesn’t seem like the package exposes its package set).

No, I don't think so. This piece of darwin-packages.nix, should still work, right?

              nixpkgs.hostPlatform = lib.mkDefault (toGuest stdenv.hostPlatform.system);

@cixel
Copy link

cixel commented Feb 4, 2025

Not sure. Seems like the Linux builder is trying to build part of your nix-darwin configuration (I guess?) but I don’t know why.

Yeah, I think that in messing around with different branches and configs I worked my machine into a state where linux-builder was being told to build stuff it's not supposed to. Could've been my "workaround" above broke things. Unsure.

I reset things to an older state and then tried again. Things seem to work now.

Relevant entries from my flake.lock, in case these are useful:

    "darwin": {
      "inputs": {
        "nixpkgs": [
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1738619295,
        "narHash": "sha256-E/zV6EsIuVrzCr07077srLAPpSvgEjtX/qJ4Nu4hPps=",
        "ref": "refs/heads/push-mmmkkprkuzzs",
        "rev": "c5afebab4fc5a86c170da96779233c32724ccc10",
        "revCount": 2042,
        "type": "git",
        "url": "file:///Users/ehdens/workspace/github.com/emilazy/nix-darwin"
      },
      "original": {
        "type": "git",
        "url": "file:///Users/ehdens/workspace/github.com/emilazy/nix-darwin"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1738678663,
        "narHash": "sha256-uPdqVr8gN3oYYcueL/Rh7wM4Y8/D6p9IvRmoBf+uQa8=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "00769b0532199db4e1bda59865f00f3a86232c75",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },

Copy link
Collaborator

@Enzime Enzime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the biggest fan of the last commit as it's unclear of it's going to get reverted (see NixOS/nixpkgs#376988 (comment))

However, according to @wolfgangwalther it should still be backwards compatible (NixOS/nixpkgs#376988 (comment)) so I'm going to merge this now

@Enzime Enzime merged commit ae406c0 into LnL7:master Feb 5, 2025
3 checks passed
EricCrosson added a commit to EricCrosson/dotfiles that referenced this pull request Feb 5, 2025
@wolfgangwalther
Copy link
Contributor

However, according to @wolfgangwalther it should still be backwards compatible (NixOS/nixpkgs#376988 (comment)) so I'm going to merge this now

Let me clarify my comment: I was mostly thinking about two scenarios:

  • passing elaborated systems to the nixos/nixpkgs module
  • accessing config.nixpkgs.hostPlatform etc.

The fixes for those will be unproblematic, now that we had a revert.

I am not sure that this applies to the change in this PR, though: I still can't wrap my head around the "copying of the whole module", but I can imagine that you will get similar breakage now with this version in nix-darwin and the revert upstream.

So... better be prepared to apply the reverted changes here as well.

@emilazy emilazy deleted the push-tmtstvpkwkow branch February 5, 2025 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants