Flake Path Error

Flake

‎‎
‎ Running sudo nixos rebuild ends up with this error:

error: flake 'path:/etc/nixos' does not provide attribute 'packages.x86_64-linux.nixosConfigurations."nixos".config.system.build.nixos-rebuild', 'legacyPackages.x86_64-linux.nixosConfigurations."nixos".config.system.build.nixos-rebuild' or 'nixosConfigurations."nixos".config.system.build.nixos-rebuild'
flake.nix
{
  description = "NixOS configuration";

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

  outputs = inputs@{ self, nixpkgs, home-manager, ... }:
    let
      user = "space";
      configDir = "nix-config";
    in {
      nixosConfigurations = import ./hosts {
        inherit (nixpkgs) lib;
        inherit inputs nixpkgs home-manager user configDir;
      };
    };
}

default.nix
{ lib, inputs, nixpkgs, home-manager, user, configDir, ... }:

let
  system = "x86_64-linux";
  pkgs = import nixpkgs {
    inherit system;
    config.allowUnfree = true;
  };
  lib = nixpkgs.lib;
  configImports = [
    ./configuration.nix
  ];
  hmImports = [
    (import ./home.nix)
  ];
  desktopHmImports = hmImports ++ [
    (import ./home-desktop.nix)
  ];
  hmArgs = { inherit user configDir; };
in
{
   desktop = lib.nixosSystem {
    inherit system;
    specialArgs = { inherit user; };
    modules = configImports ++ [
      ./desktop
      ./desktop.nix
      {
        boot.loader.grub.gfxmodeEfi = "1920x1080";
        networking.hostName = "${user}";
      }
      home-manager.nixosModules.home-manager {
        home-manager = {
          useUserPackages = true;
          extraSpecialArgs = hmArgs;
          users.${user} = {
            imports = desktopHmImports ++ [
              (import ./desktop/home.nix)
            ];
          };
        };
      }
    ];
  };
}

Try sudo nixos-rebuild /etc/nixos#desktop.

Looking at the error message, apparently nixos-rebuild, if not given a specific output, assumes you called your nixosConfiguration nixos. That is your hostname? May want to change it to something more unique.

You can alternatively change desktop to nixos, or set your hostname to desktop.

I changed the hostname from nixos to desktop, but now I get the following error while running sudo nixos-rebuild:

No manual entry for nixos-rebuild

That would be the output of man nixos-rebuild if it’s not installed. Do you have some kind of shell extension that tries to run man on failing binaries or something? Is that the full error?

Yes, it’s the full error. I’ll shortly post the .nix files as to give more context for the problem, as well as clarify what I’m trying to achieve.

Oh, nevermind, sorry I forgot an arg, you need sudo nixos-rebuild --flake /etc/nixos#desktop.

Very strange this manpage thing, I guess you explicitly disabled those and that causes nixos-rebuild to trip up if you misuse it?

Context and Goal

Upon discovering this user’s nixos configuration, I decided to try something similar, integrating flakes, organizing and installing packages with home-manager instead of the usual way:

.Nix Files


home.nix
{ user, ... }:

{
  home = {
    username = "${user}";
    homeDirectory = "/home/${user}";
    sessionVariables = {
      CARGO_TARGET_DIR = "$HOME/.target/";
    };

    stateVersion = "22.05";
  };
}

home-desktop.nix
{ inputs, config, pkgs, user, ... }:

{
  imports = [
    ./software.nix
  ]; 

  programs.home-manager.enable = true;
  programs.direnv.enable = true;

  # Enable Home Manager and Fish shell.
  programs.home-manager.enable = true;
  programs.fish = {
    enable = true;
    interactiveShellInit = "set fish_greeting";
  };
}

software.nix
{ pkgs, ... }:

{
  home.packages = with pkgs; [
    # Command line utilities
    wget
    neofetch
    killall
    htop
    unzip
    pipes
    wine
    pandoc
    texlive.combined.scheme-full
    lsof
    openssl
    unrar
    mesa
    ntfs3g
    fish
    fishPlugins.done
    fishPlugins.fzf-fish
    fishPlugins.forgit
    fishPlugins.hydro
    fzf
    fishPlugins.grc
    grc
    poppler_utils
    gnumake
    multipath-tools
    cmake
    xclip

    # Programming languages and tools
    jdk
    git
    kitty
    neovim
    python3Full
    libgccjit
    python311Packages.setuptools
    qt6.full
    gamemode
    gtk3

    # Tray applications
    networkmanagerapplet # nm-applet

    # GNOME apps
    gnome.cheese
    gnome.nautilus
    gnome.file-roller
    gnome.gnome-calculator
    gnome.gnome-disk-utility
    gnome.simple-scan
    gnome.gnome-tweaks

    # Applications
    androidStudioPackages.canary
    figma-linux
    firefox
    anki-bin
    mpv
    gimp
    krita
    inkscape
  ];
}

configuration.nix
{ config, pkgs, user, inputs, ... }:

let
  inkscape = pkgs.callPackage /etc/nixos/inkscape.nix {};
  gimp = pkgs.callPackage /etc/nixos/gimp.nix {};
