nix-samples/README.md

2.3 KiB

Nix samples

Existing samples

  • hello-world: Sample local C program;
  • hello-world-github: Some github hosted program, built against Wayland;
  • hello-world-callpackage: A basic callPackage usage;
  • hello-world-go: Basic usage of buildGoModule;
  • hello-world-docker: A docker image of a binary extracted from another derivation;
  • simple-shell: Some shells;
  • hello-versions: Choosing some package version;
  • samples: A directory with found exicting recipes!
  • flake-basic: A really basic flake
  • flake-basic-platform: A slighly more complex flake, with more targets
  • flake-mkDerivation: A flake with a ... mkDerivation
  • flake-rust-devshell: A flake with a rust overlay

Building, running, deleting

hello-world

> cd /path/to/nix-samples
> nix-build hello-world/default.nix
this derivation will be built:
  /nix/store/rwi8d1fv4hnpl194pi2cj7ikph2k5ny8-hello.drv
building '/nix/store/rwi8d1fv4hnpl194pi2cj7ikph2k5ny8-hello.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/29265kg6m3mzgf7rhfqjx34dwhgn9p4g-src
...
stripping (with command strip and flags -S -p) in  /nix/store/4nzxqrm1gddddwlz55c2q398p0si4qhf-hello/bin
/nix/store/4nzxqrm1gddddwlz55c2q398p0si4qhf-hello

> nix profile install /nix/store/4nzxqrm1gddddwlz55c2q398p0si4qhf-hello
> nix profile list
Name:               hello
Store paths:        /nix/store/4nzxqrm1gddddwlz55c2q398p0si4qhf-hello

> hello
/home/mycroft/.nix-profile/bin/hello

Note: ~/.nix-profile/bin was added in $PATH.

Prior to remove it, it must be unlinked from the profile and the build:

> nix-store --query --roots /nix/store/4nzxqrm1gddddwlz55c2q398p0si4qhf-hello
/home/mycroft/.local/state/nix/profiles/profile-7-link -> /nix/store/53zlkdqd1m2wdgi2a9q390ld9gkkkydf-profile
/home/mycroft/dev/nix-samples/result -> /nix/store/4nzxqrm1gddddwlz55c2q398p0si4qhf-hello

> nix profile remove /nix/store/4nzxqrm1gddddwlz55c2q398p0si4qhf-hello
removing 'hello'

> 

It will be needed to wipe the profile history and the result link to be able to nix-store --delete or nix-collect-garbage.

Resources