How to use packages directly in `allowUnfreePredicate`?

How to use packages directly in allowUnfreePredicate?

I think this is due to something about laziness trying to tie a knot in our brains. Validity is asserted at evaluation time of a package, but those attrs passed to checkMeta are from a point in evaluation before the actual package is produced to be accessible under pkgs.<pname>. This could be the reason why the equality check fails when using the whole package. @Ericson2314 @roberth or @Artturin will know better.

1 Like

That’s in mkDerivation, and you can see the call to derivation in the block where validity is used. So validity is definitely asserted before the derivation is created, and well, the packages in pkgs are derivations. pkg is not.

I think that’s the right time to check too, you don’t want to potentially build packages that have some kind of build time vulnerability or something, and I’m pretty sure you couldn’t prevent derivation from adding the built package to the store, so there are some potential issues with licenses that don’t allow redistribution if the check happened any later.

I wonder if you could use this if you don’t want to hard-code those names:

allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) (map lib.getName [

Chances are this results in infinite recursion? In fact, any reference to a package in this function should result in infinite recursion.

1 Like

No, that actually works. At least with my setup nixos-rebuild switch --upgrade-all runs fine. Thank you!

That’s very surprising! Curious how the pkgs.vscode resolves there without tripping up evaluation.

I didn’t use pkgs.vscode specifically, but this works:

  nixpkgs.config.allowUnfreePredicate = pkg:
    builtins.elem (
      lib.getName pkg
    ) (
      map lib.getName [
Hosted by Flying Circus.