When recently flakifying a simple project from default.nix
to flake, I used this idiom:
{
description = "…;
inputs.nixpkgs.url = "github:NixOS/nixpkgs/release-21.11";
outputs = { self, nixpkgs, nix-filter }:
let
pkgs = pkgs = nixpkgs.legacyPackages.x86_64-linux;
which makes sense to me, given that nixpkg’s flake.nix
says
legacyPackages = forAllSystems (system: import ./. { inherit system; });
in its output, and given that the nix-flake
docs says:
outputs: A function that, given an attribute set containing the outputs of each of the input flakes keyed by their identifier, yields the Nix values provided by this flake. Thus, in the example above, inputs.nixpkgs contains the result of the call to the outputs function of the nixpkgs flake file.
But then I find I have to change the nixpkgs
instantiation a bit, e.g. add an overlay, and I write
{
description = "…;
inputs.nixpkgs.url = "github:NixOS/nixpkgs/release-21.11";
inputs.nix-filter.url = "github:numtide/nix-filter";
outputs = { self, nixpkgs, nix-filter }:
let
pkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [ nix-filter.overlays.default ];
};
How does that work? Isn’t nixpkgs
here a set, and import
expects a path or string?
Independently of the “how”, is this the idiomatic style? Using the nixpkgs
outputs directly when possible, and using import nixpkgs { … }
else?