The Nix Way For Git?

Is The Nix Way for git only through Home Manager or Flakes ?
New nixer, here!

I have been searching the webs, but i could not find a way to make it work on configuration.nix either with environment packages or user packages!

Thanks in advance for the help!

I’m not 100% sure what you’re trying to do, but if it’s about keeping configuration.nix in git:

  • If you want to keep /etc/nixos in git, just run git as root.
  • If you want to keep configuration.nix and related files in a git repo owned by your user for easier git config (and perhaps better editor integration), you’ll need to change the path nixos-rebuild uses to find it.
    • Move your /etc/nixos to a directory owned by your user, e.g. /home/ivoencarnacao/.local/src/nixos
    • Set its permissions: sudo chown -R ivoencarnacao:users /home/ivoencarnacao/.local/src/nixos
    • Add somewhere in configuration.nix (importantly, now without sudo, otherwise you’ll break the permissions):
      nix.nixPath = [
    • Run this command to switch to the new configuration location:
      nixos-rebuild switch --use-remote-sudo -I nixos-config=/home/ivoencarnacao/.local/src/nixos
    • After that, nixos-rebuild switch --use-remote-sudo should just work as before, except it will build your configuration from the new location.
1 Like

On all my servers/laptops/sbc’s I’ve chowned /etc/nixos/ to my user. Any reason I - or anyone - should not?

If there is some automation to run nixos-rebuild, if it’s owned by your user, this mean your user can escalate privilege to root.