Skip to content

pkgs/top-level/stage.nix: move most nixpkgs sets to variants#400351

Merged
RossComputerGuy merged 1 commit intoNixOS:masterfrom
RossComputerGuy:feat/nixpkgs-variants
May 19, 2025
Merged

pkgs/top-level/stage.nix: move most nixpkgs sets to variants#400351
RossComputerGuy merged 1 commit intoNixOS:masterfrom
RossComputerGuy:feat/nixpkgs-variants

Conversation

@RossComputerGuy
Copy link
Member

@RossComputerGuy RossComputerGuy commented Apr 20, 2025

Things done

Idea comes from #375435 (comment).

Add separate nixpkgs variants which can be disabled or enabled as needed.

Also add mkOptionalOverlay, this allows us to throw an error when an attribute from an overlay isn't available unless enabled.

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Apr 20, 2025
@github-actions github-actions bot added 8.has: documentation This PR adds or changes documentation and removed 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Apr 20, 2025
@RossComputerGuy RossComputerGuy marked this pull request as ready for review April 20, 2025 16:11
@nix-owners nix-owners bot requested a review from Ericson2314 April 20, 2025 16:12
@wolfgangwalther
Copy link
Contributor

wolfgangwalther commented Apr 24, 2025

I like the basic idea, which is to make sure that no references to those package sets can sneak into other nixpkgs code. In the best case, all the remaining package sets like pkgsStatic etc. would also be variants. But I guess they are currently referenced in nixpkgs, so that won't work. And also, the breaking change would be much bigger.

But that still doesn't convince me, that adding those variants like pkgsLLVMLibc or pkgsBolt etc. is a good idea. We will quickly end up with a pkgsXXX variant of every available config option.

I think we are conflating two issues here:

  • Top-level package sets make it possible to create a combination of various config options. pkgsExtraHardening or pkgsStatic, for example. Nobody would expect users to set those up manually, not everyone needs to know about all the different flags that go in there.
  • Top-level package sets provide better UX than config options.

We should only add package sets for the first reason, not "for better UX". Maybe we can think about better UX separately.

Why is passing those via system on the command line so hard?

OK, I tried it. I need:

  • pkgsBolt: nix-build --arg crossSystem '{ system="x86_64-linux"; useBolt=true; }' -A hello
  • pkgsLLVM: nix-build --arg crossSystem '{ system="x86_64-linux"; useLLVM=true; linker="lld"; }' -A hello

Really annoying that I have to pass my own system as well. Doing nix-build -A pkgsBolt.hello... is so much easier.

Maybe we can introduce some kind of attribute-based-config system for CLI UX? I'm thinking of doing something like:

nix-build -A <something>.useLLVM.withLLD.pkgs.hello
nix-build -A <something>.useBolt.pkgs.hello

Where:

  • We use a prefix (not sure about the name, <something> here) to avoid calling nixpkgsFun before we need to - and also to keep the packages namespace clean.
  • Config options are exposed as attributes where sensible.
  • pkgs actually calls nixpkgsFun, thus "ends" the configuration part.

This way, we have better UX, but don't need to add package sets all the time. Maybe we can also do shortcuts like nix-build -A <something>.static.pkgs.hello, where static would be a collection of different options.

@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 24, 2025
@RossComputerGuy
Copy link
Member Author

OK, I tried it. I need:

* `pkgsBolt`: `nix-build --arg crossSystem '{ system="x86_64-linux"; useBolt=true; }' -A hello`

* `pkgsLLVM`: `nix-build --arg crossSystem '{ system="x86_64-linux"; useLLVM=true; linker="lld"; }' -A hello`

Really annoying that I have to pass my own system as well. Doing nix-build -A pkgsBolt.hello... is so much easier.

I feel like this kinda answers itself. Plus, once #365057 is merged and we stop supporting useLLVM it'll be even more complicated since you will have to supply each attribute specifically.

Maybe we can introduce some kind of attribute-based-config system for CLI UX?

