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.
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.
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
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.
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.
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
];
});