Compile Linux out-of-tree Module on NixOS in a Nix shell with an FHS Environment

In an earlier post, I talked about how you can build an out-of-tree Linux kernel module in a Nix derivation, i.e., package it in Nix. However, for quick prototyping, sometimes you want to just enter $ make in your shell, for example to check if everything compiles. Out-of-tree module projects following the recommended guidelines use a Makefile, possibly an additional KBuild file, and of course C source and header files. This header file Read more…

systemd udev Rules to Detect USB Device Plugging (including Bus and Device Number)

The other day, I was working on some udev rules to invoke a script when a USB device is added or removed from my machine. I needed the USB bus and USB port number to further process that event. I decided to use udev for that. However, getting the relevant attributes was not as intuitive as I expected, and existing documentation wasn’t that good. Here’s what I did and how I solved it. Read more…

Screenshot: Nix build: "illegal path referenced in fixed-output derivation". The part on the top shows all Nix store paths that accidentally landed in the derivation (obtained by "grep")

Fixing “Illegal path references in fixed-output derivation” in Nix

The other day I was working with fixed-output derivations. After copying several files to $out, I was facing a “Illegal path references in fixed-output derivation error”. The only helpful reference on the internet I could find was the Nix source code on GitHub. It took me a while to figure out what’s going on. You get this error when your fixed-output derivation places something in $out which contains a Nix store path! This Read more…

Accessing Network from a Nix Derivation (via Fixed output derivations)

Usually, Nix derivations are build in a sandbox that prevent any program from accessing the network. This has a good reason: We want reproducibility in Nix, and using the network is not reproducible for many reasons! But there must be a way of accessing the network from a derivation, right? Why? Because, builtins.fetchGit or builtins.fetchTarball are not flexible enough to cope with the nature of Maven, Cargo, npm or other tools that download Read more…

Code Snippet: Fixed output derivation in Nix

How to use `gcc_multi` with a specific GCC version in nixpkgs?

I recently came across the problem that pkgs.gcc_multi comes with gcc in version 12 but I needed version 11. While nixpkgs exports gcc in multiple versions (pkgs.gcc, pkgs.gcc11, pkgs.gcc12, pkgs.gcc13), pkgs.gcc_multi is only exported once, backed with the version coming from pkgs.gcc. However, using another, specific gcc version is fairly simple. In <nixpkgs at NixOS 23.11>/pkgs/top-level/all-packages.nix we can find gcc_multi. This is aliased to pkgs.wrapCCMulti gcc (function call), which is defined in the Read more…

Introducing PhipsBoot – My x86 Relocatable Bootloader

Today, I’d like to introduce you to PhipsBoot. 🎉 I started working on it in September 2023 or so, but polished it just recently. A lot of knowledge from my previous blog post about x86 Kernel Development & Relocatable Binaries went into this project. PhipsBoot is a relocatable x86_64 bootloader written in Rust and assembly that loads a kernel into 64-bit mode. It abstracts a lot of boot-related x86_64 complexity away. It is Read more…

Screenshot: PhipsBoot Output