Error: No such file or directory when trying to add new modules

I’m trying to get a flakes configuration for NixOS up and running.

This is my `flake.nix`:
{
	description = "System configuration";
	
	nixConfig = {
		extra-substituters = [ "https://nix-community.cachix.org" ];
		extra-trusted-public-keys = [ "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" ];
	};

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

  	outputs = { nixpkgs, home-manager, ... }:
		let
			system = "x86_64-linux";
			
			pkgs = import nixpkgs {
				inherit system;
				config.allowUnfree = true; # Allow proprietary software.
			};
		in {
			nixosConfigurations = {
				LBNB = nixpkgs.lib.nixosSystem {
					inherit system;

					modules = [
						./hosts/LBNB
						home-manager.nixosModules.home-manager {
							home-manager.useGlobalPkgs = true;
							home-manager.useUserPackages = true;
							home-manager.users.swj = import ./home;
						}
					];
				};
			};
		};
}
This is my `hosts/LBNB/default.nix`:
{ ... }: {
	imports = [
		./hardware-configuration.nix
		../../modules/system.nix
	];

	# Use the systemd-boot EFI boot loader.
	boot.loader = {
		systemd-boot.enable = true;
		efi.canTouchEfiVariables = true;
	};
  	
	networking.hostName = "LBNB";

	networking.networkmanager.enable = true;
	
	# Enable touchpad support.
	services.xserver.libinput.enable = true;

	system.stateVersion = "23.05";
}
This is my `modules/system.nix`
{ config, pkgs, ...}: {
        nix.settings.experimental-features = [ "nix-command" "flakes" ];
        nix.settings.auto-optimise-store = true;

	time.timeZone = "America/Sao_Paulo";

	i18n.defaultLocale = "en_US.UTF-8";

	services.xserver = {
		enable = true;
		displayManager.sddm.enable = true;
		desktopManager.plasma5.enable = true;

		layout = "br";
	};
	
	nixpkgs.config.allowUnfree = true;

	programs.partition-manager.enable = true;

	environment.systemPackages = with pkgs; [ vim wget curl git ];
	
	security.rtkit.enable = true; # Recommended for pipewire

	services = {
		# Enable sound with pipewire.
		pipewire = {
			enable = true;
			alsa.enable = true;
			alsa.support32Bit = true;
			pulse.enable = true;
		};
	};

	users.users.swj = {
		isNormalUser = true;
		initialPassword = "";
		extraGroups = [ "wheel" "networkmanager" ];
	};
}
This is my `home/default.nix`
{ config, pkgs, ...}: {
	imports = [ ./programs ];

	home = {
		username = "swj";
		homeDirectory = "/home/swj";
		stateVersion = "23.05";
	};

	nix.settings.trusted-users = [ "swj" ];

	programs.home-manager.enable = true;
}
This is my `home/programs/default.nix`
{ ... }: {
	imports = [ ./common.nix ./steam.nix ];
}
This is my `home/programs/common.nix`
{ pkgs, ... } : {
	home.packages = with pkgs; [
		obsidian
		neovim
		firefox
		pavucontrol
	];
}
And this is my `home/programs/steam.nix`
{ pkgs, ... }: {
	programs.steam = {
		enable = true;
		remotePlay.openFirewall = true;
		dedicatedServer.openFirewall = true;
	};
}

I use sudo nixos-rebuild switch --flake #. from my root directory to compile my system, however, after adding steam.nix as a module to programs I get the error:

error: getting status of '/nix/store/...-source/home/programs/steam.nix': No such file or directory

Which is weird because there were no errors before when I included common.nix which is in the same directory.
Help would be greatly appreciated.

Did you git add the files?

1 Like

That worked!
I didn’t know Nix took that into consideration. However, now I’m getting this when I run nixos-rebuild:

error: The option `home-manager.users.swj.programs.steam` does not exist. Definition values:
- In `/nix/store/...-source/home/programs/steam.nix`:
    {
        enable = true;
    }

I was also getting this error after re-running nixos-rebuild:

error: cached failure of attribute 'nixosConfigurations.LBNB.config.system.build.toplevel'

Home manager doesn’t have steam options by default. And it is a general recommendation to enable steam on the system as that sets required 32bit graphic and sound drivers up.

Oh, I see. Thanks!
As a follow up question, how do I remove the cached attribute failures so I can run nixos-rebuild again after encountering an error?