I was so confused after I got this warning when I was still using Determinate Nix. Currently Iām redoing my whole config to use upstream Nix and still got the same error after running the check.
At first I thought it was only related to determinate. I guess I didnāt keep up with the nixpkgs changes until recently lmao
final doesnāt depend on overlay ordering. This makes more sense for stdenv, and especiallystdenv.hostPlatform.system, because you want to get the āfinalā value of those, after all other overlays have been applied. In practice it should rarely make a difference, but itās one of those little details.
Stuff like system and stdenv are involved in bootstrap, so prev.system and prev.stdenv are not things you should rely on.
And in general itās always a best-practice to use final in an overlay, except for obvious infrec scenarios, e.g. for foobar = prev.foobar.override { ... } where youād have to use prev as final would infrec. You want your overlays to actually take effect - final is the nixpkgs instance that ensures that.
Iāve tried to substitute system both on the left and righthandside there, but got an error
error: attribute 'currentSystem' missing
at /nix/store/kfcxqcxb9hcq6x33sg4cmwakbb1ifwg9-source/pkgs/top-level/impure.nix:17:29:
16| localSystem ? {
17| system = args.system or builtins.currentSystem;
| ^
18| },
But just replacing the righthandside (see below) appears to work
nixpkgs.overlays = [
(final: prev: {
# unstable = nixpkgs-unstable.legacyPackages.${prev.system};
# use this variant if unfree packages are needed:
unstable = import nixpkgs-unstable {
inherit prev;
system = prev.stdenv.hostPlatform.system;
config.allowUnfree = true;
config.android_sdk.accept_license = true;
};
})
];
with this nix flake update and nixos-rebuild switch run without warnings.
But this seems still a bit weird to me, if system should be replaced with stdenv.hostPlatform.system, why do I still need to leave it just system on the left hand side?
I mean, the entire block makes almost zero sense, using an overlay just to pass a pkgs set into the module system, that pointless inherit prev that clearly shows the author has no idea what inherit does or what import nixpkgs does, the deprecated system.
But it is just copied from the wiki, unfortunately the well is poisoned.
I initially intended to ask if there was any particular reason why the wiki example used prev (I had a hunch there was no good reason, but I couldnāt directly map the previous discussion about final vs prev in this thread to this example. But forgot to actually add that to my initial comment).
Thanks for the clarification, that in this instance too prev was the wrong choice.
I hope this doesnāt go too much off topic here, but:
Despite having spent a good amount of time reading through the official and inofficial wiki, the nixpkgs manual, and forum posts, I am still learning. And my initial reply was also in trying to better understand the wiki snippet.
which appears to correspond to what was discussed in this thread here.
I assume the syntax (final.stdenv.hostPlatform) system; means basically system = final.stdenv.hostPlatform.system;.
I started reading Overlays - Official NixOS Wiki but this aspect of the inherent syntax appears to be still missing in that page.
For a newcomer I think the nix.dev tutorials are a bit nicer, especially the language one: Nix language basics ā nix.dev documentation (inherit is this heading). Itās really the first document you should read when learning about nix.
This thread is very informative, but all I get is pointed at nixpkgs as the repo with the issue, which I canāt believe.
My error looks like:
$> sudo NIX_ABORT_ON_WARN=1 nixos-rebuild switch --flake '.#'(sys host|get hostname) --cores 2 --impure
warning: Git tree '/home/user/nixos' is dirty
building the system configuration...
warning: Git tree '/home/user/nixos' is dirty
trace: evaluation warning: 'system' has been renamed to/replaced by 'stdenv.hostPlatform.system'
error:
⦠while calling the 'head' builtin
at /nix/store/pfwrb65dsv8phlsf1m98bvz11cvgb290-source/lib/attrsets.nix:1714:13:
1713| if length values == 1 || pred here (elemAt values 1) (head values) then
1714| head values
| ^
1715| else
⦠while evaluating the attribute 'value'
at /nix/store/pfwrb65dsv8phlsf1m98bvz11cvgb290-source/lib/modules.nix:1147:7:
1146| // {
1147| value = addErrorContext "while evaluating the option `${showOption loc}':" value;
| ^
1148| inherit (res.defsFinal') highestPrio;
(stack trace truncated; use '--show-trace' to show the full trace)
error: evaluation aborted with the following error message: 'NIX_ABORT_ON_WARN=true; warnings are treated as unrecoverable errors.'
Command 'nix --extra-experimental-features 'nix-command flakes' build --print-out-paths '.#nixosConfigurations."mook".config.system.build.toplevel' --no-link --cores 2 --impure' returned non-zero exit status 1.
That /nix/store path is nixPkgs, and the .version file in it containts 26.11 so I can only presume itās the current one (and not one Iām using for the previous version of Orca-Slicer), but I donāt understand.
You might have to thoroughly reed the full trace to get a hint where the warning is caused, not where it is printed.
These are generally nasty to debug, and if git grey system does not list any valid offenders anymore you are fine and you have to wait for whatever input is causing the issue to update.
Also, the use of --impure is probably not related but a very red flag. It often is a sign for using bad techniques in the configuration. More often than not it is working around deliberate design choices of flakes to a point where flakes not used anymore beyond their lock file. In that case itās often better to just use npins or tack or whatever.
Or it can be required to get the abort on warning to work, which is the method needed to get the warning context with lix. I know the thread is old, so it can be hard to remember that bit
Okay, it is in my flake, I misunderstood that I was looking for ā${system}ā, but āsystemā is an issue. And I needed to follow @frieder on what I had to fix.