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.
Instal·lació
The Nix package manager can be installed for the current user like so:
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --no-daemon
Log out and back in again, then test:
nix-shell -p mc emacs-nox # ara esteu dins un intèrpret d'ordres amb mc i 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.
Vegeu https://nixos.org/download/#nix-install-linux per a més detalls.
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.
Verify the mc command is now available for your user:
$ which mc /home/username/.nix-profile/bin/mc
Remove packages with nix-env --uninstall or 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.
See https://nix.dev/manual/nix/latest/command-ref/nix-env.html for further details.
Utilitzant un perfil de nix
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 ergnomic. 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.
Heus aquí un exemple trivial que utilitza nix profile per a instal·lar l'eina de cerca de codi 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) Eina de cerca de codi similar a ack, però més ràpida $ nix profile add nixpkgs#silver-searcher $ which ag /home/username/.nix-profile/bin/ag
Per a llistar els paquets instal·lats o eliminar-los:
$ 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.
See https://nix.dev/manual/nix/latest/command-ref/new-cli/nix3-profile.html for further details.
Reinstal·lació del 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: el perfil '/home/username/.local/state/nix/profiles/profile' és incompatible amb 'nix-env'; feu servir 'nix profile' al seu lloc
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
Ara podeu repetir els passos d'instal·lació.
Recollida de brossa per a recuperar espai de disc
Note that nix-env -e and nix profile remove both remove commands provided by a package from your user's current evironment, but the software actually remains installed in /nix/store until it is garbage collected.
You can force that garbage collection, to reclaim disk space, with one of the following commands:
nix-store --gc # recollida rutinària de brossa nix-collect-garbage -d # elimina paquets «no accessibles» de la botiga
Suprimir el Nix
Per a eliminar el gestor de paquets Nix, executeu les ordres següents:
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
Vegeu també
Article escrit per Ernstki d'acord amb la llicència CC-BY-4.0.