Flake path does not provide attribute 'packages.x86_64-linux...'

I’m trying to learn Nix and I’m following along this video and it has been quite helpful, however, when configuring home-manager as a module via flakes I’m stuck.

sudo nixos-rebuild switch --flake.#mike returns:

flake 'path:/etc/nixos' does not provide attribute 'packages.x86_64-linux.nixosConfigurations."mike".config.system.build.nixos-rebuild', 'legacyPackages.x86_64-linux.nixosConfigurations."mike".config.system.build.nixos-rebuild' or 'nixosConfigurations."mike".config.system.build.nixos-rebuild'

The entire flake.nix file:

{
  description = "A very basic flake";


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

  outputs = { self, nixpkgs, home-manager }: 
    let 
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        inherit system;
        config.allowUnfree = true;
      };
      lib = nixpkgs.lib;
    in {
      nixosConfigurations = {
        MAIN = lib.nixosSystem { 
          inherit system;
          modules = [ 
            ./configuration.nix
            ./hardware-configuration.nix
            home-manager.nixosModules.home-manager {
              home-manager.useGlobalPkgs = true; 
              home-manager.useUserPackages = true;
              home-manager.users.mike = {
                imports = [ ./hosts/MAIN/home.nix ];

              };
            }
          ];
        };
      };  
        nixbook = lib.nixosSystem { 
          inherit system;
          modules = [ 
            ./configuration.nix
            ./hardware-configuration.nix
          ];
        };
      };

    }


What have I missed?

Neither of the NixOS configurations listed are named mike, which is why nixos-rebuild is not finding one with that name.

2 Likes
~ ❯ nix flake show /etc/nixos
git+file:///etc/nixos?ref=master&rev=3e7f3d39c6649045d03c49126480deea78762c37
├───formatter
│   └───x86_64-linux: package 'alejandra-1.4.0'
└───nixosConfigurations
    └───odd: NixOS configuration

For me, odd is my NixOS configuration. So to build like that I use following: sudo nixos-rebuild switch --flake /etc/nixos#odd.

1 Like

This isn’t related to your question itself, but I just wanted to point out that this formatting is misleading. It gives the mistaken impression that home-manager.nixosModules.home-manager is a function taking an attrset argument. It is not. It is a nixos module, and the attrset following it is also a nixos module. They’re sequential elements of the list, not a function application. I think the existence of example code like this helps contribute to the prevalence of this mistake among new users, and I wanted to make sure that wasn’t happening here. Fortunately, the home-manager manual’s example that I assume started this has been changed to something less misleading, but this format still persists in the wild a lot.

1 Like

To get back to the OP question, @0293124 you should use either of:

  • sudo nixos-rebuild switch --flake .#MAIN
  • sudo nixos-rebuild switch --flake .#nixbook

Depending on which configuration you want to install.

The .#<name> thing means “use the flake output <name> from the current directory”, and nix will pick the correct type of output based on the command you’re using.

I.e., nixosConfigurations for nixos-rebuild, packages for nix run, checks for nix flake check, …

3 Likes