Flake, overlay and removed attribute

Hi, I am trying to move to Flake with some overlays and unstable packages. I want to make overlay that will expose unstable packages into the pkgs set through the attribute unstable.

flake.nix:

{
  inputs = rec {
    nixpkgs.url          = "github:NixOS/nixpkgs/nixos-24.05";
    nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";

    home-manager         = {
      url                    = "github:nix-community/home-manager/release-24.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    emacs-community      = {
      url                    = "github:nix-community/emacs-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, home-manager, ... }@inputs: {
    overlays                    = {
      emacs-community  = inputs.emacs-community.overlay;
      nixpkgs-unstable = final: prev: {
        unstable = import inputs.nixpkgs-unstable {
          system             = final.system;
        };
      };
    };

    nixosConfigurations.alaptop = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        home-manager.nixosModules.home-manager
      ];
    };
  };
}

Part of configuration.nix:

  nixpkgs.config = {
    allowUnfree               = true;
    overlays                  = [
      outputs.overlays.emacs-community
      outputs.overlays.nixpkgs-unstable
    ];
  };

Errors:

warning: Git tree '/etc/nixos' is dirty
building the system configuration...
warning: Git tree '/etc/nixos' is dirty
error:
       … while calling the 'head' builtin

         at /nix/store/lzhqf5y9dcgfkg5f7f96jjc814pgrsqy-source/lib/attrsets.nix:1575:11:

         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'

         at /nix/store/lzhqf5y9dcgfkg5f7f96jjc814pgrsqy-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'unstable' missing

       at /nix/store/k23ldgmy7b3izfivrjk5jxixf2g8i293-source/03-DesktopEnvironment/screenshots.nix:18:128:

           17|           keybindings = {
           18|             "Print"                                  = "exec '${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp -d)\" - | ${pkgs.unstable.swappy}/bin/swappy -f - -o - | ${pkgs.wl-clipboard}/bin/wl-copy --type image/png'";
             |                                                                                                                                ^
           19|             "Shift+Print"                            = "exec '${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp -d)\" - | ${pkgs.wl-clipboard}/bin/wl-copy --type image/png'";
       Did you mean notable?


You didn’t share the errors, but you’re not currently passing your overlays into the NixOS configuration. You’ll need to do one of these: Getting inputs to modules in a nix-flake | NobbZ' Blog

Personally I like the specialArgs approach best.

Then, rather than outputs., you’ll want to refer to your flake with the self input.

That way you should be able to achieve what you want, but…

Why? Accessing those packages via inputs.nixpkgs-unstable.legacyPackages.${pkgs.system} is much better.

2 Likes

Problem was fixed using the last of described solutions:

  outputs = { self, nixpkgs, home-manager, lanzaboote, ... }@inputs: {
    nixosConfigurations.alaptop = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        lanzaboote.nixosModules.lanzaboote
        home-manager.nixosModules.home-manager
        {
          nixpkgs.overlays = [(final: prev: {
            unstable      = import inputs.nixpkgs-unstable {
              system             = final.system;
              config.allowUnfree = true;
            };
            emacs-overlay = import inputs.emacs-community  { system = final.system; };
          })];
        }
      ];
    };
  };

You can still do that much more cleanly by passing inputs through specialArgs as described in the blog post, moving that in-line module into your configuration.nix instead.

I wish tutorials would stop documenting things like this, it’s creating a lot of very cumbersome flake.nix es that do way more than they should.