Running nixos-rebuild does not add new files (have I misunderstood its purpose?)

New to Nix and NixOS and I’ve run into a rather basic issue which I’m hoping someone here could explain to me.

I have a working NixOS flake setup with AwesomeWM. If I edit a file under /etc/nixos and run sudo nixos-rebuild switch --flake .# the file updates as expected. However if I were to create a new file or folder within the nixos dir, these are not created or linked when running sudo nixos-rebuild switch --flake .#. If it is not a nix file, e.g. an awesomewm file residing in the nixos dir which nix links to ~, then the rebuild still completes. If the file is nix-related then the rebuild fails, because the file does not exist in /etc/nix/store/*…

Have I misunderstood the nixos-rebuild command? What command/flag is appropriate in this case?

2 Likes

You need to include it from the main file. Depending on what you are doing imports is what you are searching for.

In this case the default.nix includes home.file.".config/awesome".source = ./config; and it is/was creating this dir in ~/.config. The awesome files are there, presumably from the initial installation, but new ones are not created/linked.

Git repo with the file structure.

When you make a new file in a git repo, it isn’t “tracked” by git until you git add the file. Nix flakes deliberately ignores files in your repo that are not tracked.

4 Likes

I did not know Nix cared about the git status. A lot of the problems I’ve been having now make sense. Thanks!

1 Like

Yea it’s a tad inconvenient but I’ve found it more useful than harmful. I can have tons of crappy scratch files like disk images in my worktree and it won’t result in nix copying all of those into the store every time I do an eval.

1 Like

I wish the nix flake tooling would warn you if you have un-tracked files within your flake repo.

it will warn if your flake repo is dirty with uncommitted files , but it should really warn users about un-tracked files too!

4 Likes

That’s a good idea, and probably not that hard to make a PR for! :slight_smile:

2 Likes

or just use my patch to always include all files that re not in gitignore listed

https://github.com/SuperSandro2000/nix/commit/0943f30c26af72964d812931d1570917ecd4d250

That behavior is really unintuitive and annoying and most people I know hate it.

3 Likes

I’ve been told that this PR Source tree abstraction by edolstra · Pull Request #6530 · NixOS/nix · GitHub
might actually be the answer to my dreams… and solve a lot of issues too!

Thanks for the patch!