Skip to content

Latest commit

 

History

History
38 lines (27 loc) · 1.49 KB

File metadata and controls

38 lines (27 loc) · 1.49 KB

MakeNix

Checkout my blog post https://fzakaria.com/2025/03/11/nix-dynamic-derivations-a-practical-application for an overview on this example.

This is a demonstratin of the power of dynamic-derivations in Nix leveraged to build a C/C++ project via Makefile.

⚠️ As of 2025-03-11, you need to use nix@d904921 in order to use dynamic-derivations. Additionally, you need to enable experimental-features = ["nix-command" "dynamic-derivations" "ca-derivations" "recursive-nix"]. Here, there be dragons 🐲.

# let's do everything in /tmp/dyn-drvs as a temporary
# nix store.
# 
# enter a bind mount for the temporary store
> nix run nixpkgs#fish --store /tmp/dyn-drvs

> nix build -f default.nix --store /tmp/dyn-drvs --print-out-paths -L
/nix/store/v4hkwn8y4m083gsap6523c0m5r985ygr-result

> ./result
Hello, World!

Check out NpmNix for an example of how you might apply dynamic-derivations for lang2nix style tooling.

Testing

You can run the parser by itself to generate the Nix expression that generates all the object files.

Afterwards you can build the nix expression to validate that it works.

# generate the .d files we need
> make deps
# generate the nix expression
> go run parser/parser.go > test.nix
# test it!
> nix build -f test.nix --arg pkgs 'import <nixpkgs> {}'