使用 Nix 管理 dotfiles
nix
& homebrew
scutil --get LocalHostName
nix --experimental-features 'nix-command flakes' run nix-darwin -- switch --flake .#mini
mv /etc/zshrc /etc/bashrc.before-nix-darwin
)NIX_DEBUG=1 darwin-rebuild switch --flake .#mini --show-trace --print-build-logs --verbose
access-tokens
(~/.config/nix/nix.conf
),之后在非 sudo 环境遇到 (Bad credentials
),之后删除 access-tokens
才行。原因是配置的 token 设置了有效期。darwin-system.drv
被删除,darwin-rebuild
失败,必须再次安装 nix-darwin
。
sudo nix-collect-garbage -d
导致
nix –experimental-features ‘nix-command flakes’ repl
nix-repl> :lf .
nix-repl> builtins.toJSON outputs.darwinConfigurations.
nix repl -f ‘
2. 通过 build 结果分析
darwin-rebuild build –flake .#mini –show-trace –print-build-logs –verbose
## Nix
Nix 配置文件:
- `/etc/nix/nix.conf` 文件
- `NIX_CONFIG` 环境变量
- command line flags 方式 `--option <name> <value>`
```shell
# 查看配置
nix config show
# 指定 Nix 配置
NIX_CONFIG="substituters = https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" darwin-rebuild build --flake .#mini -v
darwin-rebuild build --flake .#mini --option substituters "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
# 查看本地 drv 内容
nix derivation show /nix/store/j4avzn6fll1d1v588pss8nrmjfxlwlar-maven-3.6.3.drv
# 查看 pkgs 仓库 drv 内容
nix derivation show nixpkgs#maven
# 查看当前系统 drv 内容
nix derivation show -r /run/current-system
# 构建 drv
nix-store -r /nix/store/5y616j03c24dinqz74zr745i6nybmgkx-maven-3.9.9.drv
使用 stdenv
构建 derivation。
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/:$//'
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z
ifconfig en0 ether
# Change the MAC address 14:7d:da:a9:a8:8c(mbp)/84:8c:8d:b1:22:26(router)
sudo ifconfig en0 ether d8:18:fd:c0:41:96
networksetup -detectnewhardware
# Turn off the Wi-Fi device:
networksetup -setairportpower en0 off
# 查看所有
defaults domains
# 查看指定
defaults read com.apple.dock