Every repository I keep has one file in its root called maak.scm, and that file is the project’s control plane. It builds, tests, lints, formats, serves, deploys, packages, releases and writes documentation. If a command matters to the project, it is a task in that file; if it is not in that file, it is a command somebody remembers, which means it is a command that will be forgotten.
Maak is a task runner à la Make whose task list is a Guile Scheme module. That one sentence is the whole design. Every procedure in the file is a task, its docstring is the task’s documentation, its lambda list is its argument grammar, and its body is Scheme. There is no configuration language to learn and no second language to quote things in.
This post is about how I use it, what the tasks look like after a few years, and the rules that keep a task file from becoming a second codebase.
A task file is a module #
The smallest Maak file that does something has three parts: a module declaration, a task, and a default task that lists the rest.
(define-module (maak) #:export (build test default) #:declarative? #t #:use-module (maak maak)) (define (build) "Compile the program." (run (list "make" "-C" "src"))) (define (test) "Run the test suite." (build) (run (list "make" "-C" "test"))) (define (default) "List the tasks this project defines." (list-tasks))
Then:
maak maak build maak test
#:export is the task list. When a module exports nothing, every procedure in the file is a task, which is convenient while a file is young. Once the file has helpers, the export list becomes the boundary: exported procedures are tasks, everything else is a private helper that the CLI never shows. I use the strict form in every project that has more than a handful of tasks, because a helper that appears in maak --list is a helper somebody will run with the wrong arguments.
#:declarative? #t is Guile’s promise that the module can be compiled and loaded in either order, which is what makes startup cheap. The file is a module, so Maak can also read it rather than run it: --list names the tasks and their docstrings, --plan shows the commands a task would run, --dry-run shows them and runs nothing, --completion bash prints a completion script from the same list. A file somebody is halfway through writing still answers questions about itself. That is the property I missed most in every other task runner.
Tasks compose like procedures #
A task calls another task the way a function calls a function:
(define (check) "Run every check the project has: the linters, then the tests." (lint) (test))
That is the whole of maak check in the site’s repository. It is not a dependency graph, not a list of names in a shell script, and not a CI file that has to be kept in step with a second CI file. It is two calls, and both are ordinary Scheme, so a task can also branch, loop, map over a list, or read a file before deciding what to do.
The composition is where the design earns its keep. maak test runs the Emacs ERT suite and then the TypeScript tests. maak lint runs the CSS linter, loads the build script in a batch Emacs, and type-checks the TypeScript. maak check runs lint then test. Each of those is a sentence in a file that a reader can follow without a diagram.
The tasks every repository grows #
After a few projects the shape settles. These are the ones I reach for first:
| Task | What it does |
|---|---|
fmt |
Formats the source: sift where the project uses it, guix style or a batch Emacs where it does not, the project formatter for the rest. |
lint |
Runs every linter the project has, without changing anything. |
test |
Runs the test suite, or the suites: unit, integration, rendered pages. |
check |
Lint then test. This is the gate a commit has to pass. |
build |
Produces the artifact: a binary, a site, a package. |
serve |
Serves the built artifact locally, after killing whatever was on the port. |
hot-reload / dev |
Watches the source and rebuilds on change. |
deploy |
Publishes the artifact where it belongs. |
release |
The whole release ritual: version, notes, gate, commit, tag, push. |
deb-build, arch-build, rpm-build, flatpak-build, nix-build |
Builds one distribution’s package. |
keys-update, modules-update, stats |
Writes or refreshes a generated document. |
One of those rows is the same program in most of my Scheme repositories. maak fmt in the Guix channel runs sift format --write over every .scm file, and maak check-formatting runs sift check ., which prints the patch it would make and exits non-zero. The sift repository formats itself the same way – a formatter that cannot read its own project is not one to trust with anyone else’s – so the formatter, a pre-commit hook and the CI gate are one executable.
There is a pattern in the right-hand column that took me a while to see. The tasks that check a thing and the tasks that write it are usually the same program with a flag. maak keys reads the configuration’s key tables and fails on an inconsistency; maak keys-update runs the same check with HEKS_KEYS_WRITE=1 and writes the reference. maak modules and maak modules-update are the same pair. maak doctor and maak doctor-update are the same pair. The document is an output of the same code that validates it, so the answer to “the manual is out of date” is never “edit the manual”.
argv, not shell strings #
The most important rule in the file is that a command is a list of arguments:
(define (serve) "Run HTTP server serving the rendered production result of running." (kill-server) (run (list "darkhttpd" "./public" "--port" (~ "~a" http-port))))
run takes an argv list. There is no shell in the middle, so a path with a space stays one argument, a file named $(rm -rf /) is a file name rather than a command, and the command in the source is the command that runs. The alternative – building a string and handing it to sh -c – is how a build script acquires a quoting bug that only appears on somebody else’s machine.
When a task genuinely needs a shell, it says so and explains why. The clearest example is a pipeline:
(define (add-libs) (delete-file-recursively ".ccls") ;; A pipe and an append-redirection, so this is one of the lines that needs a ;; shell. Every part is a word of it, and `tr''s second set is the `\n' ;; escape the shell hands over as a newline character. (time-machine-manifest-shell (append (list "pkg-config" "--cflags") (string-split (c-packages) #\space) (list "|" "tr" "' '" "'\n'" ">>" ".ccls")) #:verbose? #t) (cat ".ccls"))
The comment is the pattern: a shortcut with a known limit gets a sentence saying what the limit is and why it is acceptable. The same rule is written into the repository’s AGENTS.md: pass argument lists, never assemble a shell string out of data. It is one of the few rules that is easier to follow than to explain, because run with a list is shorter than the quoting.
The release ritual #
Release engineering is where a task runner either pays for itself or becomes a pile of half-remembered commands. Mine is one task, and the interesting part is the configuration above it. This is from Lambdock:
(define package-name "lambdock") (define version-source "package.nix") (define version-source-pattern "version[ \t]*=[ \t]*\"([0-9]+\\.[0-9]+\\.[0-9]+)\"") (define version-copies '( ("data/org.jointhefreeworld.lambdock.metainfo.xml" . "<release version=\"([0-9]+\\.[0-9]+\\.[0-9]+)\"") ("packaging/arch/PKGBUILD" . "pkgver=([0-9]+\\.[0-9]+\\.[0-9]+)") ("packaging/opensuse/lambdock.spec" . "Version:[ \t]+([0-9]+\\.[0-9]+\\.[0-9]+)") ("packaging/voidlinux/template" . "version=([0-9]+\\.[0-9]+\\.[0-9]+)") ("rust/Cargo.toml" . "\\[package\\][^[]*version = \"([0-9]+\\.[0-9]+\\.[0-9]+)\""))) (define changelog-file "NEWS.org") (define debian-changelog-file "packaging/debian/changelog") (define spec-file "packaging/opensuse/lambdock.spec") (define release-gate '("test"))
The version is written by hand once. Every other file that cannot read it carries a copy, found by a regular expression rather than a line number, and only the captured span is rewritten, so each file keeps its own alignment, quoting and wording. A pattern that stops matching is reported instead of silently checking nothing.
Then maak release 2.3.12 "The dock remembers its shelf across restarts." does the rest:
- Refuses to run on a dirty worktree, so the release commit is the release and not everything in progress.
- Writes the version into the version source and every copy.
- Writes the release notes into the Org changelog and the Debian changelog, and inserts an entry into the RPM spec’s
%changelogwith a C-locale date, sorpm -q --changelogreads the same everywhere. - Refuses a version whose tag already exists.
- Runs the gate –
maak test– and does not commit if it fails. - Commits
chore: Release vX.Y.Z, tags it with an annotated tag, pushes the branch and the tag, and opens the release on the forge unless the tag workflow publishes it instead.
What is left for a person is the checksum. The archive is published by the forge after the tag is pushed, and no task can know the hash of a file that does not exist yet. So the recipe’s checksum is refreshed from the published archive afterwards, and that step is written down as the one thing the ritual cannot do. Pretending otherwise would be the kind of automation that is wrong exactly once per release.
The same ritual exists in every repository, with the variables changed. That is not copy-paste for its own sake: the configuration block is a few dozen lines that say what this repository calls things, and the machinery below it is identical. When I fix a bug in the machinery, I fix it in one place and copy the fixed block; when a project’s layout differs, only the configuration differs.
Package builds are tasks too #
The distribution recipes live in packaging/, and the commands that drive them are tasks. Lambdock’s are a good tour because the project ships every format:
(define (deb-build) "Build .deb package (unsigned)" (dsl:run (list "apt" "update") #:sudo? #t #:verbose? #t) (dsl:run (append (list "apt" "install" "-y") (deb-packages)) #:sudo? #t #:verbose? #t) (dynamic-wind ;; Setup: create temporary symlink at project root (lambda () (ln-s "packaging/debian" "debian" #:force? #f #:verbose? #t)) ;; Execution: run debian build commands against ./debian (lambda () (dsl:run (list "mk-build-deps" "-i" "-r" "debian/control") #:sudo? #t #:verbose? #t) (dsl:run (list "debuild" "-b" "-uc" "-us") #:verbose? #t)) ;; Cleanup: remove symlink safely (leaves packaging/debian intact) (lambda () (rm-rf "debian" #:verbose? #t))))
The dynamic-wind is the interesting part: the package directory has to be at the repository root while Debian’s tools run, and the symlink has to be gone afterwards even if the build fails. That is what dynamic-wind is for, and it is a better answer than a trap in a shell script because it is the language’s own guarantee about the cleanup.
arch-build runs makepkg and then namcap on the PKGBUILD. rpm-build builds a source tarball with git archive at the tag, puts the spec where rpmbuild expects it, builds the binary and source RPMs, and runs rpmlint on both. flatpak-build installs the runtime and builds the manifest. nix-build and nix-test go through Maak’s Nix helpers. Every one of them is a task a person can run, and every one is the same command CI runs.
The environment is part of the task #
A task that needs a tool should name the environment that has it, not hope the machine does. Maak’s Guix helpers make that the default:
(define (js-tool name) "Return the path to the pinned NAME, installing the tools on first use." (unless (file-exists? (string-append "node_modules/.bin/" name)) (js-run (list "npm" "ci" "--no-audit" "--no-fund"))) (string-append "node_modules/.bin/" name))
js-run is the time-machine-manifest-shell call from the previous post. The effect is that maak lint-js does not care whether the machine has Node, and maak build does not care whether it has the right Emacs. The environment comes from the tree, the task says what command to run inside it, and the two are reviewed together.
There are helpers for the other direction too. run-pipeline captures output and reports failure without throwing; capture returns a string; git-output and its friends answer questions about the repository; home-dir, remkdir-p, rm-rf, cp and ln-s do the file operations a script would otherwise spell with mkdir -p and rm -rf. A task file that uses them reads like a description of what should happen rather than a transcript of shell commands.
Documentation as an output #
The habit that changed how I work is treating documentation as a build artifact. heks-emacs is the clearest case: maak keys-update writes the keybindings reference from the key tables, maak modules-update writes the module table from the module declarations, maak doctor-update writes the programs the modules expect into the installation page, and maak stats refreshes the numbers in the README. Each has a checking twin that fails when the document and the code disagree.
The rule generalises: if a document can be derived from data, derive it. If it cannot, write it by hand and put the hand-written part somewhere the checks can see. The worst outcome is a document that is almost generated – close enough to look authoritative, stale enough to be wrong.
Two more generated artifacts are worth naming because they are unusual:
maak agentswritesAGENTS.mdfrom two pinned skill files (fetched at a commit, not from a branch) and the practices written inmaak.scm. Regeneration is deterministic: the same pins and the same text produce the same file, byte for byte. The file says so at the top, and says that the task is the thing to edit.maak themesrenders one sample document in every installed palette into a single HTML page, so choosing a theme is a comparison rather than a sequence ofload-themecalls. A report is a legitimate build output.
Neither of those is necessary to build the software. Both make the project easier to work on, which is the difference between automation that saves typing and automation that saves thought.
CI is the same task #
The CI configuration should be a caller, not a second implementation. In the Guix channel the Woodpecker job names the tasks:
maak check-formattingasks the formatter to check rather than write, becausemaak fmtrewrites the tree it is judging and therefore cannot fail on a file nobody formatted.maak checklints offline, builds every package in the pinned Guix revision, and authenticates the channel’s history.
Formatting comes first so a red build names the cheapest thing first. The job definition is short because the work is in the task file. When a check changes, it changes in one place, and the next CI run is the proof.
The same principle applies to the site: its deployment is maak deploy, and maak deploy is maak build plus the copies that publish the result. There is no separate “production build” that differs from the development build in ways nobody remembers.
What Maak is not #
It is not a build system with a timestamp graph. It will not look at your .c files and decide which objects are out of date; it will run the task you named. If a task needs incrementality, the task says how – a compiler’s own dependency tracking, a hash of the inputs, a marker file – and the task’s comment says why. This is a feature, not a gap: the moment a task runner guesses what is stale, it also guesses wrong, and the failure is a build that silently skipped the thing you changed.
It is also not a package manager and not an environment manager. Those jobs belong to Guix, Nix and the distribution, and Maak’s job is to call them with the right arguments in the right order.
What it is: a place where a project’s operational knowledge lives in a language that can express it, with documentation attached to every task, and a CLI that can explain the file without running it. For the kind of projects I keep – libraries, GTK4 programs, static sites, a Guix channel – that is exactly the right size.
Getting started #
A first task file needs one module and one task:
(define-module (maak) #:use-module (maak maak)) (define (hello name) "Greet NAME." (log-info "hello ~a" name))
maak hello world maak --list maak --plan hello world maak --completion bash
Task arguments arrive as strings, because they came from a command line. A task that does arithmetic converts them:
(define (quick-math x-arg y-arg) (let* ((x (string->number x-arg)) (y (string->number y-arg))) (format #t "~a + ~a = ~a" x y (+ x y))))
From there, add the tasks in the order you actually run them. Start with check, because a gate you run is worth more than ten tasks you forget. Add release when the first tag hurts. Add the package builds when a distribution recipe exists. And resist the urge to add a task for every command: a task file that mirrors the shell’s history is a task file nobody reads.
The one habit I would keep above all others is the pair. Every generator gets a checker, every checker gets a generator where one is possible, and maak check runs the checkers. That is what makes the file a control plane rather than a scrapbook, and it is the reason I trust the projects to a single Scheme file at all.
The rest of this series: developing inside Emacs, the Guix and Nix files these tasks run inside, and packaging the results for the distributions.