Outils pour utilisateurs

Outils du site


tuto:nix

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
tuto:nix [2020/03/06 18:56] – [home-manager] roottuto:nix [2022/06/21 20:15] (Version actuelle) – [nix-shell] root
Ligne 15: Ligne 15:
       * [[https://nixos.wiki/index.php?title=Cheatsheet&useskin=vector|Cheatsheet]]       * [[https://nixos.wiki/index.php?title=Cheatsheet&useskin=vector|Cheatsheet]]
  
 +===== nix-user-chroot =====
 +https://github.com/nix-community/nix-user-chroot
 +
 +Outil qui permet de donner un répertoire qui sera présenter comme point de montage ''/nix'' grâce au namespace en espace utilisateur:
 +<xtermrtf>
 +$ mkdir -m 0755 ~/.nix
 +$ nix-user-chroot ~/.nix ${SHELL=bash} -l
 +</xtermrtf>
 ===== Installation ===== ===== Installation =====
 <xtermrtf> <xtermrtf>
Ligne 36: Ligne 44:
 </xtermrtf> </xtermrtf>
  
 +==== NIX_PAGER ====
 <xtermrtf> <xtermrtf>
 export NIX_PAGER= export NIX_PAGER=
 +</xtermrtf>
 +
 +==== nixpkgs ====
 +<xtermrtf>
 +nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-15.09.tar.gz
 +nixpkgs=channel:nixos-15.09
 </xtermrtf> </xtermrtf>
  
Ligne 59: Ligne 74:
 $ nix-env -u --dry-run $ nix-env -u --dry-run
 $ nix-env -e hello $ nix-env -e hello
 +</xtermrtf>
 +
 +Force a specific channel (master in this example):
 +<xtermrtf>
 +$ nix-env -f https://github.com/NixOS/nixpkgs/archive/master.tar.gz -iA hello
 </xtermrtf> </xtermrtf>
  
Ligne 120: Ligne 140:
 ==== nix-shell ==== ==== nix-shell ====
   * https://www.sam.today/blog/environments-with-nix-shell-learning-nix-pt-1/   * https://www.sam.today/blog/environments-with-nix-shell-learning-nix-pt-1/
 +
 +<code haskell shell.nix>
 +{ pkgs ? import <nixpkgs> {} }:
 +
 +with pkgs;
 +
 +mkShell {
 +  buildInputs = [
 +    elixir_1_10
 +    nodejs-12_x
 +  ];
 +}
 +</code>
 +
 +<xtermrtf>
 +$ nix-shell
 +$ nix-shell shell.nix
 +</xtermrtf>
 +
 <xtermrtf> <xtermrtf>
 $ nix-shell --pure -E 'import <nixpkgs> {}' -A hello $ nix-shell --pure -E 'import <nixpkgs> {}' -A hello
Ligne 136: Ligne 175:
 <xtermrtf> <xtermrtf>
 $ nix-shell '<nixpkgs>' -A emacs --command 'unpackPhase; patchPhase' $ nix-shell '<nixpkgs>' -A emacs --command 'unpackPhase; patchPhase'
 +</xtermrtf>
 +
 +Force a specific channel:
 +<xtermrtf>
 +$ nix-shell -p hello -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz
 </xtermrtf> </xtermrtf>
  
Ligne 189: Ligne 233:
 $ nix-channel --add https://nixos.org/channels/nixos-19.09 nixpkgs_19_09 $ nix-channel --add https://nixos.org/channels/nixos-19.09 nixpkgs_19_09
 $ nix-channel --remove nixpkgs_19_09 $ nix-channel --remove nixpkgs_19_09
 +</xtermrtf>
 +
 +Master channel:
 +<xtermrtf>
 +$ nix-channel --add https://github.com/NixOS/nixpkgs/archive/master.tar.gz master
 </xtermrtf> </xtermrtf>
  
Ligne 306: Ligne 355:
 path is '/nix/store/2l5az5rvkkavrr7zgghgqpmsqj3vn1yp-742781c358d65c8849a6a6f5b8f4bb3dcefc203a.tar.gz' path is '/nix/store/2l5az5rvkkavrr7zgghgqpmsqj3vn1yp-742781c358d65c8849a6a6f5b8f4bb3dcefc203a.tar.gz'
 02cgs6b1rmh8hmcwm5wpxxg32p3km9c05606pykv49qq1spd6p38 02cgs6b1rmh8hmcwm5wpxxg32p3km9c05606pykv49qq1spd6p38
 +</xtermrtf>
 +
 +==== nix-instantiate ====
 +<xtermrtf>
 +$ nix-instantiate --eval -E '(import <nixpkgs> {}).vscode.version'
 +"1.43.0"
 +</xtermrtf>
 +
 +<xtermrtf>
 +$ nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
 +"20.09pre216928.991bbef6835"
 </xtermrtf> </xtermrtf>
  
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> builtins.currentSystem+nix-repl> builtins.currentSystem
 "x86_64-linux" "x86_64-linux"
 </xtermrtf> </xtermrtf>
  
 <xtermrtf> <xtermrtf>
-$ nix-repl> :l <nixpkgs>+nix repl 
 +nix-repl> :l <nixpkgs>
 nix-repl> simple = derivation { name = "simple"; builder = "${bash}/bin/bash"; args = [ ./simple_builder.sh ]; gcc = gcc; coreutils = coreutils; src = ./simple.c; system = builtins.currentSystem; } nix-repl> simple = derivation { name = "simple"; builder = "${bash}/bin/bash"; args = [ ./simple_builder.sh ]; gcc = gcc; coreutils = coreutils; src = ./simple.c; system = builtins.currentSystem; }
 nix-repl> :b simple nix-repl> :b simple
 this derivation produced the following outputs: out -> /nix/store/ni66p4jfqksbmsl616llx3fbs1d232d4-simple this derivation produced the following outputs: out -> /nix/store/ni66p4jfqksbmsl616llx3fbs1d232d4-simple
 +</xtermrtf>
 +
 +<xtermrtf>
 +nix-repl> (builtins.parseDrvName "NUnit.Console-3.0.1").name
 +"NUnit.Console"
 +</xtermrtf>
 +
 +=== nix edit ===
 +Permet d'éditer un build avant de l'installer ([|https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-edit.html|nix edit]]):
 +<xtermrtf>
 +$ EDITOR=vim nix edit -f "<nixpkgs>" samba --extra-experimental-features nix-command
 +</xtermrtf>
 +
 +On install ensuite le paquet:
 +<xtermrtf>
 +$ nix-env -i samba
 </xtermrtf> </xtermrtf>
  
Ligne 497: Ligne 574:
 </xtermrtf> </xtermrtf>
  
-==== Chemains (path) ====+==== Chemins (path) ====
 <xtermrtf> <xtermrtf>
 $ nix eval '(some/path)'  $ nix eval '(some/path)' 
Ligne 601: Ligne 678:
 ==== Override ==== ==== Override ====
 <xtermrtf> <xtermrtf>
-$ nix-repl+$ nix repl
 nix-repl> :l <nixpkgs> nix-repl> :l <nixpkgs>
 Added 4360 variables. Added 4360 variables.
Ligne 731: Ligne 808:
    \_/\_/ \___|_|\___\___/|_| |_| |_|\___(_)    \_/\_/ \___|_|\___\___/|_| |_| |_|\___(_)
  
 +</xtermrtf>
 +
 +==== builder ====
 +
 +<xtermrtf>
 +{ stdenv, fetchurl, openmpi }:
 +
 +stdenv.mkDerivation rec {
 +  name = "oned";
 +  src = fetchurl {
 +     url = "https://www.pdc.kth.se/education/tutorials/mpi/hybrid-lab/oned.c";
 +     sha256 = "<HASH_HERE>";
 +  };
 +
 +  buildInputs = [ openmpi ];
 +
 +  builder = builtins.toFile "builder.sh"
 +  "
 +  source $stdenv/setup
 +  mpicc -w -o oned.exe $src
 +  mkdir $out
 +  mkdir $out/bin
 +  cp oned.exe $out/bin
 +  ";
 +
 +  meta = {
 +    description = "JDEV 2017 Nix tutoriel";
 +    license     = stdenv.lib.licenses.gpl2;
 +    platforms   = stdenv.lib.platforms.unix;
 +  };
 +}
 </xtermrtf> </xtermrtf>
  
tuto/nix.1583520976.txt.gz · Dernière modification : 2020/03/06 18:56 de root