My nix-darwin and NixOS config
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

darwin/system: fix Time Machine activation script using exit instead of return

`exit` in an activation script aborts the entire nix-darwin activation,
so Time Machine was never configured even when the disk was present.
Wrap the logic in a function and use `return` for early exits instead.

+31 -25
+31 -25
modules/darwin/system.nix
··· 29 29 # 30 30 # The volume is auto-mounted if it exists but isn't mounted yet. 31 31 # Idempotent: skipped if the destination is already registered. 32 + # 33 + # NOTE: activation scripts must never call `exit` — that would abort the 34 + # entire nix-darwin activation. Early returns are handled via a wrapper 35 + # function so we can use `return` safely. 32 36 system.activationScripts.timeMachineDestination = lib.mkIf 33 37 (cfg.darwin.externalDisk.timeMachineVolumeUUID != null) 34 38 { ··· 37 41 uuid = cfg.darwin.externalDisk.timeMachineVolumeUUID; 38 42 in 39 43 '' 40 - echo "Checking local Time Machine volume (UUID=${uuid})..." 41 - _info=$(/usr/sbin/diskutil info "${uuid}" 2>/dev/null) 42 - if [ $? -ne 0 ]; then 43 - echo " Disk not found — skipping Time Machine setup." 44 - exit 0 45 - fi 44 + _setup_time_machine() { 45 + echo "Checking local Time Machine volume (UUID=${uuid})..." 46 + _info=$(/usr/sbin/diskutil info "${uuid}" 2>/dev/null) || { 47 + echo " Disk not found — skipping Time Machine setup." 48 + return 0 49 + } 46 50 47 - _mount=$(echo "$_info" | /usr/bin/awk '/Mount Point/ { for(i=3;i<=NF;i++) printf "%s ", $i; print "" }' | /usr/bin/sed 's/ *$//') 48 - if [ -z "$_mount" ] || [ "$_mount" = "Not applicable (no file system)" ]; then 49 - echo " Volume not mounted — mounting..." 50 - /usr/sbin/diskutil mount "${uuid}" 2>&1 51 - _mount=$(/usr/sbin/diskutil info "${uuid}" 2>/dev/null | /usr/bin/awk '/Mount Point/ { for(i=3;i<=NF;i++) printf "%s ", $i; print "" }' | /usr/bin/sed 's/ *$//') 52 - fi 51 + _mount=$(echo "$_info" | /usr/bin/awk '/Mount Point/ { for(i=3;i<=NF;i++) printf "%s ", $i; print "" }' | /usr/bin/sed 's/ *$//') 52 + if [ -z "$_mount" ] || [ "$_mount" = "Not applicable (no file system)" ]; then 53 + echo " Volume not mounted — mounting..." 54 + /usr/sbin/diskutil mount "${uuid}" 2>&1 || true 55 + _mount=$(/usr/sbin/diskutil info "${uuid}" 2>/dev/null | /usr/bin/awk '/Mount Point/ { for(i=3;i<=NF;i++) printf "%s ", $i; print "" }' | /usr/bin/sed 's/ *$//') 56 + fi 53 57 54 - if [ -z "$_mount" ] || [ "$_mount" = "Not applicable (no file system)" ]; then 55 - echo " Could not mount volume — skipping Time Machine setup." 56 - exit 0 57 - fi 58 + if [ -z "$_mount" ] || [ "$_mount" = "Not applicable (no file system)" ]; then 59 + echo " Could not mount volume — skipping Time Machine setup." 60 + return 0 61 + fi 58 62 59 - if /usr/bin/tmutil destinationinfo 2>/dev/null | /usr/bin/grep -qF "$_mount"; then 60 - echo " Already registered as Time Machine destination, skipping." 61 - else 62 - echo " Registering $_mount as Time Machine destination..." 63 - /usr/bin/tmutil setdestination -a "$_mount" 2>&1 || \ 64 - echo " WARNING: tmutil setdestination failed." 65 - fi 63 + if /usr/bin/tmutil destinationinfo 2>/dev/null | /usr/bin/grep -qF "$_mount"; then 64 + echo " Already registered as Time Machine destination, skipping." 65 + else 66 + echo " Registering $_mount as Time Machine destination..." 67 + /usr/bin/tmutil setdestination -a "$_mount" 2>&1 || \ 68 + echo " WARNING: tmutil setdestination failed." 69 + fi 66 70 67 - # Weekly backup interval (604800 seconds = 7 days) 68 - /usr/bin/tmutil setbackupinterval 604800 71 + # Weekly backup interval (604800 seconds = 7 days) 72 + /usr/bin/tmutil setbackupinterval 604800 73 + } 74 + _setup_time_machine 69 75 ''; 70 76 }; 71 77 }