Installing only a single package from `unstable`

Nah, just wherever you want to use a package from nixpkgs-unfree-master. It’s actually not necessary at all, it’s just restating that as a variable for readability, this works too:

# configuration.nix
{ pkgs, inputs, ... }: {
  environment.systemPackages = [
    inputs.nixpkgs-unfree-master.legacyPackages.${pkgs.system}.some-package-that-has-not-hit-stable-yet
  ];
}

If that’s too verbose for you, you can always change the name at the specialArgs level:

nixosConfigurations.example = nixpkgs.lib.nixosSystem rec {
  # Using `rec` to create this variable for the whole block since you seem
  # to prefer conciseness, but arguably limiting the number of scoped
  # variables with a `let ... in` is better
  system = "x86_64-linux";
  specialArgs = {
    nixpkgs-unfree-master = inputs.nixpkgs-unfree-master.legacyPackages.${system};
  };
};

At which point you can use:

# configuration.nix
{ pkgs, nixpkgs-unfree-master, ... }: {
  environment.systemPackages = [
    nixpkgs-unfree-master.some-package-that-has-not-hit-stable-yet
  ];
}

But this isn’t as popular, because you will likely eventually have other flake inputs with more complex outputs that include modules and such, where you don’t really want to collapse everything down. You can also do a mix of the two, of course.

The overall idea is just to limit what you’re stuffing into overlays for no real reason, because, while they are very powerful, they can cause very hard to understand errors, and tend to increase evaluation cost. Overlays are great for recursively replacing dependencies, using them just to create new attributes is a holdover from the only way you could depend on other projects pre-flakes.

4 Likes