I’m new to Nix. I’m using nix-darwin
on my Mac, and I have a basic flake. In there, I use darwinConfiguration.[my_host_name] = ...
where [my_host_name]
is replaced with a hard-coded copy of my computer’s hostname. Since I want to keep this config on a public GitHub repo, I would like to extract this hardcoding out of my flake and instead use a variable imported from another file (that I can gitignore) like this: darwinConfiguration.${hostname}
. I seemed to have gotten something to work when I did this:
# ./user.nix (is gitignored)
{
username = "nixos-username" # Example username
hostname = "nixos-hostname" # Example hostname
}
# ./flake.nix
...
outputs = input:
let inherit (import ./user.nix) username hostname;
in
{
darwinConfigurations.${hostname}...
...
users.users.${username} = {
name = username;
home = "/Users/${username}";
}
...
While I was able to switch to this config, something seemed to have broken internally because darwin-rebuild
and some nix
commands don’t work anymore (“no command found”) and the zsh shell which I’ve configured via nix does not start (like it did before when I hardcoded my username and hostname).
I suspect it has to do with the way I’ve imported user.nix
script and the way I used it to define my user.
How do I properly define this user.nix
file to extract my username and hostname from the main config files?