`allowUnfree[?Predicate]` does not apply to `self.packages`?

I misunderstood. If I import nixpkgs { system, overlays... }, what packages does it use? If legacyPackages is not used? If I do it this way, need I concern myself about system when making the overlay?

What is the nixos option that you mention?

Several of my examples above would not have worked, they were sloppy ad-hoc psuedocode, and I pasted them in my config. They were never evaluated with the manual import; why?

This turns into import /nix/store/path/to/nixpkgs/default.nix { inherit system overlays;};, which means you’re just evaluating nixpkgs. It won’t be the same “instance” as the legacyPackages one, and in fact you could set flake = false in your input and it will still work, but it’s the same package definitions.

The default.nix of nixpkgs will use the system and overlays as intended, so the overlay doesn’t need to worry about system.

I’m referring to nixpkgs.overlays.

Not sure, I’d need to see the pasted-together final config :slight_smile:

The nixpkgs.nix NixOS module will instantiate Nixpkgs from the repository it is part of when nixpkgs.pkgs option is not set. Similarly, nixpkgs.legacyPackages attribute will import Nixpkgs from the repo the Nixpkgs’ flake.nix is part of.

So I would recommend not using nixpkgs.legacyPackages and instead constructing pkgs by importing Nixpkgs yourself with the desired config and overlays, and adding { nixpkgs.pkgs = pkgs; } to the modules arg of lib.nixosSystem. Note that unlike home-manager, NixOS will not re-import the Nixpkgs so when you set nixpkgs.pkgs NixOS option, so the other options under nixpkgs prefix will be ignored.

1 Like

This is what I currently have, legacyPackages is gone for now

I’ve gotten a different error message!

Is there a way to specify nixpkgs options in the flake, and still set options with nixpkgs.config in the configs? I want to keep allowBroken localized to my ZFS config.

This is a new error too when I comment out the usage of the font:

