A Flake for your Crate
Creating a Nix Flake for your Rust crate.
Nix (PDF) provides users a way to access the massive Nixpkgs library of packages, create reproducable builds of software, roll slim containers, create declarative VMs, or run their whole machines. A new feature of Nix, Flakes, is bringing a convention to how projects like Rust crates can be accessed, integrated, and used within Nix (or NixOS.)
Let's explore how we can make our Rust crate usable as a Nix flake. At the end of this, any
nix user with Flakes enabled should be able to run your project with something like
nix run github:user/project. They'll be able to add your repository as a Nix overlay, install the package, do interactive builds, or create a portable bundle of it.
Using rust-bindgen in Nix
Getting things linking.
While building the Nix packages for pl/Rust I bumped into a curious issue: I couldn't link to
stdbool.h! They were clearly on my path, too.
Custom live media with Nix flakes
How to make live media with Nix flakes.
I've always been quite fond of booting live media. To test or install a new operating system, to recover an old one, find some privacy, or to do a myriad of other specialized tasks. LiveUSBs and liveCDs introduced to me a new way of thinking about my computer.
It improved my mental model of the separation of between the machine, the UEFI (or BIOS), any bootloaders, and the operating system itself.
As I learnt about them over 15 years ago I spent months exploring ways to use them. I used them to rescue systems for myself and others, diagnose hardware, recovery files, and quickly set up machines.
With Nix flakes, we can define a custom live system and build it with minimal steps. This NixOS live system which could be a composition of existing NixOS modules, or an entirely new configuration.Continue reading...