tuto:nix
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
tuto:nix [2020/03/06 18:26] – [nix-store] root | tuto:nix [2022/06/21 20:15] (Version actuelle) – [nix-shell] root | ||
---|---|---|---|
Ligne 15: | Ligne 15: | ||
* [[https:// | * [[https:// | ||
+ | ===== nix-user-chroot ===== | ||
+ | https:// | ||
+ | |||
+ | Outil qui permet de donner un répertoire qui sera présenter comme point de montage ''/ | ||
+ | < | ||
+ | $ mkdir -m 0755 ~/.nix | ||
+ | $ nix-user-chroot ~/.nix ${SHELL=bash} -l | ||
+ | </ | ||
===== Installation ===== | ===== Installation ===== | ||
< | < | ||
Ligne 36: | Ligne 44: | ||
</ | </ | ||
+ | ==== NIX_PAGER ==== | ||
< | < | ||
export NIX_PAGER= | export NIX_PAGER= | ||
+ | </ | ||
+ | |||
+ | ==== nixpkgs ==== | ||
+ | < | ||
+ | nixpkgs=https:// | ||
+ | nixpkgs=channel: | ||
</ | </ | ||
Ligne 59: | Ligne 74: | ||
$ nix-env -u --dry-run | $ nix-env -u --dry-run | ||
$ nix-env -e hello | $ nix-env -e hello | ||
+ | </ | ||
+ | |||
+ | Force a specific channel (master in this example): | ||
+ | < | ||
+ | $ nix-env -f https:// | ||
</ | </ | ||
Ligne 120: | Ligne 140: | ||
==== nix-shell ==== | ==== nix-shell ==== | ||
* https:// | * https:// | ||
+ | |||
+ | <code haskell shell.nix> | ||
+ | { pkgs ? import < | ||
+ | |||
+ | with pkgs; | ||
+ | |||
+ | mkShell { | ||
+ | buildInputs = [ | ||
+ | elixir_1_10 | ||
+ | nodejs-12_x | ||
+ | ]; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | $ nix-shell | ||
+ | $ nix-shell shell.nix | ||
+ | </ | ||
+ | |||
< | < | ||
$ nix-shell --pure -E ' | $ nix-shell --pure -E ' | ||
Ligne 136: | Ligne 175: | ||
< | < | ||
$ nix-shell '< | $ nix-shell '< | ||
+ | </ | ||
+ | |||
+ | Force a specific channel: | ||
+ | < | ||
+ | $ nix-shell -p hello -I nixpkgs=https:// | ||
</ | </ | ||
Ligne 189: | Ligne 233: | ||
$ nix-channel --add https:// | $ nix-channel --add https:// | ||
$ nix-channel --remove nixpkgs_19_09 | $ nix-channel --remove nixpkgs_19_09 | ||
+ | </ | ||
+ | |||
+ | Master channel: | ||
+ | < | ||
+ | $ nix-channel --add https:// | ||
</ | </ | ||
Ligne 306: | Ligne 355: | ||
path is '/ | path is '/ | ||
02cgs6b1rmh8hmcwm5wpxxg32p3km9c05606pykv49qq1spd6p38 | 02cgs6b1rmh8hmcwm5wpxxg32p3km9c05606pykv49qq1spd6p38 | ||
+ | </ | ||
+ | |||
+ | ==== nix-instantiate ==== | ||
+ | < | ||
+ | $ nix-instantiate --eval -E ' | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | $ nix-instantiate --eval -E ' | ||
+ | " | ||
</ | </ | ||
Ligne 408: | Ligne 468: | ||
Welcome to Nix version 2.3.3. Type :? for help. | Welcome to Nix version 2.3.3. Type :? for help. | ||
- | $ nix-repl> | + | nix-repl> |
" | " | ||
</ | </ | ||
< | < | ||
- | $ nix-repl> | + | $ nix repl |
+ | nix-repl> | ||
nix-repl> | nix-repl> | ||
nix-repl> | nix-repl> | ||
this derivation produced the following outputs: out -> / | this derivation produced the following outputs: out -> / | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | nix-repl> | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | === nix edit === | ||
+ | Permet d' | ||
+ | < | ||
+ | $ EDITOR=vim nix edit -f "< | ||
+ | </ | ||
+ | |||
+ | On install ensuite le paquet: | ||
+ | < | ||
+ | $ nix-env -i samba | ||
</ | </ | ||
Ligne 497: | Ligne 574: | ||
</ | </ | ||
- | ==== Chemains | + | ==== Chemins |
< | < | ||
$ nix eval ' | $ nix eval ' | ||
Ligne 601: | Ligne 678: | ||
==== Override ==== | ==== Override ==== | ||
< | < | ||
- | $ nix-repl | + | $ nix repl |
nix-repl> | nix-repl> | ||
Added 4360 variables. | Added 4360 variables. | ||
Ligne 733: | Ligne 810: | ||
</ | </ | ||
+ | ==== builder ==== | ||
+ | |||
+ | < | ||
+ | { stdenv, fetchurl, openmpi }: | ||
+ | |||
+ | stdenv.mkDerivation rec { | ||
+ | name = " | ||
+ | src = fetchurl { | ||
+ | url = " | ||
+ | | ||
+ | }; | ||
+ | |||
+ | buildInputs = [ openmpi ]; | ||
+ | |||
+ | builder = builtins.toFile " | ||
+ | " | ||
+ | source $stdenv/ | ||
+ | mpicc -w -o oned.exe $src | ||
+ | mkdir $out | ||
+ | mkdir $out/bin | ||
+ | cp oned.exe $out/bin | ||
+ | "; | ||
+ | |||
+ | meta = { | ||
+ | description = "JDEV 2017 Nix tutoriel"; | ||
+ | license | ||
+ | platforms | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Overlays ===== | ||
+ | Pour ajouter un paquet personnel ou pour modifier un paquet déjà existant, Nix permet d' | ||
+ | Il s'agit de fichiers Nix que l'on place dans le dossier '' | ||
+ | |||
+ | Si on ajoute le fichier '' | ||
+ | <code nix ~/ | ||
+ | self: super: { | ||
+ | |||
+ | boost = super.boost.override { | ||
+ | python = self.python3; | ||
+ | }; | ||
+ | |||
+ | monAppli = super.callPackage ./ | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | Dans cet overlay, '' | ||
+ | |||
+ | Ces modifications seront alors automatiquement appliquées, | ||
+ | |||
+ | < | ||
+ | self: super: { | ||
+ | |||
+ | nano-no-nls = super.nano.override { | ||
+ | enableNls = false; | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Nix permet de modifier les paquets encore plus profondément. Par exemple, on peut modifier le paquet existant nano de façon à utiliser la version 4.5 du code source de nano: | ||
+ | |||
+ | < | ||
+ | self: super: { | ||
+ | |||
+ | nano = super.nano.overrideAttrs (oldAttrs: rec { | ||
+ | pname = oldAttrs.pname; | ||
+ | version = " | ||
+ | src = super.fetchurl { | ||
+ | url = " | ||
+ | sha256 = " | ||
+ | }; | ||
+ | }); | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== home-manager ===== | ||
+ | Le but d' | ||
+ | |||
+ | < | ||
+ | $ nix-env -iA nixos.home-manager | ||
+ | </ | ||
+ | |||
+ | <code nix ~/ | ||
+ | { pkgs, ... }: { | ||
+ | |||
+ | home.packages = with pkgs; [ | ||
+ | geany | ||
+ | meld | ||
+ | vlc | ||
+ | ]; | ||
+ | |||
+ | home.keyboard = { | ||
+ | layout = " | ||
+ | variant = " | ||
+ | }; | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | Prise en compte de la configuration: | ||
+ | < | ||
+ | $ home-manager switch | ||
+ | </ | ||
+ | |||
+ | Séparer: | ||
+ | <code nix ~/ | ||
+ | { pkgs, ... }: { | ||
+ | |||
+ | home.packages = with pkgs; [ | ||
+ | geany | ||
+ | meld | ||
+ | vlc | ||
+ | ]; | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code nix ~/ | ||
+ | { pkgs, ... }: { | ||
+ | |||
+ | imports = [ | ||
+ | ./ | ||
+ | ]; | ||
+ | |||
+ | home.keyboard = { | ||
+ | layout = " | ||
+ | variant = " | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Autre exemple: | ||
+ | <code nix> | ||
+ | { pkgs, ... }: { | ||
+ | programs = { | ||
+ | |||
+ | firefox.enable = true; | ||
+ | |||
+ | .git = { | ||
+ | enable = true; | ||
+ | userName = " | ||
+ | userEmail = " | ||
+ | |||
+ | ignores = [ | ||
+ | " | ||
+ | " | ||
+ | ]; | ||
+ | }; | ||
+ | | ||
+ | bash = { | ||
+ | enable = true; | ||
+ | shellAliases = { | ||
+ | ll = "ls -lh"; | ||
+ | la = "ls -a"; | ||
+ | }; | ||
+ | }; | ||
+ | }; | ||
+ | } | ||
+ | </ |
tuto/nix.1583519214.txt.gz · Dernière modification : 2020/03/06 18:26 de root