Nix
Reproducibility speedrun
Human Talk - Grenoble :: 2024-06-11
nix
?The nix
language solves one problem : the creation and
composition of derivations
Where nix
really shines
$ nix run nixpkgs#hello
Hello, world!
Nix
fetched the hello
derivationNix
downloads and builds the package in an isolated
environment
/nix/store/$HASH-$PACKAGE-$VERSION
$ nix run nixpkgs/ac314c2c5c82685447deec12be65daac77503466#hello
[* MiB DL] copying «github:NixOS/nixpkgs/ac3...466» to the store
nixpkgs
repositoryNix
being pure, the same derivation will always yield
the same store pathA handy way to share project-specific environments from one machine to another
Nix
flake{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {nixpkgs, flake-utils, ...}:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit system; };
in with pkgs; {
devShells.default = mkShell { packages = [hello]; };
}
);
}
flake.lock
file is generated on the first run,This very presentation was built with nix
using
pandoc
and reveal.js
NixOS
is a Linux distribution that is configured using
the nix
languageNix Darwin
is the same but on top macOSoutputs = { nixpkgs, ... }: {
nixosConfigurations.$HOSTNAME = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [ ./configuration.nix ];
};
};
nixos-rebuild switch --flake .#HOSTNAME
Configuration.nix
?This is where the magic happens
Those packages and settings will be available system-wide
Services will be started at boot time
Home-manager
allows to manage user configurationNix
can be used to build Docker
images
without a Dockerfile