nix-darwin icon indicating copy to clipboard operation
nix-darwin copied to clipboard

Use flake.nix by default if it exists

Open belak opened this issue 1 year ago • 7 comments

Both nixos-rebuild switch and home-manager switch seem to allow using a flake without passing any arguments if a flake.nix file exists in their respective directories - /etc/nixos and ~/.config/home-manager respectively. They both seem to follow symlinks, using the actual directory containing flake.nix rather than simply those default directories.

My proposal is that darwin-rebuild should use a similar behavior - if flake.nix exists in a specific default location (though I'm not sure what that location would be), it would use that without any additional arguments being passed.

belak avatar Jul 06 '23 05:07 belak

The default location for non flake configuration is ~/.config/darwin so that would be a good place.

LnL7 avatar Jul 09 '23 10:07 LnL7

I was thinking that because nix-darwin fulfills a similar role to NixOS (manages the system primarily), it should live in /etc, how about /etc/nix-darwin?

Enzime avatar Jul 09 '23 10:07 Enzime

Although /etc/nix-darwin is symmetric with NixOS, Nix Darwin users whom don't also use NixOS will be accustomed to~/.config/darwin (perhaps $XDG_CONFIG_HOME/darwin). I suggest that it defaults to $XDG_CONFIG_HOME/darwin, and is configurable to /etc/nix-darwin for those whom want symmetry with NixOS.

edit: it's XDG_CONFIG_HOME, not XDG_HOME

what-the-functor avatar Jul 11 '23 09:07 what-the-functor

Furthermore, anything in /etc could be removed on future updates of macOS.

what-the-functor avatar Jul 11 '23 09:07 what-the-functor

The current non-flakes default is actually ~/.nixpkgs/darwin-configuration.nix which is clearly unacceptable IMO (trampling on Nixpkgs' namespace, not XDG-compliant). The only mention of ~/.config/darwin is an example in the README, as far as I can tell. So we ought to change the default anyway, and I think we should avoid adding new things that depend on $HOME for https://github.com/LnL7/nix-darwin/issues/96 type reasons.

macOS has never trampled on non-system-software /etc files to my knowledge, and it'd be a huge breaking change were they ever to do so. Nix already uses /etc/nix, so /etc/nix-darwin is as safe as Nix itself.

(That said I personally keep my flake in $HOME on both platforms, I just pass --flake ~/... explicitly. A flakes-native way of specifying the default path might be nice, but is probably overkill in terms of this issue.)

emilazy avatar Jul 11 '23 09:07 emilazy

I've created a PR that uses ~/.config/darwin: https://github.com/LnL7/nix-darwin/pull/874

bouk avatar Feb 18 '24 18:02 bouk

Any updates on this?

michaelvanstraten avatar Apr 10 '24 16:04 michaelvanstraten