From 9afef9950f28780ff24908496c36f27826a601cf Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Tue, 29 Oct 2024 00:09:37 +1100 Subject: checks: move manual `/run` instructions to activation --- modules/system/base.nix | 54 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 15 deletions(-) (limited to 'modules/system/base.nix') diff --git a/modules/system/base.nix b/modules/system/base.nix index 44a8d91..43c9d7f 100644 --- a/modules/system/base.nix +++ b/modules/system/base.nix @@ -2,22 +2,46 @@ { system.activationScripts.createRun.text = '' - if ! test -L /run; then - if ! grep -q '^run\b' /etc/synthetic.conf 2>/dev/null; then + if [[ ! -L /run ]]; then + # This file doesn't exist by default on macOS and is only supported after 10.15 + # however every system with Nix installed should have this file otherwise `/nix` + # wouldn't exist. + if [[ -e /etc/synthetic.conf ]]; then + if ! grep -q '^run\b' /etc/synthetic.conf 2>/dev/null; then echo "setting up /run via /etc/synthetic.conf..." - echo -e "run\tprivate/var/run" | sudo tee -a /etc/synthetic.conf >/dev/null - sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B &>/dev/null || true - sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t &>/dev/null || true - if ! test -L /run; then - echo "warning: apfs.util failed to symlink /run" - fi - fi - if ! test -L /run; then - echo "setting up /run..." - sudo ln -sfn private/var/run /run - fi - if ! test -L /run; then - echo "warning: failed to symlink /run" + printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf >/dev/null + fi + + # for Catalina (10.15) + sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B &>/dev/null || true + # for Big Sur (11.0) + sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t &>/dev/null || true + + if [[ ! -L /run ]]; then + printf >&2 'error: apfs.util failed to symlink /run, aborting activation\n' + printf >&2 'To create a symlink from /run to /var/run, please run:\n' + printf >&2 '\n' + printf >&2 "$ printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf" + printf >&2 '$ sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B # For Catalina\n' + printf >&2 '$ sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t # For Big Sur and later\n' >&2 + printf >&2 '\n' + printf >&2 'The current contents of /etc/synthetic.conf is:\n' + printf >&2 '\n' + sudo sed 's/^/ /' /etc/synthetic.conf >&2 + printf >&2 '\n' + exit 1 + fi + else + echo "setting up /run..." + sudo ln -sfn private/var/run /run + + if [[ ! -L /run ]]; then + printf >&2 'error: failed to symlink /run, aborting activation\n' + printf >&2 'To create a symlink from /run to /var/run, please run:\n' + printf >&2 '\n' + printf >&2 '$ sudo ln -sfn private/var/link /run\n' + exit 1 + fi fi fi ''; -- cgit v1.2.3 From 57c144515a59efde1dd59078e280a82b32626311 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Sun, 17 Nov 2024 03:12:30 +1100 Subject: system: always add /run to /etc/synthetic.conf on macOS 10.15 onwards Currently if nix-darwin is uninstalled then reinstalled without rebooting, then the `/run` symlink will still remain and nix-darwin won't readd `run` to `/etc/synthetic.conf` meaning the system will be broken on next reboot. --- modules/system/base.nix | 73 +++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 35 deletions(-) (limited to 'modules/system/base.nix') diff --git a/modules/system/base.nix b/modules/system/base.nix index 43c9d7f..f20e2b6 100644 --- a/modules/system/base.nix +++ b/modules/system/base.nix @@ -2,46 +2,49 @@ { system.activationScripts.createRun.text = '' - if [[ ! -L /run ]]; then - # This file doesn't exist by default on macOS and is only supported after 10.15 - # however every system with Nix installed should have this file otherwise `/nix` - # wouldn't exist. - if [[ -e /etc/synthetic.conf ]]; then - if ! grep -q '^run\b' /etc/synthetic.conf 2>/dev/null; then - echo "setting up /run via /etc/synthetic.conf..." - printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf >/dev/null - fi + IFS="." read -r -a macOSVersion <<< "$(sw_vers -productVersion)" - # for Catalina (10.15) - sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B &>/dev/null || true - # for Big Sur (11.0) - sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t &>/dev/null || true + if [[ ''${macOSVersion[0]} -gt 10 || ( ''${macOSVersion[0]} -eq 10 && ''${macOSVersion[1]} -ge 15 ) ]]; then + if ! grep -q '^run\b' /etc/synthetic.conf 2>/dev/null; then + echo "setting up /run via /etc/synthetic.conf..." + printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf >/dev/null + fi - if [[ ! -L /run ]]; then - printf >&2 'error: apfs.util failed to symlink /run, aborting activation\n' - printf >&2 'To create a symlink from /run to /var/run, please run:\n' - printf >&2 '\n' - printf >&2 "$ printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf" - printf >&2 '$ sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B # For Catalina\n' - printf >&2 '$ sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t # For Big Sur and later\n' >&2 - printf >&2 '\n' - printf >&2 'The current contents of /etc/synthetic.conf is:\n' - printf >&2 '\n' - sudo sed 's/^/ /' /etc/synthetic.conf >&2 - printf >&2 '\n' - exit 1 - fi + if [[ ''${macOSVersion[0]} -gt 10 ]]; then + sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t || true else - echo "setting up /run..." - sudo ln -sfn private/var/run /run + sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B || true + fi - if [[ ! -L /run ]]; then - printf >&2 'error: failed to symlink /run, aborting activation\n' - printf >&2 'To create a symlink from /run to /var/run, please run:\n' - printf >&2 '\n' - printf >&2 '$ sudo ln -sfn private/var/link /run\n' - exit 1 + if [[ ! -L /run ]]; then + printf >&2 'error: apfs.util failed to symlink /run, aborting activation\n' + printf >&2 'To create a symlink from /run to /var/run, please run:\n' + printf >&2 '\n' + printf >&2 "$ printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf" + + if [[ ''${macOSVersion[0]} -gt 10 ]]; then + printf >&2 '$ sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -t\n' + else + printf >&2 '$ sudo /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B\n' fi + + printf >&2 '\n' + printf >&2 'The current contents of /etc/synthetic.conf is:\n' + printf >&2 '\n' + sudo sed 's/^/ /' /etc/synthetic.conf >&2 + printf >&2 '\n' + exit 1 + fi + else + echo "setting up /run..." + sudo ln -sfn private/var/run /run + + if [[ ! -L /run ]]; then + printf >&2 'error: failed to symlink /run, aborting activation\n' + printf >&2 'To create a symlink from /run to /var/run, please run:\n' + printf >&2 '\n' + printf >&2 '$ sudo ln -sfn private/var/link /run\n' + exit 1 fi fi ''; -- cgit v1.2.3 From 25e0b6064eed7a4ffeca7bacbba9dcca6fa8cc86 Mon Sep 17 00:00:00 2001 From: Aiden Scandella Date: Mon, 25 Nov 2024 16:10:39 -0800 Subject: system: fix detection and ownership of /etc/synthetic.conf This file is owned by root and mode 600 on my system, so the grep is failing and it's adding a new entry every run. ```sh -rw------- 1 root wheel 664 Nov 25 15:52 /etc/synthetic.conf ``` --- modules/system/base.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'modules/system/base.nix') diff --git a/modules/system/base.nix b/modules/system/base.nix index f20e2b6..2374855 100644 --- a/modules/system/base.nix +++ b/modules/system/base.nix @@ -5,6 +5,16 @@ IFS="." read -r -a macOSVersion <<< "$(sw_vers -productVersion)" if [[ ''${macOSVersion[0]} -gt 10 || ( ''${macOSVersion[0]} -eq 10 && ''${macOSVersion[1]} -ge 15 ) ]]; then + if [[ $(stat -c '%a' /etc/synthetic.conf) != "644" ]]; then + echo "fixing permissions on /etc/synthetic.conf..." + sudo chmod 644 /etc/synthetic.conf + fi + + if [[ $(grep -c '^run\b' /etc/synthetic.conf) -gt 1 ]]; then + echo "found duplicate run entries in /etc/synthetic.conf, removing..." + sudo sed -i "" -e '/^run\tprivate\/var\/run$/d' /etc/synthetic.conf + fi + if ! grep -q '^run\b' /etc/synthetic.conf 2>/dev/null; then echo "setting up /run via /etc/synthetic.conf..." printf 'run\tprivate/var/run\n' | sudo tee -a /etc/synthetic.conf >/dev/null -- cgit v1.2.3