- Nix 78%
- CMake 16.3%
- C 5.7%
| .gitignore | ||
| CMakeLists.txt | ||
| default.nix | ||
| flake.lock | ||
| flake.nix | ||
| hello.c | ||
| LICENSE | ||
| README.md | ||
| shell.nix | ||
A simple Nix flake example project. See this Reddit thread for context.
The hello.c and CMakeLists.txt files represent the existing package source file and build rules. You should have these already, or something equivalent like a Makefile for non-CMake C/C++ projects. The flake.lock file is auto-generated by nix build; it records the specific revisions of the dependencies to support reproducible builds. shell.nix is optional but provides an environment with cmake, make, and gcc for nix develop. default.nix defines the actual derivation (build rules) for the hello-flakes package. Depending on the programming language there may be existing Nix library routines you can use to simplify derivations. Finally the flake.nix file ties everything together. All the filenames other than flake.nix and flake.lock are arbitrary for Nix flakes (but customary). Some were chosen for compatibility with older Nix commands like nix-shell.
To adapt this for another CMake-based package you would need to update the package name (anywhere hello-flakes is mentioned in *.nix) and add any required dependencies to the buildInputs list in default.nix. (They should also be added in shell.nix for development builds.) Non-CMake builds would require additional alterations. After making those changes delete the example flake.lock and let nix build recreate it.