Nix Package Manager

Pierre Gambarotto

Created: 2023-11-15 mer. 09:28

Nix comme package manager

flakes :

  • épingler les dépendances à une version précise, e.g. nixpkgs
  • distribuer des choses définies dans le langage nix :
    • des packages
    • des configurations nixos
    • des environnements shell
    • et autres

Exemple : packager xymon-client

https://plmlab.math.cnrs.fr/nix/xymon-client extrait du flake.nix :

xymon-client = pkgs.stdenv.mkDerivation {
  pname = "xymon-client";
  version = "4.3.30";
  buildInputs = with pkgs;[ pcre libtirpc ]; # dependancies
  CONFTYPE = "client";            #
  XYMONUSER="$(whoami)";          #
  XYMONTOPDIR="$(out)";           # ENV variables
  XYMONHOSTIP = "127.0.0.1";      #
  PKGBUILD = "yes";               #
  configureFlags = [
    "--client"
    "--pcreinclude ${pkgs.pcre}/include"
    "--pcrelib ${pkgs.pcre}/lib"
    "--make ${pkgs.gnumake}/bin/make"
  ];
  dontAddPrefix = true;
  src = builtins.fetchurl {
    url = "https://netcologne.dl.sourceforge.net/project/xymon/Xymon/4.3.30/xymon-4.3.30.tar.gz";
    sha256 = "sha256:1xgm3ch2aqlmmkny3805c47ap1hjl9hjq1r5czwmvqg1r1qigmcf";
  };
};

stdenv.mkDerivation

fournit des scripts bash correspondant aux phases de construction d’un paquetage :

  • unpackPhase
  • patchPhase
  • configurePhase
  • buildPhase
  • checkPhase
  • installPhase
  • fixupPhase
  • installCheckPhase
  • distPhase

Phase => fonction bash

declare -f configurePhase

Construire un paquetage

nix build git+https://plmlab.math.cnrs.fr/nix/xymon-client.git --accept-flake-config
# => creates result in current directory

Installer un paquetage

nip profile install git+https://plmlab.math.cnrs.fr/nix/xymon-client.git --accept-flake-config
which xymon
# => ~/.nix-profile-bin/xymon
realpath $(which xymon)
/nix/store/x8h3v902g3h5df5djx0r2rhkl66l3yld-xymon-client-4.3.30/bin/xymon

Obtenir un shell avec l’environnement de construction

nix develop git+https://plmlab.math.cnrs.fr/nix/xymon-client.git
# new shell
echo $IN_NIX_SHELL # impure
# manual build
unpackPhase# create xymon-4.3.30
cd xymon-4.3.30
configurePhase
buildPhase
installPhase
fixupPhase
cd ..
# results is in outputs