Open HtwoO opened 4 days ago
BTW, I was able to follow https://nixcademy.com/2024/01/15/nix-on-macos/ and run
nix run nix-darwin -- switch --flake path.to.initial.flake
without obvious error, but could not find nix-darwin
or darwin-rebuild
after the command. I then run nix-store --gc
and run the command again and found out it was much slower, not sure why. Maybe because the first time it downloaded stuff from https://mirror.sjtu.edu.cn/nix-channels/store
configured in /etc/nix/nix.conf
and the second time I saw it downloaded from https://cache.nixos.org
.
The following is the content of my current /etc/nix/nix.conf
:
experimental-features = nix-command flakes
# trusted-substituters = https://mirror.iscas.ac.cn/nix-channels/store https://cache.nixos.org/
substituters = https://mirror.sjtu.edu.cn/nix-channels/store https://cache.nixos.org
build-users-group = nixbld
trusted-users = my.current.username
I can see it's now a symlink to a file in /nix/store/
macOS.CLI> ls -l /etc/nix/nix.conf
lrwxr-xr-x 1 root wheel 24B 6 29 17:46 /etc/nix/nix.conf -> /etc/static/nix/nix.conf
macOS.CLI> ls -l /etc/static/nix/nix.conf
lrwxr-xr-x 1 root wheel 52B 1 1 1970 /etc/static/nix/nix.conf -> /nix/store/kbxh2adn9rpc03ls888z5485v3fq7rkb-nix.conf
Previously, I would occasionally hand edit /etc/nix/nix.conf
, but now that it's a symbolic link to a file in /nix/store/
I should not hand edit the file any more. Am I right?
How do I reverse the effects/changes applied by nix run nix-darwin -- switch --flake ...
?
without obvious error, but could not find nix-darwin or darwin-rebuild after the command.
Did you restart your shell?
I believe
nix-info
reported wrong macOS version, it should bemacOS 11.7.8 (20G1351)
.
For some time after switching away from the 10.x numbering scheme, some system APIs would still return OS versions in that format for compatibility reasons, so that's not an issue.
Previously, I would occasionally hand edit
/etc/nix/nix.conf
, but now that it's a symbolic link to a file in/nix/store/
I should not hand edit the file any more. Am I right?
This is correct. Instead of editing it by hand, you would configure it with the nix
options in your nix-darwin system configuration. For example, I have this in my system configuration:
nix.settings = {
auto-optimise-store = true;
experimental-features =
[ "ca-derivations" "flakes" "nix-command" "repl-flake" ];
keep-derivations = true;
keep-outputs = true;
substituters = [ "https://cache.garnix.io" ];
trusted-public-keys =
[ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
};
which translates into this /etc/nix/nix.conf
:
# WARNING: this file is generated from the nix.* options in
# your nix-darwin configuration. Do not edit it!
allowed-users = *
auto-optimise-store = true
build-users-group = nixbld
cores = 0
experimental-features = ca-derivations flakes nix-command repl-flake
extra-sandbox-paths =
keep-derivations = true
keep-outputs = true
max-jobs = auto
require-sigs = true
sandbox = false
sandbox-fallback = false
substituters = https://cache.garnix.io https://cache.nixos.org/
trusted-public-keys = cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
trusted-substituters =
trusted-users = root
Did you restart your shell?
No. I realized I should have tried opening a new shell. I saw the following in the store:
macOS.CLI> ls -l /nix/store | rg 'nix-darwin'
dr-xr-xr-x 16 root nixbld 512B 1 1 1970 6ir80yhfd7lhiqp78i43kq8hr947wcyg-nix-darwin/
macOS.CLI> ls -l /nix/store | rg --count 'darwin'
190
macOS.CLI> ls -l /nix/store | rg 'darwin-rebuild'
-r--r--r-- 1 root nixbld 2.7K 1 1 1970 310pjmvk23w2m7cr0kkx5hia7w5cgaq1-darwin-rebuild.drv
-r--r--r-- 1 root nixbld 0.7K 1 1 1970 bv7zmylsbdlzipw606ynsc51s424gb0y-darwin-rebuild.zsh-completions
dr-xr-xr-x 4 root wheel 128B 1 1 1970 g3274z1798yh881a9n7f1sy3mkl8ifkh-darwin-rebuild/
-r--r--r-- 1 root nixbld 6.7K 1 1 1970 izq9m1f78vnrp908rkmrbh59765wdjpv-darwin-rebuild.sh
dr-xr-xr-x 4 root wheel 128B 1 1 1970 rrbn6iyqkxriaa34x8v2l94iq81mchhi-darwin-rebuild/
-r--r--r-- 1 root nixbld 2.8K 1 1 1970 w5q0pckls3i3qf9jcj9w83r8nndhngqh-darwin-rebuild.drv
This is correct. Instead of editing it by hand, you would configure it with the
nix
options in your nix-darwin system configuration. For example, I have this in my system configuration:
Thank you for the confirmation and the reference configuration.
Is there anything else we can help with here? I’d like the documentation to be approachable and address anything confusing in it. Unfortunately we’re probably not equipped to explain the flakes feature from scratch, but maybe we could introduce them a little, link to a general tutorial (although we’d need to decide which), and more clearly separate out the choice of flake vs. non‐flake configuration? It’d be useful to know what would have helped point you in the right direction as a beginner.
run the command again and found out it was much slower, not sure why
I figured this out by running the following:
nix --option substituters "https://mirror.iscas.ac.cn/nix-channels/store" \
--option trusted-substituters "https://mirror.iscas.ac.cn/nix-channels/store" \
--option trusted-users "$USER" run nix-darwin -- switch --flake ~/.config/nix
and it finished a lot quicker.
@emilazy
what is the relationship between
configuration.nix
andflake.nix
At least explain this a bit. I thought "are they referring to the same file there?".
With
mkdir -p ~/.config/nix-darwin
cd ~/.config/nix-darwin
in that section, I assumed ~/.config/nix-darwin
is empty from scratch. Then in Migrating from an existing configuration.nix section the document says
Add the following to
flake.nix
in the same folder asconfiguration.nix
Is this second flake.nix
referring to the same flake.nix
in Getting started from scratch section?
It's like referring to flake.nix
or nix run nix-darwin -- switch --flake .
without the cd ~/.config/nix-darwin
.
Maybe provide a basic/working /path/to/configutration.nix
example there.
I appreciate the feedback, thank you! I’ll try and take a look at how we can make the documentation more clear here soon if someone else doesn’t beat me to it.
I am rather new to Nix and evaluating nix as a replacement for Homebrew. I have nix installed on my macOS and wanted to try
nix-darwin
.I first followed https://davi.sh/til/nix/nix-macos-setup/ for setting up
nix-darwin
. It refers to./configuration.nix
in~/.config/nix/flake.nix
, but I have no idea what is supposed to be inconfiguration.nix
Then I found https://daiderd.com/nix-darwin/ and the steps described there to install
nix-darwin
is the same as theREADME.md
here. At https://github.com/LnL7/nix-darwin/blob/master/README.md?plain=1#L82 it is unclear what is the relationship betweenconfiguration.nix
andflake.nix
in Step 1.And in the file
./result/bin/darwin-installer
downloaded by https://github.com/LnL7/nix-darwin/blob/master/README.md?plain=1#L19 I could see it will installed something in$HOME/.nixpkgs
List of config files I have edited on my system:
/etc/nix/nix.conf
~/.config/nix/nix.conf
My current system environment:
I believe
nix-info
reported wrong macOS version, it should bemacOS 11.7.8 (20G1351)
.PS: I like the approach of using XDG_BASE_DIR standard for
nix
, as I have other Linux hosts that I may want to transition to NixOS in the future.-- Fonzie