Nix

インストール

λ bash <(curl https://nixos.org/nix/install)
...

Installation finished!  To ensure that the necessary environment
variables are set, please add the line

  . /Users/gupi/.nix-profile/etc/profile.d/nix.sh

to your shell profile (e.g. ~/.profile).
  • fish を使う方法は不明

  • マルチユーザは以下のように --daemon をつける

λ sh <(curl https://nixos.org/nix/install) --daemon
  • 30001 ~ 30032 の USERID が割り当てられる

  • 30000 の GROUP ID が割り当てられる

# nix-build, nix-shell などのパスが通る
# single-user
. /home/guchi/.nix-profile/etc/profile.d/nix.sh

# multi-user
λ source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh

ディレクトリ構造

/nix

~/.nix-defexpr/channels

~/.nix-profile/bin

パッケージのインストール先ディレクトリ

/etc/profile.d/nix.sh

マルチユーザのみ

コマンド

nix-env

# 利用可能なパッケージの一覧を表示
λ nix-env -qa

# パッケージのインストール
λ nix-env -i hello

# インストール済みパッケージのアップグレード
λ nix-env -u

# アップグレード内容を確認
λ nix-env -u --dry-run

nix-channel

# nixpkgs チャネルの追加
λ nix-channel --add https://nixos.org/channels/nixpkgs-unstable

# nixpkgs チャネルの削除
λ nix-channel --remove nixpkgs

# チャネルの更新
λ nix-channel --update

nix-collect-garbage

λ nix-collect-garbage -d

nix-build

λ nix-build '<nixpkgs>' -A firefox

nix の更新

# シングルユーザ
λ nix-channel --update; nix-env -iA nixpkgs.nix

# マルチユーザ
λ sudo -i sh -c 'nix-channel --update && nix-env -iA nixpkgs.nix && launchctl remove org.nixos.nix-daemon && launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist'

アンインストール

# シングルユーザ
λ rm -rf /nix

# マルチユーザ
λ sudo rm -rf /etc/profile/nix.sh /etc/nix /nix ~root/.nix-profile ~root/.nix-defexpr ~root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels

## If you are on Linux with systemd, you will need to run:
λ sudo systemctl stop nix-daemon.socket
λ sudo systemctl stop nix-daemon.service
λ sudo systemctl disable nix-daemon.socket
λ sudo systemctl disable nix-daemon.service
λ sudo systemctl daemon-reload

## If you are on macOS, you will need to run:
λ sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
λ sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist

トラブルシューティング

ユーザが変な感じ

$ /var/folders/p9/ln28v7zs7_53lz3ln4xyq2g00000gn/T/nix-binary-tarball/var/foldersXXXXXX.BKisLzLF/unpack/nix-2.2.2-x86_64-darwin/install: directory /nix exists, but is not writable by you. This could indicate that another user has already performed a single-user installation of Nix on this system. If you wish to enable multi-user support see http://nixos.org/nix/manual/#ssec-multi-user. If you wish to continue with a single-user install for gupi please run 'chown -R gupi /nix' as root.

λ sudo chown -R gupi /nix

warning: name collision in input Nix expressions

warning: name collision in input Nix expressions, skipping '/Users/gupi/.nix-defexpr/channels_root/nixpkgs'

λ nix-channel --remove nixpkgs

# もしくは
λ sudo nix-channel --remove nixpkgs

warning: Nix search path entry

warning: Nix search path entry '/Users/gupi/.nix-defexpr/channels/nixpkgs' does not exist, ignoring

λ sudo nix-channel --update

参考リソース

Last updated