Help setting seperate host configs in flake.nix

      nixosConfigurations = {
        ########################
        yuki = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/yuki/configuration.nix ];
          specialArgs = {
            hostname = "yuki";
            inherit pkgs-unstable inputs;
          };
        };

       ############################
        kumokon = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/kumokon/configuration.nix ];
          specialArgs = {
            hostname = "kumokon";
            inherit pkgs-unstable inputs;
          };
        };
         ###########################
        thinker = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/thinker/configuration.nix ];
          specialArgs = {
            hostname = "thinker";
            inherit pkgs-unstable inputs;
          };
        };
        ############################
      };

home manager config

      homeConfigurations = {
        ##########################
        "safri@yuki" = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          extraSpecialArgs = {inherit inputs;};

          modules = [ ./hosts/yuki/home.nix ];
          specialArgs = { hostname = "yuki"; };
        };
        #############################
        "safri@thinker" = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          extraSpecialArgs = {inherit inputs;};

          modules = [ ./hosts/yuki/home.nix ];
          specialArgs = { hostname = "thinker"; };
        };
        ###########################
      };

The configuration builds when “yuki = nix…” is “nixos = nix…” even though I changed my hostname

in both cases,

sudo nixos-rebuild switch --flake ~/.nix#yuki

fails to build (and same with home manager)

safri@yuki:~/.nix/ > nh os switch ~/.nix#yuki
> Building NixOS configuration
warning: Git tree '/home/safri/.nix' is dirty
error: flake 'git+file:///home/safri/.nix' does not provide attribute 'packages.x86_64-linux.yuki.config.system.build.toplevel', 'legacyPackages.x86_64-linux.yuki.config.system.build.toplevel' or 'yuki.config.system.build.toplevel'
┏━ 1 Errors: 
┃ error: flake 'git+file:///home/safri/.nix' does not provide attribute 'packages.x86_64-linux.yuki.config.system.build.toplevel', 'legacyPackages.x86_64-linux.yuki.config.system.build.toplevel' or 'yuki.config.system.build.toplevel'
┣━━━                                                            
┗━ ∑ ⚠ Exited with 1 errors reported by nix at 13:33:12 after 0s
Error: 
   0: Command exited with status Exited(1)

Location:
   src/commands.rs:262

dotfiles

If anybody could help fix my flake to allow for host separated configuration that would be greatly appreciated.

Hm, I’ve never used nh, but it doesn’t look like it’s working correctly. The error you should be getting is something like:

building the system configuration...
warning: Git tree '/home/tlater/.local/src/dotfiles' is dirty
error: flake 'git+file:///home/tlater/.local/src/dotfiles' does not provide attribute 'packages.x86_64-linux.nixosConfigurations."aaaaa".config.system.build.toplevel', 'legacyPackages.x86_64-linux.nixosConfigurations."aaaaa".config.system.build.toplevel' or 'nixosConfigurations."aaaaa".config.system.build.toplevel'

The main difference being:

or 'yuki.config.system.build.toplevel'

vs

or 'nixosConfigurations."aaaaa".config.system.build.toplevel'

As such, I would guess nh just doesn’t implement this correctly. Try using nixos-rebuild.

safri@yuki:~/ > sudo nixos-rebuild switch --flake ~/.nix#yuki
[sudo] password for safri: 
warning: Git tree '/home/safri/.nix' is dirty
error: flake 'git+file:///home/safri/.nix' does not provide attribute 'packages.x86_64-linux.nixosConfigurations."yuki".config.system.build.nixos-rebuild', 'legacyPackages.x86_64-linux.nixosConfigurations."yuki".config.system.build.nixos-rebuild' or 'nixosConfigurations."yuki".config.system.build.nixos-rebuild'
{
  description = "My first flake";

  inputs = {
    nixpkgs.url = "nixpkgs/nixos-25.05";
    nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager/release-25.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    firefox-addons = {
      url = "gitlab:rycee/nur-expressions?dir=pkgs/firefox-addons";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nyaa = {
      url = "github:Beastwick18/nyaa";
      inputs.nixpkgs.follows = "nixpkgs";
    };


    textfox.url = "github:adriankarlen/textfox";

  };

  outputs = { self, nixpkgs, nixpkgs-unstable, home-manager, nur, nyaa, firefox-addons, ... }@inputs: let

      system = "x86_64-linux";
      pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
      lib = nixpkgs.lib;
      pkgs = nixpkgs.legacyPackages.${system};

    in {

      nixosConfigurations = {
        yuki = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/yuki/configuration.nix ];
          specialArgs = {
            hostname = "yuki";
            inherit pkgs-unstable inputs;
          };
        };
        kumokon = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/kumokon/configuration.nix ];
          specialArgs = {
            hostname = "kumokon";
            inherit pkgs-unstable inputs;
          };
        };
        thinker = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/thinker/configuration.nix ];
          specialArgs = {
            hostname = "thinker";
            inherit pkgs-unstable inputs;
          };
        };
      };

      homeConfigurations = {
        "safri@yuki" = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          extraSpecialArgs = {inherit inputs;};

          modules = [ ./hosts/yuki/home.nix ];
        };
        "safri@thinker" = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          extraSpecialArgs = {inherit inputs;};

          modules = [ ./hosts/yuki/home.nix ];
        };
      };
    };

}

Everything is working now with this flake, I don’t think it had anything to do with the flake though, I think I just needed to add “nixosConfigurations.yuki” to the build command.

safri@yuki:~/ > nh os switch ~/.nix#nixosConfigurations.yuki  

You should not need to. Something is very wrong:

That is simply not the correct attribute to be building. if I were you I would check if the nixos-rebuild script is actually the same as upstream’s. I guess it’s possible you’ve grabbed a newer version of it than your actual nixpkgs version and the attribute is changing or such?

both nixos-rebuild and nixos-rebuild-ng seem to build that attribute

Yep, fair enough, it’s done when using switch or boot.

Something is definitely still broken, however.

Yea I’m honestly not sure whats happening but its able to build when I preface “nixosConfigurations” and I’m able to specify which host I’m building from.

There was also a period when my server “kumokon” was able to run “nh os switch ~/.nix#$host” just fine but I can’t seem to reproduce that anymore over ssh.