Skip to content

Commit ca42caf

Browse files
committed
cure symlinked store in /etc/synthetic.conf
much thanks to the eagle-eyed @lilyball for spotting this
1 parent 4abec14 commit ca42caf

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

scripts/create-darwin-volume.sh

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,20 @@ test_fstab() {
206206
/usr/bin/grep -q "$NIX_ROOT apfs rw" /etc/fstab 2>/dev/null
207207
}
208208

209-
test_nix_symlink() {
210-
[ -L "$NIX_ROOT" ] || /usr/bin/grep -q "^nix." /etc/synthetic.conf 2>/dev/null
209+
test_nix_root_is_symlink() {
210+
[ -L "$NIX_ROOT" ]
211211
}
212+
213+
test_synthetic_conf_either(){
214+
/usr/bin/grep -qE "^${NIX_ROOT:1}($|\t.{3,}$)" /etc/synthetic.conf 2>/dev/null
215+
}
216+
212217
test_synthetic_conf_mountable() {
213218
/usr/bin/grep -q "^${NIX_ROOT:1}$" /etc/synthetic.conf 2>/dev/null
214219
}
220+
215221
test_synthetic_conf_symlinked() {
216-
/usr/bin/grep -qE "^${NIX_ROOT:1}\s+\S{3,}" /etc/synthetic.conf 2>/dev/null
222+
/usr/bin/grep -qE "^${NIX_ROOT:1}\t.{3,}$" /etc/synthetic.conf 2>/dev/null
217223
}
218224

219225
test_nix_volume_mountd_installed() {
@@ -370,7 +376,26 @@ During install, I add '${NIX_ROOT:1}' to /etc/synthetic.conf, which instructs
370376
macOS to create an empty root directory for mounting the Nix volume.
371377
EOF
372378
# make the edit to a copy
373-
/usr/bin/sed -e "/^${NIX_ROOT:1}$/d" "/etc/synthetic.conf" > "$SCRATCH/synthetic.conf.edit"
379+
/usr/bin/grep -vE "^${NIX_ROOT:1}($|\t.{3,}$)" /etc/synthetic.conf > "$SCRATCH/synthetic.conf.edit"
380+
381+
if test_synthetic_conf_symlinked; then
382+
warning <<EOF
383+
384+
/etc/synthetic.conf already contains a line instructing your system
385+
to make '${NIX_ROOT}' as a symlink:
386+
$(/usr/bin/grep -nE "^${NIX_ROOT:1}\t.{3,}$" /etc/synthetic.conf)
387+
388+
This may mean your system has/had a non-standard Nix install.
389+
390+
The volume-creation process in this installer is *not* compatible
391+
with a symlinked store, so I'll have to remove this instruction to
392+
continue.
393+
394+
If you want/need to keep this instruction, answer 'n' to abort.
395+
396+
EOF
397+
fi
398+
374399
# ask to rm if this left the file empty aside from comments, else edit
375400
if /usr/bin/diff -q <(:) <(/usr/bin/grep -v "^#" "$SCRATCH/synthetic.conf.edit") &>/dev/null; then
376401
if confirm_rm "/etc/synthetic.conf"; then
@@ -546,7 +571,8 @@ EOF
546571
}
547572

548573
remove_volume_artifacts() {
549-
if test_synthetic_conf_mountable; then
574+
if test_synthetic_conf_either; then
575+
# NIX_ROOT is in synthetic.conf
550576
if synthetic_conf_uninstall_prompt; then
551577
# TODO: moot until we tackle uninstall, but when we're
552578
# actually uninstalling, we should issue:
@@ -761,7 +787,7 @@ else
761787
echo ""
762788
} >&2
763789

764-
if test_nix_symlink; then
790+
if test_nix_root_is_symlink; then
765791
failure >&2 <<EOF
766792
error: $NIX_ROOT is a symlink (-> $(readlink "$NIX_ROOT")).
767793
Please remove it. If nix is in /etc/synthetic.conf, remove it and reboot.

0 commit comments

Comments
 (0)