Language page — context, influences, and learning notes on the 100hellos site.
Source on GitHub (100hellos/nix)
docker run --rm --platform="linux/amd64" 100hellos/nix:latest
Read the repo README, or fork the project and customize it.
For an interactive shell:
docker run --rm --platform="linux/amd64" --entrypoint="" -it 100hellos/nix:latest zsh
Nix is a purely functional package manager and build system that treats packages like values in purely functional programming languages such as Haskell - they are built by functions that don't have side-effects, and they never change after they have been built.
Nix is both a package manager and a domain-specific functional programming language used for package management and system configuration. The Nix language is dynamically typed and purely functional, making it excellent for describing package builds and system configurations in a declarative way.
Our Nix "Hello World!" program uses a pure Nix expression that gets evaluated natively:
hello-world.nix:
# Pure Nix Hello World program
# This is a native Nix expression that evaluates to "Hello World!"
"Hello World!"
hello-world.sh:
#!/bin/sh
# Source Nix environment
. /home/human/.nix-profile/etc/profile.d/nix.sh
# Evaluate the pure Nix expression and clean up the output
nix-instantiate --eval --strict /hello-world/hello-world.nix | tr -d '"'
This approach demonstrates Nix's core functionality as a language - we write a pure Nix expression (just the string literal "Hello World!") and use nix-instantiate --eval to evaluate it. This is truly native Nix, not just using Nix to spawn other tools.
Nix works excellently on MUSL-based systems like Alpine Linux through its single-user installation mode. The --no-daemon flag ensures compatibility with containerized environments and MUSL-based distributions.
You can easily modify the hello-world.nix file to explore more complex Nix capabilities:
# Mathematical expression
1 + 2 * 3
# String interpolation
let name = "World"; in "Hello ${name}!"
# Function application
(x: "Hello " + x) "World!"
# List operations
builtins.head ["Hello" "World" "!"]
You can also modify the shell script to use nix-shell for creating reproducible environments:
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p figlet cowsay
figlet "Hello from Nix!"
cowsay "Reproducible environments are awesome!"
The beauty of this approach is that hello-world.nix contains pure Nix language code that can be arbitrarily complex, while the shell script simply evaluates it using native Nix tools.
.nix fileContent type
Image
Digest
sha256:26d52e16d…
Size
153 MB
Last updated
4 months ago
docker pull 100hellos/nix