Build, cache, and run possibly compiled scripts with dependencies using the Nix package manager.
- Magix is simple and stupid.
- Magix is a tiny wrapper around
nix-build
. - Magix uses a Nix expression templates, and so, is easier to understand, modify, and enhance.
- Magix is heavily tested (only unit tests at the moment, but please drop a pull request).
#!/usr/bin/env magix
#!magix bash
#!runtimeInputs jq
jq --help
#!/usr/bin/env magix
#!magix haskell
#!haskellPackages bytestring
#!ghcFlags -threaded
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString qualified as BS
main :: IO ()
main = BS.putStr "Hello, World!\n"
#!/usr/bin/env magix
#!magix python
#!pythonPackages numpy
from numpy import array
xs = array([1,2,3])
print(xs)
Try Magix without installation on a Bash script called =empty=
wget https://github.com/dschrempf/magix/raw/refs/heads/main/test-scripts/bash/empty
nix run github:dschrempf/magix#magix empty
empty
Install Magix, and, for example, run the =args= test script for Bash
./test-scripts/bash/args one two three -h
Command basename is: args Command line arguments are: one two three -h
magix -h
Usage: magix [-v|--verbose] [-f|--force-build] [-c|--cache-path CACHE_PATH] [-n|--nixpkgs-path NIXPKGS_PATH] SCRIPT_FILE_PATH [SCRIPT_ARGS] Build, cache, and run possibly compiled scripts with dependencies using the Nix package manager Available options: -h,--help Show this help text -v,--verbose Print debug messages -f,--force-build Force build, even when cached build exists -c,--cache-path CACHE_PATH Path of cache directory to use for builds (default: '$XDG_CACHE_HOME/magix') -n,--nixpkgs-path NIXPKGS_PATH Path of Nixpkgs repository to use (default: extracted from '$NIX_PATH') SCRIPT_FILE_PATH File path of script to build, cache and run SCRIPT_ARGS Arguments passed on to the script
- Property-based testing (e.g., generate arbitrary directives or even scripts). When creating arbitrary directives, one could test if the resulting Nix expressions are syntactically correct.
- We create random caches and hashes during tests. We could write an Arbitrary
instance for
Config
to simplify this process. - CICD pipeline.
I have performed basic benchmarks and have recorded some profiles. When a script is cached, Magix has a runtime cost of around 20ms.
The runtime cost depends on the used language because the Nix expressions used to wrap the script are different.
- bennofs/nix-script: Does not pre-compile scripts, does not cache compilations; however, Haskell code base and complexity seems to be much smaller.
- BrianHicks/nix-script: Magix was heavily inspired by BrianHicks/nix-script, which I also maintain. However, my Rust is a bit rusty, and I wanted a simpler solution.
I want magix
to be a simple and fast solution that just works. If you are
looking for a wrapper with more extras, try the Nix package manager ;-).