- macOS: home-manager only (I don't use nix-darwin).
- Linux (NixOS): NixOS with embedded home-manager.
- Linux (non-NixOS): home-manager only (e.g., Ubuntu).
- Update sops keys:
make update-sops - Edit encrypted files:
make edit-backup - Pin global flake registry to this repo:
make pin-registry
Clone this repository and place it in the home directory (required by neovim and chezmoi).
First, add the following to /etc/nix/nix.conf:
build-users-group = nixbld
experimental-features = nix-command flakes
trusted-users = root pengleiThen initialize home-manager:
$ nix --extra-experimental-features nix-command --extra-experimental-features flakes run nixpkgs#home-manager switch -- --flake .#penglei.aarch64-darwinIn a flake directory, direnv can initialize the shell via use flake automatically.
However, subsequently adding packages with nix shell ... does not take effect in this shell.
The root cause is incorrect PATH priority: subshells that reinitialize by re-reading configurations (e.g., zshrc) are not reentrant.
The following configuration solves this problem:
XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
export NIX_PROFILES="/nix/var/nix/profiles/default $HOME/.nix-profile"
setopt local_options shwordsplit
export NIX_SSL_CERT_FILE=/etc/ssl/cert.pem
for i in $NIX_PROFILES; do
if [ ! -e "$NIX_SSL_CERT_FILE" ]; then
if [ -e "$i/etc/ssl/certs/ca-bundle.crt" ]; then
export NIX_SSL_CERT_FILE=$i/etc/ssl/certs/ca-bundle.crt
fi
fi
if [ -e "$i/bin" ]; then
if ! [[ :$PATH: == *:"$i/bin":* ]]; then
export PATH="$i/bin:$PATH"
fi
fi
if [ -e "$i/share" ]; then
if ! [[ :$XDG_DATA_DIRS == *:"$i/share"* ]]; then
export XDG_DATA_DIRS="$XDG_DATA_DIRS:$i/share"
fi
fi
done
unset iThe nix installer initializes the shell env with:
# Nix
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# End NixIf SSL is broken (e.g., after nix profile remove cacert), set the env explicitly:
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
if [ ! -e "$NIX_SSL_CERT_FILE" ]; then
export NIX_SSL_CERT_FILE=/etc/ssl/cert.pem
fiAdd the following to /etc/sudoers.d/user:
penglei ALL=(root) NOPASSWD: /usr/bin/su -
pam_smartcard module is enabled by default; no additional configuration needed.
-
Disable most default keyboard shortcuts:
Launchpad & Dock, Mission Control, Keyboard, Services, Spotlight
In Mission Control, modify keyboard shortcuts:
Option + Up: Mission ControlOption + Down: Application Windows
-
Modifier Keys: Caps Lock -> Control
-
Disable "Automatically rearrange Spaces based on most recent use" in
Desktop & Dock > Mission Control
-
Restore passphrase and GPG keys:
make restoreAfter placing the private key in
~/.gnupg/private-keys-v1.d, restart the agent:$ gpgconf --kill gpg-agent $ gpgconf --launch gpg-agent
-
Copy zsh command history
To quit app followed by mouse cursor, enable all additional control configurations:
$ sudo nixos-rebuild switch --flake .-
Rollback NixOS
# /nix/var/nix/profiles/system-*-link/bin/switch-to-configuration switch -
Clean home-manager news
$ home-manager news --flake . -
Use vim on a freshly installed NixOS
NixOS does not include vim by default (only nano). Use the following to get vim temporarily:
$ nix --extra-experimental-features nix-command --extra-experimental-features flakes shell nixpkgs#vim
-
Clean journald logs older than one hour
# journalctl --rotate # journalctl --vacuum-time=1h
-
Installing yabai
-
Switching between spaces requires disabling SIP:
$ csrutil enable --without fs --without debug --without nvram -
Configure sudo — append to
/etc/sudoers.d/user:penglei ALL=(root) NOPASSWD: /Users/penglei/.nix-profile/bin/yabai --load-sa penglei ALL=(root) NOPASSWD: /Users/penglei/.nix-profile/bin/yabai --uninstall-saAfter completing the sudo configuration, manually run
sudo yabai --load-saonce without waiting for the next reboot.
-
-
Restart yabai daemon
$ launchctl load -F ~/Library/LaunchAgents/org.nix-community.home.yabai.plist $ launchctl unload -F ~/Library/LaunchAgents/org.nix-community.home.yabai.plist $ launchctl kickstart -k gui/$(id -u)/org.nix-community.home.yabai
Log locations:
$TMPDIR/rime.squirrel/Squirrel.INFO$TMPDIR/rime.squirrel/Squirrel.WARNING
Force deployment after updating configuration:
-
Run
home-manager switchto re-link rime configuration -
Clean cache:
$ rm -rf ~/Library/Rime/build -
Click "Deploy" in the Squirrel menu
installation.yaml should be writable after upgrading Squirrel.
Run as root:
# nix profile install nixpkgs#nix_git-
Shell Expansion
-
macOS
-
Rime Input Method
-
Font
- Inject username when using home-manager standalone.