Overriding Flakes Inputs in Hydra
I’ve been using NixOS for over 10 years now. I run NixOS on all of my servers, desktops and laptops - but also weird things like game consoles, e-book readers and mobile phones. Since I have a reasonable amount of personal Nix code, it’s important I have continuous integration configured for my various systems.
So I run a few Hydra servers with that goal. Hydra supports periodically fetching different inputs then building - but not for Nix Flakes! When using Flakes, the inputs can only come from the flake.lock
file. This means that you can’t say “build this Flake every 24 hours with the latest nixpkgs” - i.e. if you give Hydra a Flake, it’s always going to build the same thing.
It would be ideal if Hydra fully understood Nix Flakes and was able to override inputs. Instead, I’ve hacked up a workaround which I’ve been using for a year now, so I should document it here.
The idea is:
- Hydra supports supplying updated inputs to “legacy” (non-flake) Nix expressions
- flake-compat implements Flakes using “legacy” Nix
We should be able to just combine those two things and have a daily build of our Flake code. Sadly, flake-compat also doesn’t support overriding inputs. Luckily, after deleting some legacy code which I personally didn’t need in my fork, the change was super simple:
@@ -5,7 +5,10 @@
# containing 'defaultNix' (to be used in 'default.nix'), 'shellNix'
# (to be used in 'shell.nix').
-{ src, system ? builtins.currentSystem or "unknown-system" }:
+{ src
+, system ? builtins.currentSystem or "unknown-system"
+, nodeOverrides ? {}
+}:
let
@@ -199,7 +202,7 @@ let
else
sourceInfo
)- lockFile.nodes;
+ lockFile.nodes // nodeOverrides;
result = if !(builtins.pathExists lockFilePath)
Which makes it possible to write a plain Nix expression which takes the inputs from Hydra and passes them into the existing Flake code.
{ nixpkgs
, jovian-nixos
, flake-compat
}:
let
flake = src:
(import flake-compat {
inherit src;
nodeOverrides = {
nixpkgs = flake nixpkgs;
jovian-nixos = flake jovian-nixos;
};
}).result;
in
(flake ../.).outputs.hydraJobs;
Which we can configure in Hydra:
And there we go. I have daily builds for each of my NixOS systems. When something changes in nixpkgs and breaks a system, I am notified and can fix it.