Welcome to Hydra
CB (Continuous Build system)
This is what NixOS itself uses for building packages for it's channels. Setting it up yourself on NixOS is pretty easy with this nix config:
1 { config, pkgs, lib, ... }:
2
3 {
4 services.hydra = {
5 enable = true;
6 hydraURL = "localhost:3000";
7 buildMachinesFiles = [ ];
8 notificationSender = "hydra@localhost";
9 useSubstitutes = true;
10 };
11 }
once you add that to your configuration.nix
(or another nix file that you import) and rebuild you'll find it running on port 3000 (localhost:3000). For creating a project and other admin roles I would recommand looking at this page.
Your own nixpkgs
I started my own nixpkgs repository recently and this is my flake:
1 {
2 description = "Aaron Honeycutt's packages";
3
4 inputs = {
5 nixpkgs.url = "nixpkgs/nixos-unstable";
6 flake-utils.url = "github:numtide/flake-utils";
7 };
8
9 outputs = {
10 self,
11 nixpkgs,
12 flake-utils,
13 ...
14 }:
15 flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux"] (
16 system: let
17 pkgs = import nixpkgs {
18 inherit system;
19 config.allowUnfree = true;
20 overlays = [
21 (import ./pkgs)
22 ];
23 };
24
25 in {
26 packages = (import ./pkgs {}) pkgs;
27
28 hydraJobs = (import ./pkgs {}) pkgs;
29 }
30 );
31 }
With this you can run nix build .#honeyfetch
(one of the packages in that repository) to build it for the host architecture. Now the part for Hydra itself is HydraJobs
so that Hydra will pick up those packages and build them:
Building for other architectures
NixOS is great at supporting 4 main architectures (known as Platforms):
- x86_64-linux
- aarch64-linux
- x86_64-darwin
- aarch64-darwin
there is a 5th one which is i686-linux though it is not as common.
Hydra can build for all of them and this example we'll add aarch64-linux (for devices such as the Raspberry Pi in my case), this is how our Hydra configuration looks with that enabled:
1 { config, pkgs, lib, ... }:
2
3 {
4 services.hydra = {
5 enable = true;
6 hydraURL = "localhost:3000";
7 buildMachinesFiles = [ "/etc/nix/machines" ];
8 notificationSender = "hydra@localhost";
9 useSubstitutes = true;
10 };
11
12 nix.buildMachines = [
13 {
14 hostName = "localhost";
15 protocol = null;
16 # system = "x86_64-linux";
17 systems = [ "x86_64-linux" "aarch64-linux" ];
18 supportedFeatures = ["kvm" "nixos-test" "big-parallel" "benchmark"];
19 maxJobs = 8;
20 }
21 ];
22 }
If you just want to build for x86_64-linux or a certain Platform only you can use the system
variable instead of the systems
one. If you use both the system
one will override everything so only that one will be used. Once the change is made simply rebuild your configuration with sudo nixos-rebuild
and you should see this, it is important to note that building on a non-native Platform will take a while.
Other questions
For more reading I have my nix files hosted on GitLab here. Reach out to my on Mastodon for questions!