Where do people keep their `configuration.nix`

Hi all,

As the title says, I am wondering how people manage their configuration.nix file. I currently have it in my home directory in a git repo, and then symlink /etc/nixos/configuration.nix to this file. This is nice in that it allows me to have all my dotfiles in my home directory and allows me to edit them without sudo, however it seems a bit hacky and I am increasingly realising that it might not be a good idea.

For example, this doesn’t seem to play nicely with some things like cachix that want to change your configuration.nix. It is also a bit of a pain to set up a new computer as I have to get the user working first and then build everything. Further I tried using flakes and couldn’t get it to work with this set up.

Would be interesting to hear what other people do for this. In short I’m looking for some solution that allows me to easily edit and store my dotfiles without fighting the system.


My configuration.nix is empty except for including hardware-configuration.nix and my real config.nix which I manage with git and keep in /etc/nixos/nix-configs/

I rarely edit them in place so rights don’t matter much. I edit them on my main workstation and use git to get them to any target machine.

1 Like

I define all my systems via nixops in a common git repo and add a few rc-files I symlink to that I don’t want to inline in Nix, namely ~/.emacs.d/init.el -> ./init.el and ~/.stumpwm.d/init.lisp -> stumpwm.lisp. I never got nixops(1) to replicate some features of nixos-rebuild(8) so I include my laptop.nix from the repo on my local system via

# /etc/nixos/configuration.nix
{ lib, pkgs, config, ... } @args:

  deployment-path = /home/tmplt/nixops/laptop.nix;
  system-name = "perscitia";
in lib.filterAttrs (n: v: n != "deployment") ((import deployment-path).${system-name} { inherit args pkgs config lib; } )

Somewhat messy, and the repo could use some trimming. Eventually I want to be able to fully declare everything in my system in a set of files so I can easily bootstrap from an install medium, but I’m not there yet.

1 Like

I cloned my config repo into Projects directory in my home directory and have been running nixos-rebuild switch -I nixpkgs=$HOME/Projects/nixpkgs -I nixos-config=$HOME/Projects/nixfiles/hosts/$(hostname)/configuration.nix

I do not even have /etc/nixos on my computer, and the nixfiles directory is completely anonymous – I can move it anywhere and, since I actually use relative paths in the rebuild command, I will not even have to change anything.

Some other tools like nixos-option might require nixos-config on $NIX_PATH as well, but I do not use them. I could always just alias nixos-option to env NIX_PATH=nixos-config=$PWD/... nixos-option and run it in my anonymous repo if I wanted to.

  1. Actually, these days I use a simple script but it still does basically the same thing.
1 Like

My /etc/NixOS/configuration.nix is just the generated one plus the minimal necessary modifications that are necessary to get flakes in the system.

From then on, I just use the flake by cd in the folder and then doing nixos-rebuild switch --flake .

1 Like

I probably have the weirdest way of doing it, I just have a Bash script aliased to nixup that copies from the local folder to /etc/nixos then runs sudo nixos-rebuild switch --upgrade-all. I don’t imagine it would be a recommended way but haven’t had problems… yet.

1 Like

I deploy all my nixos machines with nixops which lives in a git repo.

1 Like

Thanks for the answers everyone, I think I’m going to try to move my config into a standalone (movable) directory and call it using nixos-rebuild switch --flake /path/to/this/directory


This is what I do – I was going to mention it but held off since you’d mentioned trying flakes but having trouble getting something working. I’m around in #nixos (or #nix-community:numtide.com on Matrix) a lot and will continue to offer up my assistance with adopting flakes, to the extent that I can.


I’ve made /etc/nixos a git repo with receive.denyCurrentBranch = updateInstead.
I thenmodify it in a clone in my home and,once I’ve done,I do sudo git push

1 Like

I’m experimenting with the following:

# configuration.nix...
  environment.etc."nixos/configuration.nix" = {
    source = "/persist/etc/nixos/configuration.nix";
  environment.etc."nixos/hardware-configuration.nix" = {
    source = "/persist/etc/nixos/hardware-configuration.nix";

which produces symbolic link sets:

  • /etc/nixos/configuration.nix/etc/static/nixos/configuration.nix/persist/etc/nixos/configuration.nix
  • /etc/nixos/hardware-configuration.nix/etc/static/nixos/hardware-configuration.nix/persist/etc/nixos/hardware-configuration.nix

Initially I didn’t expect the middle symbolic link.

First time round the files need to be copied into /persist/etc/nixos before the nixos-rebuild switch.

I’ve yet to put /persist/etc/nixos/ under version control yet…

1 Like