My NixOS Flake based Configuration is failing to start

I am running the following sudo nixos-rebuild switch --flake .#NixDesk1 -vvv
and it errors with the following

error: flake ‘git+file:///home/matt/sources/nix-config’ does not provide attribute ‘packages.x86_64-linux.nixosConfigurations.“NixDesk1”.config.system.build.nixos-rebuild’, ‘legacyPackages.x86_64-linux.nixosConfigurations.“NixDesk1”.config.system.build.nixos-rebuild’ or ‘nixosConfigurations.“NixDesk1”.config.system.build.nixos-rebuild’

What am I doing wrong here that it is not able to find/work with NixDesk1?

flake.nix

{
  description = "NixOS Configuration with Flakes";

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

  outputs = { self, nixpkgs, home-manager, flake-utils, ... }: flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: 
    let
      pkgs = import nixpkgs {
        inherit system;
        config.allowUnfree = true;
      };
      lib = nixpkgs.lib;
    in {
      nixosConfigurations = {
        NixDesk1 = lib.nixosSystem {
          inherit system;
          modules = [
            ./hosts/NixDesk1/configuration.nix
            ./hosts/NixDesk1/hardware-configuration.nix
            home-manager.nixosModules.home-manager
          ];
        };
      };

      homeManagerConfigurations.matt = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        modules = [
          ./users/matt/home.nix
        ];
      };
    }
  );
}

./hosts/NixDesk1

{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  # Enable nix-command and flakes
  nix = {
    package = pkgs.nixFlakes;
    extraOptions = ''
      experimental-features = nix-command flakes
    '';
  };

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  networking.hostName = "nixdesk";

  # Enable networking
  networking.networkmanager.enable = true;

  # Sound Enable
  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;

  # Enable necessary services
  services = {
    automatic-timezoned.enable = true;
    # Enable Hyprland
    xserver = {
      enable = true;
      layout = "us";
      xkbOptions = "";
      displayManager.sddm.enable = false;
      displayManager.gdm.enable = false;
      displayManager.lightdm = {
        enable = true;
        greeters.simple.enable = true;
      };
      desktopManager.hyprland.enable = true;
    };

    # Enable CUPS to print documents.
    printing.enable = true;

    # Enable sound with pipewire.
    pipewire = {
      enable = true;
      alsa.enable = true;
      alsa.support32Bit = true;
      pulse.enable = true;
      # If you want to use JACK applications, uncomment this
      #jack.enable = true;

      # use the example session manager (no others are packaged yet so this is enabled by default,
      # no need to redefine it in your config for now)
      #media-session.enable = true;
    };

    openssh.enable = true;
  };

  # User configuration
  users.users.your-username = {
    isNormalUser = true;
    extraGroups = [ "wheel" "networkmanager" ];
    shell = pkgs.zsh;
  };

  # System packages
  environment.systemPackages = with pkgs; [
    # terminal utilities
    neovim
    wget
    git
    lf
    zsh
    # Fonts
    noto-fonts
    noto-fonts-cjk
    noto-fonts-emoji
    # Hyperland
    hyprland
    # Applications
    google-chrome
    vscode
    libreoffice-qt
    hunspell
    hunspellDicts.en_US

  ];

  # Allow unfree packages if needed
  nixpkgs.config.allowUnfree = true;

  # Enable Home Manager
  home-manager.users.matt = import ../../users/matt/home.nix;

  system.stateVersion = "24.05";
}

./users/matt/home.nix

{ config, pkgs, ... }:

{
  home.username = "matt";
  home.homeDirectory = "/home/matt";

  programs.zsh = {
    enable = true;
    ohMyZsh.enable = true;
    # Additional Zsh configurations
  };

  programs.neovim = {
    enable = true;
    plugins = with pkgs.vimPlugins; [
      vim-nix
      # Add Neovim plugins here
    ];
    extraConfig = ''
      " Neovim configurations
    '';
  };

  home.packages = with pkgs; [
    lf
    ranger
    # Additional user-specific packages
  ];

  fonts.fontconfig = {
    enable = true;
    defaultFonts = [
      "Noto Sans"
      "Noto Sans CJK"
      "Noto Emoji"
      # Add any additional fonts
    ];
  };

  # Additional Home Manager modules
  # ...
}

I am running nix 2.18.8 and nixos 24.05.5596.d51c28603def (Uakari)

When you get a “flake XYA does not provide attribute” error, you can use nix flake show to list what outputs are provided by your flake.

$ nix flake show
path:/home/lelgenio/flake?lastModified=1729741534&narHash=sha256-5lScOzxBpge2D5xQXLf04glnpJJG25EEpqK8EMzqXNc%3D
├───homeManagerConfigurations: unknown
└───nixosConfigurations
    └───x86_64-linux: NixOS configuration

Your flake provides nixosConfigurations.x86_64-linux.NixDesk1 instead of nixosConfigurations.NixDesk1, this is due to flake-utils.

{
  description = "NixOS Configuration with Flakes";

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

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

      homeManagerConfigurations.matt = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        modules = [ ./users/matt/home.nix ];
      };
    };
}

Fixed:

$ nix flake show
path:/home/lelgenio/flake?lastModified=1729741745&narHash=sha256-MsBFdBzrdCXT2uoVX1ccffpv7zYeSOrhrMBXcS3YFJE%3D
├───homeManagerConfigurations: unknown
└───nixosConfigurations
    └───NixDesk1: NixOS configuration
1 Like

You’re not supposed to put nixosConfigurations in the flake-utils.lib.eachSystem. You’re producing nixosConfigurations.x86_64-linux.NixDesk1 = lib.nixosSystem ... but you need to just produce nixosConfigurations.NixDesk1.

1 Like