Confused about nix.nixPath

Hi, I’m bit confused as to how I should set custom path for my /etc/nixos/configuration.nix with nix.nixPath since it has to be defined in said config file, right?

Seems that the documentation is lacking on this, or why it even exists in the first place. I presume it’s a work around for deployment tools like nixops… at a guess, or special cases where you would need alternative paths if you need to test many different configurations etc etc. I can’t think of use cases right now because it’s the end of the week. If anyone cares to add real world use cases and examples, then the documentation can be updated and the below issue closed. We just have to find out who added it, and what there thinking was ;-)…

commit a8edf185a9e1677088c8c30acc9d281c8350bca7
Author: Eelco Dolstra <>
Date:   Mon May 26 14:55:47 2014 +0200

    Add constant ‘nixPath’
    It contains the Nix expression search path as a list of { prefix, path
    } sets, e.g.
      [ { path = "/nix/var/nix/profiles/per-user/root/channels/nixos"; prefix = ""; }
        { path = "/etc/nixos/configuration.nix"; prefix = "nixos-config"; }
        { path = "/home/eelco/Dev/nix/inst/share/nix/corepkgs"; prefix = "nix"; }

I want to version control my config, so first tough was to make a symlink from e.x. ~/.config/nixos/configuration.nix to /etc/nixos/..., but then I found this thread:

So I was hoping that setting nix.nixPath would be less hacky then setting up a alias or a shell script that exports the NIX_PATH before running nixos-rebuild

I’ve been messing around with building my system configuration with flakes, which allows the configuration files to reside anywhere and all hang together better avoiding ‘band aids’ (symlinks). The just have to be in a git repo somewhere, and boom! it will work!

Your probably not willing to dive in to flakes right now, but they sure feel a lot cleaner than botching things with symlinks.

That does sound nice, but I practically do not know anything about Nix right now xD

well your in the right place to learn! …

Doesn’t the example in the docs specify how to use it? I.e.:

[{ path = "/home/broccoli/NixOS/configuration.nix"; prefix = "nixos-config"; }]

I don’t know that much about the implicit module resolution, but that would make sense.

In practice, I’d also recommend looking towards flakes. It’s sad that the infrastructure around those isn’t fully mature yet, they do make use cases like this much more sanely achievable.

Hosted by Flying Circus.