Skip to content

Instantly share code, notes, and snippets.

@CorbanR
Last active March 15, 2020 10:37
Show Gist options
  • Save CorbanR/19e4702f52f3889b53169fca1c8acbfb to your computer and use it in GitHub Desktop.
Save CorbanR/19e4702f52f3889b53169fca1c8acbfb to your computer and use it in GitHub Desktop.
Nix

Create Volumes

you only need run if you plan on using https://github.com/LnL7/nix-darwin

  • Ensure sudo vim /etc/synthetic.conf contains
nix
run
  • Reboot

  • Create Nix and Run APFS Volumes (replace CHANGEME with your disk(example: disk1) and enter the password you want)

sudo diskutil apfs addVolume <CHANGEME|disk1> APFSX Nix -mountpoint /nix -passprompt
sudo diskutil apfs addVolume <CHANGEME|disk1> APFSX Run -mountpoint /run -passprompt

sudo diskutil enableOwnership /nix
sudo diskutil enableOwnership /run

# If you don't want the disk to show on your desktop
sudo chflags hidden /nix
sudo chflags hidden /run

LaunchD / Mount steps

Make sure you update the password to the password you entered earlier

  • Create sudo vim /Users/Shared/mount-nix.sh and ensure it contains
#!/bin/sh
# This can be cleaned up... but simple for now
echo<CHANGEME|password>| diskutil quiet apfs unlock Nix -stdinpassphrase -mountpoint /nix
echo<CHANGEME|password>| diskutil quiet apfs unlock Run -stdinpassphrase -mountpoint /run

NOTE: at least on my machine, /Users/Shared is on a filevaulted drive, so while the password is in plaintext it is owned by root and encrypted at rest

  • Ensure the script is executable, and permissions are correct
sudo chmod +x /Users/Shared/mount-nix.sh
sudo chown root:wheel /Users/Shared/mount-nix.sh

NOTE: I created the script in a global launchd location, I don't think this is stricly neccesary but has worked for me and mounts the volumes before GUI apps are brought up See https://www.launchd.info/ and https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html

  • create sudo vim /Library/LaunchDaemons/com.<CHANGEME|asdf>.mountnix.plist and ensure it contains the following(make sure you update <CHANGEME|asdf> in the file path and the plst content below)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.<CHANGEME|asdf>.mountnix</string>
    <key>Disabled</key>
    <false/>
    <key>UserName</key>
    <string>root</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/Shared/mount-nix.sh</string>
    </array>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>
  • update permissions and load into launchd. Replace <CHANGEME|asdf> with your name or whatever you want
sudo chown root:wheel /Library/LaunchDaemons/com.<CHANGME|asdf>.mountnix.plist
sudo launchctl load /Library/LaunchDaemons/com.<CHANGEME|asdf>.mountnix.plist
  • Reboot and Nix and Run should be mounted in /nix and /run

Install Nix

I chose to install nix in multiuser mode and so far it's worked great

sh <(curl https://nixos.org/nix/install) --daemon
@CorbanR
Copy link
Author

CorbanR commented Feb 25, 2020

Could probably change

<key>ProgramArguments</key>
    <array>
        <string>/Users/Shared/mount-nix.sh</string>
    </array>

To just

<key>Program</key>
 <string>/Users/Shared/mount-nix.sh</string>

/shrug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment