Skip to content

nixos/misc/nixpkgs add setting nixpkgs.config.allowUnfreePackages = ["list" "of" "packages"]#396595

Merged
yuyuyureka merged 2 commits intoNixOS:masterfrom
dwt:nixpkgs-config-allowUnfreePackages
Jan 27, 2026
Merged

nixos/misc/nixpkgs add setting nixpkgs.config.allowUnfreePackages = ["list" "of" "packages"]#396595
yuyuyureka merged 2 commits intoNixOS:masterfrom
dwt:nixpkgs-config-allowUnfreePackages

Conversation

@dwt
Copy link
Contributor

@dwt dwt commented Apr 6, 2025

Inspired by #197325 this adds a new option nixpkgs.allowUnfreePackages, which merges additively and can thus be defined in multiple modules close to where the unfree package is installed.

I would have liked ot name this option
nixpkgs.config.allowUnfreePackages, to define it closer to where the allowUnfree and allowUnfreePredicate options are defined, but I didn't see how this could be achived, given that nixpkgs.config is an attribute set or function instead of a module. I would welcome some guidance on how to do this.

I would also have liked to have an assertion that this setting should not be defined when nixpkgs.config.allowUnfreePredicate or nixpkgs.config.allowUnfree` is set, but I don't yet know how to do that. (And I would like to learn).

Closes #197325

Things done

  • 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 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Apr 6, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any 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 6, 2025
Copy link
Member

Choose a reason for hiding this comment

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

To make this more scalable:

Suggested change
) (pkg: builtins.elem (lib.getName pkg) config.nixpkgs.allowUnfreePackages);
) (pkg: allowUnfreePackagesAsSet?${lib.getName pkg});

And then in a let binding outside of the pkg: function, something like

lib.genAttrs (_name: null) config.nixpkgs.allowUnfreePackages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a way to get a feel for the performance tradeoffs of these kind of changes? In procedural languages, it is quite often faster to use lists for these kind of tests - for small lists of around 8 or less items, than produce a hash and add everything to it.

This of course hinges on the assumption that this is only called for the actual unfree packages that are in my closure, which should be usually be exactly as many as are in this list.

@dwt
Copy link
Contributor Author

dwt commented Apr 7, 2025

@roberth Thanks for the input, sorry to say that it will likely take me some time to react.

In the meantime: The eval fails with an error I'm not seeing locally:

  error:
       Failed assertions:
       - Your system configures nixpkgs with an externally created instance.
       `nixpkgs.config` options should be passed when creating the instance instead.

I would appreciate some guidance on how to reproduce / avoid this.

@dwt
Copy link
Contributor Author

dwt commented Apr 7, 2025

I would appreciate some guidance on how to reproduce / avoid this.

Looking at generic/check-meta.nix#126 it looks like the safest way to solve this would be to enhance that code to change the fallback function to look into nixpkgs.config.allowUnfreePackages by default, and not have a type for that thing at all, but just some configuration.

The whole thing is constructed in this strange way, which makes me think that there may be a rationale behind this? Perhaps something like that one can share the nixpkgs.config variable safely with a new instance of nixpkgs when importing it?

I have to admit that I don't really understand why this is built like this. :/

@roberth
Copy link
Member

roberth commented Apr 9, 2025

Failed assertions:
       - Your system configures nixpkgs with an externally created instance.
       `nixpkgs.config` options should be passed when creating the instance instead.

There's 2 ways to use Nixpkgs: standalone, where NixOS configures Nixpkgs, or you can use NixOS with an already configured Nixpkgs. Yours seems to be of the latter kind, based on the error message. You could either change it to ignore the pkgs you already have, or you could change the config where that pkgs is constructed.
To say anything with more certainty, I'd have to know more about how you NixOS config is created.

@dwt
Copy link
Contributor Author

dwt commented Apr 10, 2025

@roberth Not quite sure I get you, that error is from a check in a GitHub runner - not from my system. From reading the code it seems likely (though I didn't find anything definitive) that what I am doing in the code, that is setting something in nixpkgs.config from inside nixpkgs is unwanted? I don't quite grok the message and the code that generates it so the intent of that error message is not clear to me.

@dwt dwt force-pushed the nixpkgs-config-allowUnfreePackages branch from 33873b2 to 571ef97 Compare April 11, 2025 20:29
@github-actions github-actions bot added the 6.topic: stdenv Standard environment label Apr 11, 2025
@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. and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Apr 11, 2025
@dwt
Copy link
Contributor Author

dwt commented Apr 11, 2025

@roberth I think I found a better way to integrate this functionality. This involves a custom merge function on the nixpkgs.config type (which seems a bit messy), but the beauty is, that building the predicate now happens in check-meta.nix as a fallback if no predicate is defined. Therefore hopefully sidestepping the eval failure I this idea created before.

To me, there should probably be some sort of assertion to prevent you defining both a predicate and the list of package names, but at least it works, and doesn't complain in the nixpkgs checks, so this is hopefully a good start.

@dwt dwt force-pushed the nixpkgs-config-allowUnfreePackages branch from 571ef97 to 76dca3e Compare April 11, 2025 20:44
@dwt dwt requested a review from roberth April 28, 2025 19:17
Copy link
Member

@afh afh left a comment

Choose a reason for hiding this comment

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

👍 on the approach, please find minor comments

@dwt
Copy link
Contributor Author

dwt commented May 8, 2025

Some more points for discussion / input that I gathered from reading the code, but am not sure I get correctly as I haven't found any documentation on this:

  • Is there a specific reason why the config attribute is not a normal nixpkgs module that merges via it's types, as they are defined in pkgs/top-level/config.nix? Something I was thinking of, is that this allows sharing the config attribute set between different nixpkgs instances (i.e. copying it over from your normal nixpkgs to nixpkgs-unstable or a local nixpkgs-dev)
  • This might also be the reason why it is a good idea to have a collection of strings in there, instead of jut collecting the packages directly. Is that the case? Is there some other reason?
  • Would it be better to assert that packages cannot be set together with the predicate? Or should the two be merged? Or should we allow that the predicate overrides the package list?

I guess there is more, but I would really like some input on these questions to know how to develop this further.

For this I would like to ping @roberth and perhaps @emilazy or some of the contributors who worked on this previously like @Stunkymonkey or @Mic92 or @reckenrode (at least if I interpret the history of these files correctly. Sorry if I don't).

@dwt dwt force-pushed the nixpkgs-config-allowUnfreePackages branch from 76dca3e to 5ffc7a4 Compare May 8, 2025 11:01
Very-Blank added a commit to Very-Blank/Nixos that referenced this pull request Dec 10, 2025
As we don't have "NixOS/nixpkgs#396595" this is
the best we can do currently.
@dwt dwt force-pushed the nixpkgs-config-allowUnfreePackages branch from c7c7599 to 308b135 Compare December 28, 2025 14:44
@dwt dwt requested review from afh and yuyuyureka December 28, 2025 14:49
@nixpkgs-ci nixpkgs-ci bot requested a review from adisbladis December 28, 2025 14:49
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 28, 2025
@dwt
Copy link
Contributor Author

dwt commented Dec 28, 2025

@roberth I would also appreciate another review from you.

@dwt dwt force-pushed the nixpkgs-config-allowUnfreePackages branch 2 times, most recently from f30bf12 to 01a69f0 Compare January 1, 2026 16:20
@Majiir
Copy link
Contributor

Majiir commented Jan 3, 2026

This is working for me. 🎉 But the pull request title and commit descriptions still refer to nixpkgs.allowUnfreePackages, which confused me while I was switching over.

@dwt
Copy link
Contributor Author

dwt commented Jan 3, 2026

@Majiir am I missing something? What would you have expected the pull request title to be?

@Majiir
Copy link
Contributor

Majiir commented Jan 3, 2026

The new option is nixpkgs.config.allowUnfreePackages, not nixpkgs.allowUnfreePackages.

@dwt dwt changed the title nixos/misc/nixpkgs add setting nixpkgs.allowUnfreePackages = ["list" "of" "packages"] nixos/misc/nixpkgs add setting nixpkgs.config.allowUnfreePackages = ["list" "of" "packages"] Jan 3, 2026
dwt added 2 commits January 3, 2026 20:40
…["list" "of "packages"]

Inspired by NixOS#197325 this adds a
new option nixpkgs.allowUnfreePackages, which merges additively and can
thus be defined in multiple modules close to where the unfree package is
installed.

I would have liked ot name this option
nixpkgs.config.allowUnfreePackages, to define it closer to where the
allowUnfree and allowUnfreePredicate are defined, but I didn't see how
this could be achived. I would welcome some guidance on how to do this.
@dwt dwt force-pushed the nixpkgs-config-allowUnfreePackages branch from 01a69f0 to b9cccbb Compare January 3, 2026 19:40
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-in-distress/3604/127

Copy link
Contributor

@yuyuyureka yuyuyureka left a comment

Choose a reason for hiding this comment

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

Diff looks good

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jan 25, 2026
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/6326

@yuyuyureka yuyuyureka added this pull request to the merge queue Jan 27, 2026
Merged via the queue into NixOS:master with commit 918178a Jan 27, 2026
32 checks passed
@github-project-automation github-project-automation bot moved this to Done in Stdenv Jan 27, 2026
@yuyuyureka
Copy link
Contributor

Thank you for your patience in waiting for the review and merge.

There are two followup tasks here:

  • Tree-wide, use the new option where it makes sense (tree-wide: use allowUnfreePackages where applicable #484367)
  • In pkgs/stdenv/generic/check-meta.nix you will find the code which suggests allowUnfreePredicates to the user to allow specific unfree packages when attempting to eval them. This should be changed to suggest allowUnfreePackages instead, although this requires a slight rework of remediate_allowlist / remediate_predicate.

@dwt dwt deleted the nixpkgs-config-allowUnfreePackages branch January 29, 2026 08:37
@jopejoe1
Copy link
Member

Regarding of sharing the option type between nixos and pkgs made this pr for that #489889

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

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: stdenv Standard environment 8.has: module (update) This PR changes an existing module in `nixos/` 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: 1 This PR was reviewed and approved by one person.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Multiple allowUnfreePredicates should compose with or

10 participants