$ zimbatm

How to package with Nix

by: zimbatm https://zimbatm.com

slide: https://zimbatm.com/talks/howto-package-with-nix


Nixpkgs

https://github.com/NixOS/nixpkgs


the derivation

{ name
, system
, builder
, args ? [ ]
, outputs ? [ "out" ]
, __structuredAttrs ? false
, outputHash ? null
, outputHashAlgo ? null
, outputHashMode ? null
, allowedReferences ? null
, disallowedReferences ? null
, allowedRequisites ? null
, disallowedRequisites ? null
, maxSize ? null
, maxClosureSize ? null
, ...
}@drvAttrs:

let
  self = {
    all = [ self ];
    name = name;
    outPath = ...;
    drvPath = ..."
    drvAttrs = drvAttrs
    type = "derivation";
    outputName = "out";
  };
in
  self

stdenv.mkDerivation

pkgs/stdenv/generic/setup.sh

{ pname ? null
, version ? null
, name = "${pname}-${version}"

, buildInputs ? []
, nativeBuildInputs ? []

, phases = [
    "unpackPhase"
    "patchPhase"
    "configurePhase"
    "buildPhase"
    "checkPhase"
    "installPhase"
    "fixupPhase"
    "installCheckPhase"
    "distPhase"
  ]
 
, meta = {}
, passthru  ? {}
 
}

build phases cont

{
  # unpackPhase
, src ? null
 
  # patchPhase
, patches ? []
 
  # configurePhase
, configureFlags ? []
, cmakeFlags ? []
 
  # checkPhase
, doCheck ? false
 
  # installPhase
, outputs ? [ "out" ]
 
  # installCheckPhase
, doInstallCheck ? false

}

build hooks

{
  buildInputs = [ cmake ];
}

search for make


packaging a C program


entering the build

cntr support

breakpointHook


dev vs nixpkgs


Python


Ruby


Rust


Node


Go

{ buildGoPackage, fetchFromGitHub }:
buildGoPackage rec {
  name = "vgo2nix-${version}";
  version = "example";
  src = fetchFromGitHub { ... };  # Incomplete
  goDeps = ./deps.nix;
}

 _____
< EOF >
 -----
       \     (\/)
        \   (_o |
             /  |
             \  \______
              \        )o
               /|----- |
               \|     /|