wiki/notebook/tools.nix.derivations.org
foo-dogsquared ffbd770528 Update Nix-related notes
Pretty incomplete but it is going to be... :)
2021-12-28 21:13:35 +08:00

2.8 KiB

Nix derivations

Derivations are recipes for the Nix build daemon how to build the package. At a glance, this is the equivalent to manifests from Flatpak packages or Guix packages.

The following code block shows what a derivation looks like.

nix show-derivation nixpkgs#hello
{
  "/nix/store/vvb4wxmnjixmrkhmj2xb75z62hrr41i7-hello-2.10.drv": {
    "outputs": {
      "out": {
        "path": "/nix/store/xcp9cav49dmsjbwdjlmkjxj10gkpx553-hello-2.10"
      }
    },
    "inputSrcs": [
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "inputDrvs": {
      "/nix/store/127p1886lb1q7x02wyy77ib9ghhc324v-hello-2.10.tar.gz.drv": [
        "out"
      ],
      "/nix/store/4lzwc3wzbqjq973psxkph8jjq4g6cssr-stdenv-linux.drv": [
        "out"
      ],
      "/nix/store/js6ib8zv84knb7kwnjdrqgwf86djjblk-bash-5.1-p12.drv": [
        "out"
      ]
    },
    "system": "x86_64-linux",
    "builder": "/nix/store/a54wrar1jym1d8yvlijq0l2gghmy8szz-bash-5.1-p12/bin/bash",
    "args": [
      "-e",
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "env": {
      "buildInputs": "",
      "builder": "/nix/store/a54wrar1jym1d8yvlijq0l2gghmy8szz-bash-5.1-p12/bin/bash",
      "configureFlags": "",
      "depsBuildBuild": "",
      "depsBuildBuildPropagated": "",
      "depsBuildTarget": "",
      "depsBuildTargetPropagated": "",
      "depsHostHost": "",
      "depsHostHostPropagated": "",
      "depsTargetTarget": "",
      "depsTargetTargetPropagated": "",
      "doCheck": "1",
      "doInstallCheck": "",
      "name": "hello-2.10",
      "nativeBuildInputs": "",
      "out": "/nix/store/xcp9cav49dmsjbwdjlmkjxj10gkpx553-hello-2.10",
      "outputs": "out",
      "patches": "",
      "pname": "hello",
      "propagatedBuildInputs": "",
      "propagatedNativeBuildInputs": "",
      "src": "/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz",
      "stdenv": "/nix/store/xcmlbsqabmckx42p8w18ri5zq8v2iiav-stdenv-linux",
      "strictDeps": "",
      "system": "x86_64-linux",
      "version": "2.10"
    }
  }
}

While we can create derivations with the derivations builtin from the Nix language, in practice you'll use stdenv.mkDerivation from nixpkgs standard library.

  • nixpkgs also comes with several convenient functions/environments for several programming languages and frameworks including Python, Rust, Go, and Nim
  • it also includes environments for common setups such as for clang compiler