Nix Package Manager: Installation and System Changes Analysis
January 02, 2025
沒什麼組織、一些倏忽即逝有趣或不有趣的想法
Nix 初探
Installation - https://nix.dev/install-nix
sh <(curl -L https://nixos.org/nix/install)What it does:
Install Nix package manager
Create a new profile for the current user
Add the Nix profile to the user’s shell profile
Based on the installation log, here are the critical changes Nix made to your machine:
File System Changes: (this is because macOS now (starting in 10.15 Catalina) has a read-only root directory. To support Nix, it will create a volume and configure macOS to mount it at /nix) Created a dedicated encrypted volume called “Nix Store” mounted at
/nixModified/etc/synthetic.confto create the mount point Modified/etc/fstabto specify volume mount optionsUser and Group Creation: Created a system group called
nixbldwith GID 350 Created 32 system users (_nixbld1 through _nixbld32) with UIDs 351-382 All build users are: Set to have /var/empty as home directory Disabled from logging in Added to the nixbld group Hidden from the systemDirectory Structure: Created several directories under /nix, including:
install: mkdir /nix/varinstall: mkdir /nix/var/loginstall: mkdir /nix/var/log/nixinstall: mkdir /nix/var/log/nix/drvsinstall: mkdir /nix/var/nixinstall: mkdir /nix/var/nix/dbinstall: mkdir /nix/var/nix/gcrootsinstall: mkdir /nix/var/nix/profilesinstall: mkdir /nix/var/nix/temprootsinstall: mkdir /nix/var/nix/userpoolinstall: mkdir /nix/var/nix/daemon-socketinstall: mkdir /nix/var/nix/gcroots/per-userinstall: mkdir /nix/var/nix/profiles/per-userinstall: mkdir /nix/storeinstall: mkdir /etc/nixShell Configuration: Backed up and modified shell configuration files:
/etc/bashrc/etc/zshrcAdded Fish shell configurations Added Nix environment setup scripts to these files (e.g. execute. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh')System Services: Created a LaunchDaemon at /Library/LaunchDaemons/org.nixos.nix-daemon.plist Set up a service to automatically mount the Nix volume
Package Management: Installed Nix package manager under
/nix/store/Set up the default profile with basic packages including SSL certificates (nss-cacert)These changes make Nix work as a separate package manager on macOS, isolated from the rest of your system in its own volume.
Usage
nix-shell -p <package>: Start a shell with the specified package availablenix-shell -p <package> --command <command>: Run a command in a shell with the specified package availablenix-shell -p <package> --run <command>: Run a command in a shell with the specified package available and exitnix-store --gc: Garbage collect the Nix store to remove unused packages