in

{
  # General System Settings
  system.stateVersion = "23.11";
  boot.kernelPackages = pkgs.linuxPackages_latest;
  nix.settings.experimental-features = [ "nix-command" "flakes" ];
  nixpkgs.config.allowUnfree = true;
  imports = [ ./hardware-configuration.nix ];

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

  # Remove NixOS Manual
  documentation.nixos.enable = false;
  
  # Network config
    networking = {
    hostName = "space";
    networkmanager.enable = true;
  };

  # User Configurations
  users.users.${user} = {
    isNormalUser = true;
    extraGroups = [ "wheel" "audio" "video" "optical" "storage" "networkmanager" ];
    initialPassword = "password";
  };
  users.defaultUserShell = pkgs.fish;

  # X11 and GNOME
  services.xserver = {
    enable = true;
    layout = "us";
    xkbVariant = "";
    displayManager.gdm.enable = true;
    desktopManager.gnome.enable = true;
  };
  environment.gnome.excludePackages = (with pkgs; [
    gnome-photos
    gnome-tour
  ]) ++ gnomePackages;
  
  # Virtualisation
  virtualisation.docker = {
    enable = true;
    storageDriver = "btrfs";
    rootless = {
      enable = true;
      setSocketVariable = true;
    };
  };

  # Other Services
  services.gvfs.enable = true;
  nix.gc = {
    automatic = true;
    options = "--delete-generations 7d";
  };

  # Environment Variables
  environment.variables.EDITOR = "nvim";

  environment.gnome.excludePackages = (with pkgs; [
  gnome-photos
  gnome-tour
]) ++ (with pkgs.gnome; [
    baobab      # disk usage analyzer
    cheese      # photo booth
    eog         # image viewer
    epiphany    # web browser
    gedit       # text editor
    simple-scan # document scanner
    totem       # video player
    yelp        # help viewer
    evince      # document viewer
    file-roller # archive manager
    geary       # email client
    seahorse    # password manager
    
    # these should be self explanatory
    gnome-calculator gnome-calendar gnome-characters gnome-clocks gnome-contacts
    gnome-logs gnome-maps gnome-music gnome-screenshot 
    gnome-system-monitor gnome-weather pkgs.gnome-connections
  ]);

  # Programs
  programs.neovim = {
    enable = true;
    defaultEditor = true;
  };
  programs.gamemode.enable = true;
  programs.fish.enable = true;

  # Supported Filesystems
  boot.supportedFilesystems = [ "ntfs" ];
}

default.nix
{ lib, inputs, nixpkgs, home-manager, user, configDir, ... }:

let
  system = "x86_64-linux";
  pkgs = import nixpkgs {
    inherit system;
    config.allowUnfree = true;
  };
  lib = nixpkgs.lib;
  configImports = [
    ./configuration.nix
  ];
  hmImports = [
    (import ./home.nix)
  ];
  desktopHmImports = hmImports ++ [
    (import ./home-desktop.nix)
  ];
  hmArgs = { inherit user configDir; };
in
{
   desktop = lib.nixosSystem {
    inherit system;
    specialArgs = { inherit user; };
    modules = configImports ++ [
      ./desktop
      ./desktop.nix
      {
        boot.loader.grub.gfxmodeEfi = "1920x1080";
        networking.hostName = "${user}";
      }
      home-manager.nixosModules.home-manager {
        home-manager = {
          useUserPackages = true;
          extraSpecialArgs = hmArgs;
          users.${user} = {
            imports = desktopHmImports ++ [
              (import ./desktop/home.nix)
            ];
          };
        };
      }
    ];
  };
}

desktop.nix
{ config, pkgs, lib, ... }:

{
  # Printing and sound
  services.printing.enable = true;
  sound.enable = true;
  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;

  # Pipewire config
  services.pipewire = {
    enable = true;
    alsa = { enable = true; support32Bit = true; };
    pulse.enable = true;
  };

}



Please be aware that I’m still in the midst of editing my .nix files, so they may be a bit unorganized. Also changed the hostname to be the same as the username space.

Oh, nevermind, sorry I forgot an arg, you need sudo nixos-rebuild --flake /etc/nixos#desktop.

Throws the same error

Yeah, I guess this causes the man message. Probably worth a bug report.

Ok, this should be the final try: sudo nixos-rebuild switch --flake /etc/nixos#desktop

error: getting status of '/nix/store/w28srw2lqqp3lww3603r3nsz3nvv56g5-source/hosts/desktop': No such file or directory

If your flake is in a git repository, you need to make sure that git knows about every file that nix will access. Nix will copy the flake into the nix store before evaluating, and it uses git to figure out what files to copy.

I.e., you need something like:

git -C /etc/nixos add --all

The flake is not in a git repository

Ah, well, then this directory doesn’t exist and you shouldn’t try to import it in your configuration.

After learning a bit more about flakes and improving the .nix files, I ended up with a working flake integrated system. Had to make a new folder called “desktop” in the “hosts” folder, like in the git repository (with the needed .nix files).

1 Like