Concept → IO ()

Linux Emacs Coding Music Links About Search

It's Magix

Long time no see! In this post I would like to present Magix, a tool to build, cache, and run possibly compiled scripts with dependencies using the Nix package manager.

First, I would like to draw your attention to a blog post by Brian Hicks, in which he introduces nix-script. In brief, Magix is a slimmed down version of nix-script:

Have a look at the following example:

#!/usr/bin/env magix
#!magix haskell
#!haskellPackages text

import Data.Text (pack)
import Data.Text.IO (putStrLn)
import Prelude hiding (putStrLn)

main :: IO ()
main = putStrLn $ pack "Hello, World!"

Magix is going to

  1. parse the directives,
  2. assemble a tiny Nix wrapper expression,
  3. use the Nix package manager to build this expression, and
  4. run the derivation result.

The first time doing so, takes around 0.9 seconds on my machine. That sucks. However, in step 1, Magix also hashes the input script, and saves a link to the derivation result. That is, if Magix knows a script, the next execution is much faster: 0.09 seconds. That is one order of magnitude faster!