Open samuela opened 7 months ago
you need to do let pkgs = import nixpkgs { inherit system; };
instead
Thanks @lunaneff -- that indeed was the issue. I'm confused however: Specifying system
isn't required in other invocations, eg in nix-shell
. Why is it failing here? Shouldn't it ought to default to the host system?
This seems like a real footgun.
@samuela nix-shell
defaults to impure evaluation, whereas nix shell
defaults to pure evaluation (unless it is called with --file
).
Shouldn't it ought to default to the host system? that's what it's trying to do, using
builtins.currentSystem
, but that information is not available in pure evaluation mode.
also, you should really be doing pkgs = nixpkgs.legacyPackages.${system};
to actually import the packages from the flake. currently you are implicitly asking nix to evaluate the default.nix
file found in the same directory as the flake.nix
file.
perhaps we could change impure.nix to do something like builtins.currentSystem or throw "it seems you are trying to load nixpkgs in pure evaluation mode, please specify system"
we could even check for the presence of builtins.getFlake
to decide if we should give flake-related hints, like recommending using legacyPackages.${system}
.
Ah yeah that makes sense! I think that would be a big improvement in terms of clarity
also, you should really be doing pkgs = nixpkgs.legacyPackages.${system}; to actually import the packages from the flake.
why should i be using legacyPackages
? that sounds like... legacy code?
Also, when using nixpkgs.legacyPackages.${system}
how would one specify config
options? Eg what's the equivalent of
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
why should i be using
legacyPackages
? that sounds like... legacy code?
Because legacyPackages
is for the legacy package method, the multi-level attribute way Nixpkgs does it. The regular packages is for your Flake's own packages.
that sounds like... legacy code?
It's not, it's how nixpkgs exposes its packages in the first place.
also, you should really be doing pkgs = nixpkgs.legacyPackages.${system}; to actually import the packages from the flake. currently you are implicitly asking nix to evaluate the default.nix file found in the same directory as the flake.nix file.
legacyPackages.${system}
is actually implemented as import ./. { inherit system; }
— if you're not passing overlays or config options to Nixpkgs, these two forms are equivalent
it's equivalent for nixpkgs specifically, at the current time, but for other flakes, and possibly future nixpkgs versions, it may be different, so it shouldn't be encouraged.
Issue description
I have the following
flake.nix
:And I'm seeing the following error when attempting to build:
Steps to reproduce
I've posted my complete setup, including
flake.lock
in this gist.Technical details