Getting Nixos Config Path from within .nix file

In my dotfiles I want to locate where the directory is on my machine in my nix files.

For example I would like:

    imports = [
        ./configs/alacritty.nix
        ./configs/code.nix
    ];

To look like this:

    imports = [
        /my/absolute/path/configs/alacritty.nix
        /my/absolute/path/configs/code.nix
    ];

and I need this to work regardless of where the nixos directory is located. I hope I’ve explained this well as I can’t find anything when searching online. Thanks in advance.

That’s not possible (purely) and smells of x-y. For what purpose would you want to do that?
The behaviour of a config should not ever depend on the top-level directory it’s located in.

My nixos config gets moved around a bit. I was wondering if there was just anyway too locate it during “runtime” or when the configuration was being built. I wanted the same effect as relative paths just without the mess.

… why? That’s what the relative path syntax is for.

Your config should be kept together, to ensure that the relative paths continue to work.

1 Like