diff --git a/content/posts/hydra-ci-images.md b/content/posts/hydra-ci-images.md new file mode 100644 index 0000000..6dcf279 --- /dev/null +++ b/content/posts/hydra-ci-images.md @@ -0,0 +1,92 @@ ++++ +title = "Using Hydra to build custom images" +date = 2025-07-31 +draft = false + +[taxonomies] +categories = [ "nixos" ] +tags = [ "nixos", "nixos-server", "nixos-25.05", "hydra", "custom-images"] ++++ + +# Building custom images + +You can build images with either the legacy (non-flake) and flake method, there are a few great resources such as [nix.dev](https://nix.dev/tutorials/nixos/building-bootable-iso-image) and [NixOS Wiki](https://nixos.wiki/wiki/Creating_a_NixOS_live_CD). For example if we wanted a minimal (CLI only) ISO for x86_64 with helix and git we can do that here: + +```nix,linenos +{ + description = "Minimal NixOS installation media"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + outputs = { self, nixpkgs }: { + nixosConfigurations = { + exampleIso = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ({ pkgs, modulesPath, ... }: { + imports = [ (modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix") ]; + environment.systemPackages with pkgs; = [ helix git ]; + }) + ]; + }; + }; + }; +} +``` + +We would build the image like this using flakes: + +```nix,linenos +git init +git add flake.nix +nix build .#nixosConfigurations.exampleIso.config.system.build.images.iso +``` + +I started my own [nixos live disk repository](https://gitlab.com/ahoneybun-nix/nixos-live-disk) recently for building images for my Pi 4, Pi 5 and x86_64 minimal CLI versions. + +If we want to build an image for aarch64-linux with the graphical installer for GNOME with the latest kernel, hostname set and helix. + +```nix,linenos +{ + description = "Minimal NixOS installation media"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + outputs = {self, nixpkgs }: { + nixosConfigurations = { + drack = nixpkgs.lib.nixosSystem { + system = "aarch64-linux"; + modules = [ + ({ pkgs, lib, modulesPath, ... }: { + imports = [ "${modulesPath}/installer/cd-dvd/installation-cd-graphical-calamares-gnome.nix" ]; + boot.kernelPackages = pkgs.linuxPackages_latest; + boot.supportedFilesystems = lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" ]; + environment.systemPackages = with pkgs; [ helix ]; + networking.hostName = "drack"; + services.openssh.enable = true; + system.stateVersion = "25.05"; + }) + ]; + }; + }; + }; +} +``` + +# Having Hydra get a job + +With the following in the flake we can have Hydra start building the images: + +```nix,linenos + hydraJobs = { + images = { + vetra = self.nixosConfigurations.vetra.config.system.build.sdImage; + sidera = self.nixosConfigurations.sidera.config.system.build.sdImage; + drack = self.nixosConfigurations.drack.config.system.build.isoImage; + test-gui = self.nixosConfigurations.test-gui.config.system.build.isoImage; + test-cli = self.nixosConfigurations.test-cli.config.system.build.isoImage; + }; + }; +``` + +{{ figure(src="/images/hydra-ci-images/hydra-custom-images.png", alt="Hydra building images for different architectures", caption="Hydra building images for different architectures") }} + +# Other questions + +Reach out to me on Mastodon for questions! diff --git a/static/images/hydra-ci-images/hydra-custom-images.png b/static/images/hydra-ci-images/hydra-custom-images.png new file mode 100644 index 0000000..9105d84 Binary files /dev/null and b/static/images/hydra-ci-images/hydra-custom-images.png differ