Skip to content

fzakaria/MakeNix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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> {}'

About

A demonstration of how you can leverage Nix dynamic derivations for C/C++ Makefile projects

Topics

Resources

License

Stars

Watchers

Forks