דילוג לתוכן

Nix

The Nix package manager is an advanced tool for advanced users that can be used to acquire virtually any free software package you can imagine from its large, community-maintained repository.

It can be installed on KDE Linux for a single-user system. Nix stores software and dependencies under /nix/store, and keeps your search path updated automatically as tools are added or removed.

התקנה

אפשר להתקין את מנהל החבילות Nix למשתמש הנוכחי באופן הבא:

sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon

יש לצאת מהמשתמש במערכת ולהיכנס אליו שוב ואז לבדוק:

nix-shell -p mc emacs-nox  # עכשיו נכנסת למעטפת עם mc ו־emacs

Note that when you quit this shell, mc and emacs are no longer in your shell’s search path. See the next section to make such tools available persistently.

ר׳ https://nixos.org/download/#nix-install-linux לפרטים נוספים

Persistent package installations

Use nix-env -iA or nix-env --install --attr to install packages to /nix/store and make them available in your user’s search path:

$ nix-env -f '' -iA mc
⋮
building '/nix/store/1q2sh2f178jx9fl37gd9ks85ysfvpwd9-user-environment.drv'...

This creates a new “environment” which contains all the state changes necessary to make the mc package available, and these can be rolled forward or backward. This is the ''real'' appeal of the Nix package management system, but beyond the scope of this guide.

חשוב לוודא שהפקודה mc זמינה עכשיו למשתמש שלך:

$ which mc
/home/username/.nix-profile/bin/mc

הסרת חבילות עם nix-env --uninstall או עם nix-env -e:

$ nix-env -e mc
uninstalling 'mc-4.8.33'
building '/nix/store/rqbghiyds6f7a49qiwi9gmq7bnkgn9qi-user-environment.drv'...

See the section about [[#garbage-collection|garbage collection]] below for how to reclaim space used by packages that you're no longer using.

כדאי לגשת אל https://nix.dev/manual/nix/latest/command-ref/nix-env.html לפרטים נוספים.

דרך nix profile

The nix <command> interface is still technically considered experimental (more context on the “experimental” status of nix profile can be found in this RFC), but in practice it’s widely-used, and more ergonomic. Tab-completion and the --help options for the various nix subcommands will also work out of the box on a fresh installation. Like nix-env, nix profile will install packages to /nix/store and make them available in your search path, persisting between login sessions.

הינה דוגמה פשוטה דרך nix profile להתקין את כלי חיפוש הקוד ag:

$ mkdir -p ~/.config/nix
$ cat >> ~/.config/nix/nix.conf <<EOF
experimental-features = nix-command flakes
EOF

$ nix search nixpkgs silver searcher
⋮
* legacyPackages.x86_64-linux.silver-searcher (2.2.0)
  Code-searching tool similar to ack, but faster

$ nix profile add nixpkgs#silver-searcher
$ which ag
/home/username/.nix-profile/bin/ag

כדי להציג חבילות מותקנות או להסיר אותן:

$ nix profile list
⋮
Name:               silver-searcher
Flake attribute:    legacyPackages.x86_64-linux.silver-searcher
Original flake URL: flake:nixpkgs
Locked flake URL:   github:NixOS/nixpkgs/f08e6b11a5ed43637a8ac444dd44118bc7d273b9?narHash=sha256-7vUo0qWCl/rip%2Bfzr6lcMlz9I0tN/8m7d5Bla/rS2kk%3D
Store paths:        /nix/store/l120si3zsshmf3jr7dkn5dvcj0n586xb-silver-searcher-2.2.0

$ nix profile remove silver-searcher

See the section about garbage collection below for how to reclaim space used by packages that you're no longer using.

כדאי לגשת אל https://nix.dev/manual/nix/latest/command-ref/new-cli/nix3-profile.html לפרטים נוספים.

התקנת Nix מחדש

If you've enabled the “experimental” nix profile feature, you'll need to disable that and delete the state files associated with your user's profile before reinstalling, otherwise you'll get an error message like this:

error: profile '/home/username/.local/state/nix/profiles/profile' is incompatible with 'nix-env'; please use 'nix profile' instead
Warning: this will forget any previously-installed packages!

Comment out the experimental-features line in your Nix configuration file, and then delete the profile state directory:

$ sed -i'' 's/^experimental-features = nix-command flakes$/#&/' ~/.config/nix/nix.conf
$ rm -rf ~/.local/state/nix/profiles/profile

Now you can repeat the installation steps.

Garbage-collecting to reclaim disk space

Note that nix-env -e and nix profile remove both remove commands provided by a package from your user's current environment, but the software actually remains installed in /nix/store until it is garbage collected.

אפשר לאלץ איסוף זבל בכוח, כדי להשיב נפח כונן אבוד, באמצעות אחת מהפקודות הבאות:

nix-store --gc           # איסוף זבל שגרתי
nix-collect-garbage -d   # הסרת חבילות „בלתי נגישות” מהחנות

הסרת Nix

כדי להסיר את מנהל החבילות Nix, יש להריץ את הפקודות הבאות:

sudo systemctl disable --now nix-daemon.service nix-daemon.socket

sudo rm -rf /nix /etc/nix /etc/profile.d/nix.sh /etc/tmpfiles.d/nix-daemon.conf /nix /root/.nix-channels /root/.nix-defexpr /root/.nix-profile /root/.cache/nix ~/.nix-channels ~/.nix-defexpr ~/.nix-profile ~/.cache/nix

for i in $(seq 1 32); do sudo userdel nixbld$i; done

sudo groupdel nixbld

See also


הכתבה נתרמה על ידי Ernstki בכפוף לרישיון CC-BY-4.0.