Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What do I change if I want to have my configuration in my home directory instead of /etc? #66

Open
ckp95 opened this issue Feb 20, 2024 · 2 comments
Labels
question Further information is requested

Comments

@ckp95
Copy link

ckp95 commented Feb 20, 2024

I have not moved to flakes yet. Right now I keep my configuration.nix and hardware.nix under my home directory at ~/me/src/dotfiles. In my configuration.nix, I have set my nixPath as:

  nix.nixPath = [
    "nixos-config=/home/cameron/me/src/dotfiles/configuration.nix"
    "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
    "/nix/var/nix/profiles/per-user/root/channels"
  ];

so when I run sudo nixos-rebuild switch it uses the config there rather than looking in /etc/nixos. (I don't know what the channels-related ones are actually doing, I just kept them there from the original config)

I want to keep this directory layout in a flake-based config. I notice in the template, this section:

  # This will additionally add your inputs to the system's legacy channels
  # Making legacy nix commands consistent as well, awesome!
  nix.nixPath = ["/etc/nix/path"];
  environment.etc =
    lib.mapAttrs'
    (name: value: {
      name = "nix/path/${name}";
      value.source = value.flake;
    })
    config.nix.registry;

What is this /etc/nix/path doing? I don't currently have such a directory. Will it be created automatically? And do I need to add my dotfiles directory to this list?

@Misterio77
Copy link
Owner

Misterio77 commented Apr 27, 2024

Hey @ckp95, apologies for the late response!

The NIX_PATH (here configured by nix.nixPath) is where nix will look when you have a angle bracket lookup.

For example, nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos will tell nix to use a channel named nixos owned by root when looking up <nixpkgs>. While /nix/var/nix/profiles/per-user/root/channels will tell nix to look for a channel with the same name for any other angle bracket it finds (e.g. <foo> will be looked up in /nix/var/nix/profiles/per-user/root/channels/foo).

When using flakes, you usually want to move away from channels, as they're effectively replaced with flake inputs.

The nix path angle bracket look up is still useful, though, as sometimes you want to evaluate non-flake nix files, which will still use the angle bracket syntax to lookup stuff (mostly nixpkgs).

In this template, we point NIX_PATH to /etc/nix/path, and create a /etc/nix/path/foobar for each flake input you have (e.g. /etc/nix/path/nixpkgs). Yep, this directory is created if it doesn't exist already.

This lets you use the exact inputs you have locked in your flake with the "legacy" angle brackets (global nix path) syntax.


The nixos-config nix path only matters to nixos-rebuild, when it's called without a --flake argument.

nixos-rebuild looks it up to find where your config is (falling back to /etc/nixos/configuration.nix).

When building your system with flakes, you will specify the path to your config with --flake, so the nixos-config nix path does not matter at all.

@Misterio77
Copy link
Owner

In practice, the only angled bracket lookup that's actually useful outside of your config is <nixpkgs>, so we plan on simplifying this on the template to make things clearer.

@Misterio77 Misterio77 added the question Further information is requested label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants