Issue with NixOS Configuration and Git

I started using this NixOS configuration as a base for my setup.

I decided to move the configuration into a Git repository to keep track of changes, but when I do, it breaks. Running nixos-rebuild results in the following error:

➜  nixos sudo nixos-rebuild switch --flake ~/.dotfiles/nixos#nixos
building the system configuration...
error:
       … while calling the 'head' builtin

         at /nix/store/g8zzlf6drg73c987ii390yicq4c0j778-source/lib/attrsets.nix:922:11:

          921|         || pred here (elemAt values 1) (head values) then
          922|           head values
             |           ^
          923|         else

       … while evaluating the attribute 'value'

         at /nix/store/g8zzlf6drg73c987ii390yicq4c0j778-source/lib/modules.nix:807:9:

          806|     in warnDeprecation opt //
          807|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          808|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: getting status of '/nix/store/pdrbc49jdibvjw49p9bxln85fxz75kd3-source/pkgs/dmenu/default.nix': No such file or directory

The structure of my Nix configuration is as follows:

➜  nixos tree -L 1
.
β”œβ”€β”€ flake.lock
β”œβ”€β”€ flake.nix
β”œβ”€β”€ hosts
β”œβ”€β”€ modules
β”œβ”€β”€ overlays
└── pkgs

The pkgs directory has the following structure:

➜  nixos tree -L 1 pkgs
pkgs
β”œβ”€β”€ default.nix
β”œβ”€β”€ dmenu
β”œβ”€β”€ dwm
└── st

The pkgs/default.nix file contains:

pkgs: {
  dmenu = pkgs.callPackage ./dmenu { };
  dwm = pkgs.callPackage ./dwm { };
  st = pkgs.callPackage ./st { };
}

Deleting the .git folder resolves the issue.
if possible i dont wanna make a lot of changes to my config but i still wanna keep track of it through git
thx in advance :smiley:

I’m assuming dmenu, dwm, and st are folders with a default.nix inside each, as you didn’t make that explicitly clear, have all the files in the config been added to the git repo? The error states that nix can’t find ./pkgs/dmenu/default.nix, which is what is expected if you forgot to git add that file to the repo. When not using flakes, nix will use any file found with the appropriate name and location but when using flakes they need to be added to the git repo before they can be used.

yes each directory has its own default.nix
and yes i did add them to the git repo it didnt seem to fix the issue

Does this file exist? And what’s the output of git status?

yup the file exists (when not in a git repo the config builds just fine) and this is the output of the git status

On branch master
Changes not staged for commit:
        modified:   pkgs/dwm (modified content)
        modified:   pkgs/st (modified content, untracked content)

no changes added to commit

Forgot the actual command I wanted to ask about - what’s the output of

git ls-files pkgs/dwm/default.nix

And shot in the dark, but does --use-remote-sudo (instead of sudo) work?

1 Like

this command returns nothing,
--use-remote-sudo doesnt seem to help either

im not really familiar with the git ls-files command so i dont know if this is normal

If it returns nothing, that means that the file is not in the git index, and therefore nix will not find it either when using a flake in the repo.

Can you try git add --intent-to-add pkgs/dwm/default.nix then run the ls-files command again?

1 Like

okkay i think this is the issue
output of git add --intent-to-add pkgs/dwm/default.nix returns
\fatal: Pathspec 'pkgs/dwm/default.nix' is in submodule 'pkgs/dwm'

can i not use submodules?

Yes but you must pass ?submodule=1. (obviously…)

(Flakes are stable and well thought out you see.)

1 Like