error: The option `nixpkgs.pkgs' does not exist. Definition values:
       - In `<unknown-file>'

       … while evaluating the attribute 'config'

       at /nix/store/fr68dr66gmggn62jir7vp1bcnignwxp9-source/lib/modules.nix:333:9:

          332|         options = checked options;
          333|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          334|         _module = checked (config._module);

       … while evaluating 'collectFailed'

       at /nix/store/gwxrym36bd2dj406z9wc1diaas84ysdp-source/modules/default.nix:15:19:

           14|
           15|   collectFailed = cfg:
             |                   ^
           16|     map (x: x.message) (filter (x: !x.assertion) cfg.assertions);

       … from call site

       at /nix/store/gwxrym36bd2dj406z9wc1diaas84ysdp-source/modules/default.nix:41:16:

           40|     let
           41|       failed = collectFailed rawModule.config;
             |                ^
           42|       failedStr = concatStringsSep "\n" (map (x: "- ${x}") failed);

       … while evaluating 'fold''

       at /nix/store/fr68dr66gmggn62jir7vp1bcnignwxp9-source/lib/lists.nix:56:15:

           55|       len = length list;
           56|       fold' = n:
             |               ^
           57|         if n == len

       … from call site

       at /nix/store/fr68dr66gmggn62jir7vp1bcnignwxp9-source/lib/lists.nix:60:8:

           59|         else op (elemAt list n) (fold' (n + 1));
           60|     in fold' 0;
             |        ^
           61|

       … while evaluating 'foldr'

       at /nix/store/fr68dr66gmggn62jir7vp1bcnignwxp9-source/lib/lists.nix:53:20:

           52|   */
           53|   foldr = op: nul: list:
             |                    ^
           54|     let

       … from call site

       at /nix/store/gwxrym36bd2dj406z9wc1diaas84ysdp-source/modules/default.nix:22:7:

           21|     in
           22|       fold f res res.config.warnings;
             |       ^
           23|

       … while evaluating 'showWarnings'

       at /nix/store/gwxrym36bd2dj406z9wc1diaas84ysdp-source/modules/default.nix:18:18:

           17|
           18|   showWarnings = res:
             |                  ^
           19|     let

       … from call site

       at /nix/store/gwxrym36bd2dj406z9wc1diaas84ysdp-source/modules/default.nix:39:12:

           38|
           39|   module = showWarnings (
             |            ^
           40|     let

I have tried both

{ nixpkgs = { inherit pkgs; }; }
{ nixpkgs.pkgs = pkgs; }

letting

    pkgs = import nixpkgs {
      inherit system;
      overlays = [ self.overlays.${system}.allowUnfree ];
      config = { allowUnfree = true; };
    };

Not without more terrible hacks, Nixpkgs config needs to be provided when instantiating Nixpkgs. But IMO allowBroken is overkill anyway and you are better off to override the meta.broken locally with .overrideAttrs (attrs: { meta = attrs.meta // { broken = false; }; })

nixpkgs.pkgs is a NixOS option, not a home-manager one. For home-manager used separately from NixOS, it should be sufficient to pass the pkgs argument to lib.homeManagerConfiguration.

1 Like
error: The option `boot.zfs.package' is read-only, but it's set multiple times.
    zfs = {
      enableUnstable = enableUnstableZfs;
      forceImportAll = false;
      forceImportRoot = false;
    } // lib.optionalAttrs enableUnstableZfs {
      package = pkgs.zfsUnstable.overrideAttrs (old: {
        meta = lib.recursiveUpdate old.meta { broken = false; };
      });
    };

This does not work either

    pkgs = import nixpkgs {
      inherit system;
      config.allowUnfree = true;
      overrides = [
        (pkgs.zfsUnstable.overrideAttrs (old: {
          meta = lib.recursiveUpdate old.meta { broken = false; };
        }))
      ];
    };
error: Package ‘zfs-kernel-2.1.5-5.19.8’ in /nix/store/fr68dr66gmggn62jir7vp1bcnignwxp9-source/pkgs/os-specific/linux/zfs/default.nix:196 is marked as broken, refusing to evaluate.

I am now wondering how often I’ve used overrides instead of overlays, and this has been the cause of my troubles.

Is there a way to override a read-only option?

With typos corrected, and the allowUnfree override working, I’m left with the ZFS issue.

      overlays = [
        (_: prev: {
          zfsUnstable = prev.zfsUnstable.overrideAttrs (old: {
            meta = old.meta // { broken = false; };
          });
        })
        self.overlays.${system}.allowUnfree
      ];

This does not work, and I am warned that I must use allowUnstable.

What is the correct way to override meta from this function?

That should work with .overrideAttrs since the meta is an attribute passed to stdenv.mkDerivation.

But it doesn’t, it always warns that I don’t have allowBroken.

What information do we need to debug that?

      overlays = [
        (_: prev: {
          zfsUnstable = prev.zfsUnstable.overrideAttrs (old: {
            meta = old.meta // { broken = false; };
          });
        })
        self.overlays.${system}.allowUnfree
      ];

Thanks to the help from above, the solution I ended up using follows.

I made a function to generate an overlay that modifies the license of every package provided to say that it is a free license:

  # make an overlay lambda that overrides the license of every provided package
  # to spoof free-ness
  # returns an attrset where the keys are the pnames of each derivation
  mkUnfreeOverlay = packages: let
    overrides = lib.pipe packages [
      (map (value: { name = lib.getName value; inherit value; }))
      builtins.listToAttrs
      (builtins.mapAttrs (_: package: package.overrideAttrs (
        old: lib.recursiveUpdate old {
          meta.license = (
            if builtins.isList old.meta.license
            then map (_: { free = true; }) old.meta.license
            else { free = true; }
          );
        }
      )))
    ];
  in (_: _: overrides);

This can then be used in a flake such as:

    overlays = genSystems (system: let
      pkgs = self.packages.${system};
    in {
      allowUnfree = flib.mkUnfreeOverlay [
        pkgs.ttf-ms-win11
      ];
    });

And to tell nixpkgs about it, I use:

    pkgs = import nixpkgs {
      inherit system;
      config.allowUnfree = true;
      overlays = [
        self.overlays.${system}.allowUnfree
      ];
    };

Then the package can be used like pkgs.ttf-ms-win11 anywhere with no headache.

Make sure to add { nixpkgs.pkgs = pkgs; } in the nixosConfigurations modules list, and inherit pkgs in homeConfigurations just as usual.