How to fix `evaluation warning: 'system' has been renamed to/replaced by 'stdenv.hostPlatform.system'`

okay, I switched it to:

              (
                {
                  pkgs,
                  inputs,
                  ...
                }:
                {
                  _module.args = {
                    unstablePkgs = import inputs.unstable {
                      inherit (pkgs) config overlays;
                      localSystem = pkgs.stdenv.hostPlatform;

                    };
                  };
                }
              )

and it does work indeed. Thank you very much !

1 Like

@Erwyn also see specialArgs

_module.args is preferable over specialArgs, where possible. (In this case, it’s possible.)

1 Like

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

1 Like

Thanks for the helpful information! In my case it was caused by this:

https://gitlab.com/ahoneybun/nix-configs/-/blob/main/flake.nix?ref_type=heads#L89

Changing:

${prev.system}

to this:

${prev.stdenv.hostPlatform.system}

fixed it for me.

Use final not prev, whenever possible.

1 Like

What is the difference in this context? It does seem to replace the version of helix from nixpkgs with the upstream tagged version.

final doesn’t depend on overlay ordering. This makes more sense for stdenv, and especially stdenv.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.

See also the wiki entry for this, it’s actually one of the better pages: Overlays - Official NixOS Wiki

3 Likes

Here’s an example where it really mattered: Packages in overlay arguments are different from regular package-set?

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.

3 Likes

I’m still a bit lost, I have the following in my system flake.nix:

          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.system;
                  config.allowUnfree = true;
                  config.android_sdk.accept_license = true;
                };
              })
            ];

which I assume causes the warning for me.

This is based on this example from the wiki NixOS system configuration - Official NixOS Wiki

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?

Because the LHS is the name for the argument to the pkgs instance, which is a completely different thing then the system you read from it.

4 Likes

Stop using prev for no reason. Always use final unless you have a reason not to.

2 Likes

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.

1 Like

I see, that makes sense. Thanks.

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.

It seems like as a result of this discussion someone updated the example in NixOS system configuration - Official NixOS Wiki to

                unstable = import nixpkgs-unstable {
                   inherit (final) config;
                   inherit (final.stdenv.hostPlatform) system;
                };

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.

inherit has nothing to do with overlays. I agree that the wiki is a lost cause, check the manuals instead. Nix syntax will be in the nix manual.

2 Likes

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.

3 Likes

I was looking for this sort of recommendation, but I wasn’t expecting to find it here. That’s great! Thank you :smiley:

1 Like