Install nix (https://nixos.org/download.html)

sh <(curl -L https://nixos.org/nix/install) --daemon

Create a place for the hello world

mkdir helloworld
cd helloworld
touch default.nix

nix-prefetch-url https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz
# path is '/nix/store/xxx-hello-2.10.tar.gz'
# 0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i

Edit file ‘helloworld/default.nix'

let
pkgs = import <nixpkgs> {};
in
pkgs.stdenv.mkDerivation {
name = "hello-2.10";
src = pkgs.fetchurl {
url = "https://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz";
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
};
}

Build also known as ’nix-build default.nix'

nix-build
ls -l
# -rw-r--r-- 1 xxx xxx 248 dd mmm hh:mm default.nix
# lrwxr-xr-x 1 xxx xxx 54 dd mmm hh:mm result -> /nix/store/xxx-hello-2.10

tree result
# result
# ├── bin
# │ └── hello
# └── share
# ├── info
# │ └── hello.info
# └── man
# └── man1
# └── hello.1.gz
./result/bin/hello
# Hello, world!

Inspiration: