POST
Using Nix's "Single-user Mode" on macOS
Here is how to set up Nix in single-user mode on macOS.
I have been playing with the Nix package
manager lately (I will write more about it
some other time). On macOS, Nix mandatorily installs itself in
“multi-user mode” in macOS, which means that the build/install process
is actually run under central control by a set of special build
accounts. This allows concurrent users to build packages without
breaking things, but for a single-user system like mine, it doesn’t
add much value. Furthermore, it was inconvenient because my
command-line proxy settings (i.e. the http_proxy
and related
environment variables) did not get properly picked up by the daemon
when it changed dynamically, as it does often through the day as I
move between home, office and other networks.
So, with the help of several nice people on the ##nix-darwin
IRC
channel, I figured out how to revert my installation to single-user
Nix mode. Here it is:
Install and configure Nix as
documented, or like I
did, with brew cask install nix
(I know—the irony of using
Homebrew to install Nix!)
Next, we need to unload and stop the nix daemon:
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo launchctl stop org.nixos.nix-daemon
Change the ownership of the entire /nix
directory to your
personal user:
chown -R yourusername /nix
Change your configuration to unset the NIX_REMOTE
environment
variable. This is set automatically if you use bash
because the Nix
installation adds it to /etc/profile
, so you will have to unset it
manually in your own configuration, or modify the system files (I
leave that part up to you according to your setup). I use the Elvish
shell, so you can use my nix.elv
library,
which I load from my
rc.elv
file like this:
# Set up Nix environment
use nix
nix:multi-user-setup
# Work without the daemon
E:NIX_REMOTE = ""
Remove the following line from /etc/nix/nix.conf
:
build-users-group = nixbld
That’s it! You should now be able to run nix-env
and all other Nix
commands and they will operate directly, without going through the
daemon.
Once you are convinced that things are working fine, and to fully cleanup the multi-user install, you can remove the Nix build group and users with these commands:
sudo dscl . -delete /Users/nixbld1
sudo dscl . -delete /Users/nixbld2
sudo dscl . -delete /Users/nixbld3
sudo dscl . -delete /Users/nixbld4
sudo dscl . -delete /Users/nixbld5
sudo dscl . -delete /Users/nixbld6
sudo dscl . -delete /Users/nixbld7
sudo dscl . -delete /Users/nixbld8
sudo dscl . -delete /Users/nixbld9
sudo dscl . -delete /Groups/nixbld
I’ll write more about my experiences with Nix in the future. Stay tuned.
- Related:
- Elvish, an awesome Unix shell
- Fast translation with Google Translator
- Spotlight: use-package, a declarative configuration tool - Mastering Emacs
- Using Multiple SSH Keys with Github
- Fixing Emacs problems with the fish shell
- Moving files between git repositories, preserving history
- Three levels of GIT config
- Watching for changes (Polling notifications) in Evernote
- How to create a new KVM VM using command line tools
- Find all single-note tags in Evernote
- How to turn off "sort by relevance" in Evernote 5.6.0 Beta
- Mac keyboard shortcuts by Matt Gemmell
- Airmail tip: prevent "Save to Evernote" action from opening the created note
- How to stop com.apple.dock.extra from "using significant energy"
- Top 5 Recommended Google Font Combinations
- HowTo: Changing the available display formats for Evernote's "Insert Date" command
- Changing "message:" protocol handler from Sparrow back to Mail.app
- Fix journal in an HFS+ file system
- How to fix "texexpand error: More than one input file specified" in latex2html
- Installing latex2html under Win7 with cygwin
- LogParser, Event Logs, and Vista - Neil Carpenter's Blog - Site Home - TechNet Blogs
- Setting up a global hotkey to add tasks to Outlook
- GTD tip: clean up physical clutter using ziploc bags
- Making cygwin, Windows and emacs understand the same symlinks
- Hierarchical copying with cfengine3
- Emulate vi's % command (jump to matching parenthesis) in Emacs
- Installing AucTeX on EmacsW32 on Win7/64bit
- Must-Have Windows Software (or Windows Programs that I use) - good coders code, great reuse