I agree but I think we should stick to the variants approach until we're able to design a better system. It'll also likely be some amount of time we want both for compatibility.

@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 24, 2025
@Ericson2314
Copy link
Member

Yeah this is good. I look forward to everything being moved!

@wolfgangwalther
Copy link
Contributor

This is a breaking change for everyone using one of those package sets right now, so I say we can't merge this before branch-off anymore.

@wegank wegank added 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Apr 24, 2025
@RossComputerGuy
Copy link
Member Author

Is it a breaking change? It only really effects people if they turn off allowVariants which we never do right now. The plan is to change that after the release this PR lands in.

Copy link
Member

@alyssais alyssais left a comment

Choose a reason for hiding this comment

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

Love the direction. Glad somebody is finally getting around to this.

Copy link
Member

Choose a reason for hiding this comment

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

They're not really subsets. They contain just as much as the original set.

Copy link
Member Author

Choose a reason for hiding this comment

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

What's a better way to explaining it?

Copy link
Member

Choose a reason for hiding this comment

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

They're differently instantiated package sets.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've reworded things slightly, idk if that's any better.

Copy link
Member

Choose a reason for hiding this comment

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

Given how simple this was before I'm not sure the quite complex mkOptionalOverlay function is worth it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I've dropped the commit which did that. We can figure something out later.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that's a desirable change — one of the reasons to disable aliases is to get rid of throws when iterating over package sets. Usually that's only relevant for sets below the top level but I don't think we'd want the top level to work confusingly differently.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, would we want to add another option for turning off the optional overlay?

@RossComputerGuy RossComputerGuy force-pushed the feat/nixpkgs-variants branch 2 times, most recently from b662e26 to 58b5540 Compare April 27, 2025 05:05
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
This allows for using different toolchains, libc's, or global build changes across nixpkgs.
This allows for using different toolchains, libcs, or global build changes across nixpkgs.

And maybe it would be good to explain why you'd want to enable/disable this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

This complicated function is still here and is now only used once.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, removed

@Ericson2314
Copy link
Member

I am still a bit confused, because I hate variants but like this PR.

If we want to provide short-hands, that can still be in the hydra jobset, but a new attribute set. Likewise for the CLI. Perhaps making those new entry points is sort of the stuff that @wolfgangwalther is already planning.

I don't really worry about drift in the meaning of "aliases" as that also seems like something we can clear up after the fact?

@RossComputerGuy
Copy link
Member Author

Yeah, and I don't see how we could get to @wolfgangwalther's work without doing something like this at least for the interim. The goal here is to move packages in nixpkgs off of using pkgs*.

@wolfgangwalther
Copy link
Contributor

The goal here is to move packages in nixpkgs off of using pkgs*.

And I fully agree with that goal. I just think we should use allowAliases, not introduce allowVariants.

@RossComputerGuy
Copy link
Member Author

I've explained that that isn't really optimal since it's not really an alias, it'll break existing things if people turned aliases off, and if someone wants it for CI then every throw in aliases will show up.

@wolfgangwalther
Copy link
Contributor

I understand your position, because you don't want any breaking changes for existing use-cases.

My position is different, because I am not only OK with breaking changes, in small steps - in this case, I actively want them. If we ever want to get away from those variants, we must break them eventually. This seems like a reasonable first step.

@Ericson2314
Copy link
Member

Can we do allowVariants for 25.05, and no allowVariants for 25.11?

@wolfgangwalther
Copy link
Contributor

Can we do allowVariants for 25.05, and no allowVariants for 25.11?

As said earlier, I'm not a big fan of introducing it now, if we already have the intent to remove it again.

But to be clear: I am not blocking this PR, otherwise I would have "Requested Changes". So if the three of you agree with the current approach (and it looks like this, given the two approvals), then you might still want to go ahead with it in this form. I think I have voiced all my concerns :D

@RossComputerGuy
Copy link
Member Author

Can we do allowVariants for 25.05, and no allowVariants for 25.11?

That's been my plan.

But to be clear: I am not blocking this PR, otherwise I would have "Requested Changes".

Sounds good.

@RossComputerGuy RossComputerGuy merged commit 4eb6667 into NixOS:master May 19, 2025
20 of 21 checks passed
@RossComputerGuy RossComputerGuy deleted the feat/nixpkgs-variants branch May 19, 2025 16:52
@Ericson2314
Copy link
Member

@RossComputerGuy Can you add modify the docs to say we expect allowVariants to be temporary, ideally removed by 25.11?

@RossComputerGuy
Copy link
Member Author

After work I can, about 8 hours from now. Unless someone is able to do it sooner.

@RossComputerGuy
Copy link
Member Author

expect allowVariants to be temporary, ideally removed by 25.11

Just now getting to this, I don't think 25.11 would remove it based on this:

Can we do allowVariants for 25.05, and no allowVariants for 25.11?

Would it be better to note that it is likely to be dropped after 26.05?

Of course it could be removed after 25.11 but it really depends on the pace of how we can get things through.

@Ericson2314
Copy link
Member

Ericson2314 commented May 21, 2025

Just leave it vague and say it will be removed in a future stable release.

@RossComputerGuy
Copy link
Member Author

Done in #409265

@Ericson2314
Copy link
Member

@RossComputerGuy uh is that the PR you meant to link?

@RossComputerGuy
Copy link
Member Author

No apparently the PR didn't get created even though I remember making it, it should be #409484

@RossComputerGuy
Copy link
Member Author

As per @Ericson2314's request (#409484 (comment)), we're backporting this to 25.05

@nixpkgs-ci
Copy link
Contributor

nixpkgs-ci bot commented May 24, 2025

Successfully created backport PR for release-25.05:

@nixpkgs-ci nixpkgs-ci bot added the 8.has: port to stable This PR already has a backport to the stable release. label May 24, 2025
Comment on lines +194 to +202
variants = import ./variants.nix {
inherit
lib
nixpkgsFun
stdenv
overlays
makeMuslParsedPlatform
;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

So we now have an allowVariants config option - but it doesn't do anything. Its value is not used anywhere. All the variants are still available when setting it to false.

What was the intent to introduce this again, when apparently nobody has used it, yet?

Copy link
Member Author

Choose a reason for hiding this comment

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

The plan is to set it to true in CI once we have a competent replacement. #410056 is one that I've worked on. We're kinda blocked on that with GCC NG, @Ericson2314 and I are working on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

The plan is to set it to true in CI

I think this is just a typo and you mean false.

I think you missed my point: When I use allowVariants = false, then it doesn't work. It doesn't do anything. The PR body mentions this:

Also add mkOptionalOverlay, this allows us to throw an error when an attribute from an overlay isn't available unless enabled.

But apparently this has been lost during later refactors of the PR. Now all variants are unconditionally included all the time.

We currently have a prominently placed release note (including a backport) which mentions that we have a new config option allowVariants, but this config option is disfunctional.

I hope that clarifies it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is just a typo and you mean false.

Yes, I meant false. It was a typo.

I think you missed my point: When I use allowVariants = false, then it doesn't work. It doesn't do anything. The PR body mentions this:

Also add mkOptionalOverlay, this allows us to throw an error when an attribute from an overlay isn't available unless enabled.

But apparently this has been lost during later refactors of the PR. Now all variants are unconditionally included all the time.

mkOptionalOverlay was removed due to a review.

We currently have a prominently placed release note (including a backport) which mentions that we have a new config option allowVariants, but this config option is disfunctional.

I hope that clarifies it.

Huh, lemme check if this works. I remember testing it and it did work.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's easy to confirm that it can't work. Just grep for allowVariants. It's only used in top-level/config and the release notes :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh now I see what's going on, after #400351 (comment) I didn't add in lib.optionalAttrs for the variants attribute in pkgs/top-level/stage.nix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.has: documentation This PR adds or changes documentation 8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants