Path /nix/store does not exist

i was planning to restructure my nix conf. it looked like this
flake.nix
flake.lock
nixos/
–>configuration.nix
–>an515-58.nix // hardware-configuration
–>home.nix

now i want to change it into
flake.nix
flake.lock
nixos/
–>configuration.nix
–>an515-58.nix
home/
–>default.nix
–>hyprland
–>waybar
–>nixvim

i added home-manager.users.yoda = import ./home // or ./home/default.nix and the error comes
here is my flake.nix

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";

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

    nixvim = {
      url = "github:nix-community/nixvim";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, home-manager, nixvim, ... }@inputs:
  let
    system = "x86_64-linux";
    pkgs = import nixpkgs {
      inherit system;

      config = {
        allowUnfree = true;
      };
    };
  in

  {
  nixosConfigurations = {
    dosed = nixpkgs.lib.nixosSystem {
      specialArgs = { inherit inputs system; };
      
      modules = [
        ./nixos/configuration.nix
	home-manager.nixosModules.home-manager {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
	    home-manager.backupFileExtension = "backup";
            home-manager.users.yoda = import ./home/default.nix;
            home-manager.extraSpecialArgs = { inherit inputs; };
        }
      ];
    };

  };

  };
}

when i try rebuilding it with sudo nixos-rebuild switch --flake ~/system#dosed,
error: path ‘/nix/store/ayl73dmdcrb4djflqx5gris5pw5q4jqv-source/home/default.nix’ does not exist

If your configuration flake is under Git, make sure to git add the new and moved files. (Actually making a commit is not necessary.) Flake inputs only see files in Git that are at least added, though it’s not necessary to git add every change for changes to be seen, only when there are new filenames.

2 Likes

thanks! was wondering why. where did u learn about this?

I learned about this behavior when I ran into it myself. It is one of the things about Nix flakes that people run into early on. The behavior is intentional and not a bug, but it’s so unintuitive that there’s been a lot of discussion about it. Hopefully some day, it can be made more scrutable.

Here is the gist of the situation as I understand it. When using the nix command with Nix flakes, it copies the flake into the Nix store first. (That’s why the filenames you saw were inside the Nix store instead of where you might have expected.) When doing so with a local path, it automatically determines what fetcher to use. If the path appears to be in a Git repository, a Git fetcher is used. The Git fetcher still keeps changes from the working directory intact if there are any, but any “untracked” files are omitted. This is actually a good idea a lot of the time since you may have very large untracked files in a repository. (A good example might be the direnv cache, for example.) But, it can also be inconvenient.

In order to bypass this, you can specify a URL with a scheme instead. e.g. instead of nix build .#output you can do nix build path://${PWD}#output. (The hash part is optional in either syntax, but in the latter syntax we do need an absolute path, hence the use of $PWD instead of ..)

Hope this helps!

2 Likes

The latter copies the .git folder to the store, I recommend just git-adding (since that’s by design).