In 2023 I started experimenting with Nix. I thought I could keep it contained to just some of my side-projects, but I soon lost control. I had heard about Nix before, but no one ever warned me; A little Nix on the side quickly became NixOS on my personal computer. In no time, I found myself up late at nights re-writing my dotfiles, trying to make them more declarative, refactoring my system configuration in a language I can still barely comprehend. But it wasn't enough. I needed more.
At work the hours dragged on while I suffered on Nixless machines. Just the thought of going eight hours without re-writing a configuration file into a declarative module with type-checking made me break into a cold sweat. I needed to find a way to feed my addiction. But there were so many systems out there without Nix, how could I get my fix? How could I continue to experience the un-paralleled high that only comes from gloriously reproducible software?
That pursuit may never end, but for now it has take the form of Make-nix.
The Makefile contains target recipes to The flake.nix configuration imports make_opts.nix. This file contains an attribute set generated by the Makefile. This is where the imperative options provided by the user are bridged with the declarative configuration.
📘 make-nix usage
make <help|install|home|system|all|test>
[TGT_USER=<user>]
[TGT_HOST=<host>]
[TGT_TAGS=<tag1>,<tag2>,<tag3>,...]
[TGT_SYSTEM=<system>]
[TGT_SPEC=<spc1>,<spc2>,<spc3>,...]
[OPTION FLAGS]| Target | Description |
|---|---|
help |
View make-nix usage help. |
install |
Install Nix and/or Nix-Darwin. |
home |
Build and activate a Home-manager configuration. |
system |
Build and activate a NixOS or Nix-Darwin system configuration. |
all |
Execute both the system and home targets in that order. |
test |
Check all flake configurations. |
| Variable | Description |
|---|---|
TGT_USER |
User configuration (current user will be passed by default). |
TGT_HOST |
System configuration host (current hostname will be passed by default). |
TGT_SYSTEM |
System platform to target for builds: x86_64-linux, aarch64-linux, x86_64-darwin, or aarch64-darwin (current platform will be passed by default). |
TGT_SPEC |
Comma-separated list of system specialisation configurations (no spaces). |
TGT_TAGS |
Customize home-manager user configuration based on tags, similar to specialisations for system configurations. |
These are boolean; assigning any truthy value will enable them.
Truthy values:
1,yes,Yes,YES,true,True,TRUE,on,On,ON,y,Y
DETERMINATE=true– Install Nix using the Determinate Systems installer.NIX_DARWIN=true– Install Nix-Darwin for macOS.SINGLE_USER=true– Install Nix for single-user mode (default installer only).USE_CACHE=true– Use the NIX_CACHE_URLS list from the make.env file as a proxy cache instead of cache.nixos.org. This variable accepts a comma-separated list of URLs (no spaces), in order of precidence.
DRY_RUN=true– Evaluate the new configuration but don't activate it.HOME_ALONE=true– Configure options for a system running home-manager without NixOS or Nix-Darwin.BOOT_SPEC=true– Set the default boot menu option to the first listed specialisation.
Note: Only supports systemd-boot configurations.
KEEP_LOGS=true– Don't erase logs after operations (for debugging).
# Install Nix using the default installer for single-user mode:
make install SINGLE_USER=Y
# Install Nix-Darwin using the Determinate Systems installer:
make install DETERMINATE=1 NIX_DARWIN=y
# Build and activate the home-manager config using a standalone configuration:
make home HOME_ALONE=true
# Build and activate the current system configuration:
make system
# Standalone home-manager config for user `sam` on host `xps-15`, with tags and platform:
make home user=sam host=xps-15 system=aarch64-linux HOME_ALONE=1 tags=debian,server
# Rebuild and switch system with specialisations and boot default:
make system host=workstation1 spec=wayland,x11_egpu BOOT_SPEC=1
# Rebuild and switch both system and home-manager configs:
make all
# Evaluate (but do not activate) all configurations:
make all DRY_RUN=1
# Run `nix flake check` for all configurations:
make test