From 1326f654cc1d5fcf7aa40e70aceace2808a78718 Mon Sep 17 00:00:00 2001 From: Stefan Junker Date: Mon, 8 Apr 2024 15:55:03 +0000 Subject: [PATCH] feat(tfgrid): split into base and devnet-vm0 profiles and install kernel/initrd to rootfs --- .../configuration.nix | 34 +++++++++++++++++++ .../default.nix | 14 ++++++++ .../configuration.nix | 23 +------------ modules/flake-parts/packages.zos-utils.nix | 2 +- .../flake-parts/tfgrid-microvm/default.nix | 20 ++++++++--- .../tfgrid-microvm/mk-zos-vm-dir.nix | 5 ++- 6 files changed, 67 insertions(+), 31 deletions(-) create mode 100644 modules/flake-parts/nixosConfigurations.tfgrid-base/configuration.nix create mode 100644 modules/flake-parts/nixosConfigurations.tfgrid-base/default.nix diff --git a/modules/flake-parts/nixosConfigurations.tfgrid-base/configuration.nix b/modules/flake-parts/nixosConfigurations.tfgrid-base/configuration.nix new file mode 100644 index 00000000..aec7c11d --- /dev/null +++ b/modules/flake-parts/nixosConfigurations.tfgrid-base/configuration.nix @@ -0,0 +1,34 @@ +{ + config, + inputs, + self, + pkgs, + ... +}: let + hostName = "tfgrid-base"; +in { + imports = [ + inputs.srvos.nixosModules.server + inputs.srvos.nixosModules.mixins-terminfo + + self.nixosModules.holo-users + ../../nixos/shared.nix + ../../nixos/shared-nix-settings.nix + + self.nixosModules.zosVmDir + ]; + + networking.hostName = hostName; + + nix.settings.max-jobs = 8; + + nix.settings.substituters = [ + "https://holochain-ci.cachix.org" + ]; + + nix.settings.trusted-public-keys = [ + "holochain-ci.cachix.org-1:5IUSkZc0aoRS53rfkvH9Kid40NpyjwCMCzwRTXy+QN8=" + ]; + + system.stateVersion = "23.11"; +} diff --git a/modules/flake-parts/nixosConfigurations.tfgrid-base/default.nix b/modules/flake-parts/nixosConfigurations.tfgrid-base/default.nix new file mode 100644 index 00000000..5d246e75 --- /dev/null +++ b/modules/flake-parts/nixosConfigurations.tfgrid-base/default.nix @@ -0,0 +1,14 @@ +{ + self, + lib, + inputs, + ... +}: { + flake.nixosConfigurations.tfgrid-base = inputs.nixpkgs.lib.nixosSystem { + modules = [ + ./configuration.nix + ]; + system = "x86_64-linux"; + specialArgs = self.specialArgs; + }; +} diff --git a/modules/flake-parts/nixosConfigurations.tfgrid-devnet-vm0/configuration.nix b/modules/flake-parts/nixosConfigurations.tfgrid-devnet-vm0/configuration.nix index 774890cd..8a47458e 100644 --- a/modules/flake-parts/nixosConfigurations.tfgrid-devnet-vm0/configuration.nix +++ b/modules/flake-parts/nixosConfigurations.tfgrid-devnet-vm0/configuration.nix @@ -8,17 +8,10 @@ hostName = "tfgrid-devnet-vm0"; in { imports = [ - inputs.srvos.nixosModules.server - inputs.srvos.nixosModules.mixins-terminfo + ../../nixosConfigurations.tfgrid-base/configuration.nix inputs.sops-nix.nixosModules.sops - self.nixosModules.holo-users - ../../nixos/shared.nix - ../../nixos/shared-nix-settings.nix - - self.nixosModules.zosVmDir - self.nixosModules.nomad-client ]; @@ -33,18 +26,4 @@ in { }; networking.hostName = hostName; - - hostName = "TODO"; - - nix.settings.max-jobs = 8; - - nix.settings.substituters = [ - "https://holochain-ci.cachix.org" - ]; - - nix.settings.trusted-public-keys = [ - "holochain-ci.cachix.org-1:5IUSkZc0aoRS53rfkvH9Kid40NpyjwCMCzwRTXy+QN8=" - ]; - - system.stateVersion = "23.11"; } diff --git a/modules/flake-parts/packages.zos-utils.nix b/modules/flake-parts/packages.zos-utils.nix index 2e0a8e69..81b12d7a 100644 --- a/modules/flake-parts/packages.zos-utils.nix +++ b/modules/flake-parts/packages.zos-utils.nix @@ -9,7 +9,7 @@ ... }: { packages = let - configName = "tfgrid-devnet-vm0"; + configName = "tfgrid-base"; in { zos-vm-build = pkgs.writeShellApplication { diff --git a/modules/flake-parts/tfgrid-microvm/default.nix b/modules/flake-parts/tfgrid-microvm/default.nix index 85d3958e..a0a83a2f 100644 --- a/modules/flake-parts/tfgrid-microvm/default.nix +++ b/modules/flake-parts/tfgrid-microvm/default.nix @@ -1,7 +1,5 @@ # TODO: make sure new kernels/initrds also get copied to `/boot/vmlinuz` and `/boot/initrd.mg` -{self, ...}: let - mkZosVmDir = import ./mk-zos-vm-dir.nix; -in { +{self, ...}: { flake.nixosModules = { zosVmDir = { config, @@ -9,14 +7,22 @@ in { modulesPath, pkgs, ... - }: { + }: let + mkZosVmDir = import ./mk-zos-vm-dir.nix; + + bootFiles = pkgs.runCommandNoCC "bootfiles" {} '' + mkdir $out + ${pkgs.gcc}/bin/strip ${config.system.build.kernel.dev}/vmlinux -o $out/vmlinuz + cp ${config.system.build.initialRamdisk}/initrd $out/initrd.img + ''; + in { imports = [ (modulesPath + "/profiles/qemu-guest.nix") self.nixosModules.zosVmDirOverlayAutodetect ]; # can be built with # nix build -v .\#nixosConfigurations..config.system.build.zosVmDir - system.build.zosVmDir = mkZosVmDir {inherit self pkgs config;}; + system.build.zosVmDir = mkZosVmDir {inherit self pkgs config bootFiles;}; fileSystems."/" = { device = "vroot"; @@ -37,9 +43,13 @@ in { boot.loader.external.enable = true; + boot.kernelPackages = pkgs.linuxPackages_latest; + # the first argument points to the new system's toplevel, which is equivalent to config.system.build.toplevel boot.loader.external.installHook = pkgs.writeShellScript "noop" '' ${pkgs.coreutils}/bin/ln -sf "$1"/init /init + ${pkgs.coreutils}/bin/ln -sf ${bootFiles}/vmlinuz /boot/vmlinuz + ${pkgs.coreutils}/bin/ln -sf ${bootFiles}/initrd.img /boot/initrd.img ''; services.cloud-init.enable = true; diff --git a/modules/flake-parts/tfgrid-microvm/mk-zos-vm-dir.nix b/modules/flake-parts/tfgrid-microvm/mk-zos-vm-dir.nix index 510ace24..39424c97 100644 --- a/modules/flake-parts/tfgrid-microvm/mk-zos-vm-dir.nix +++ b/modules/flake-parts/tfgrid-microvm/mk-zos-vm-dir.nix @@ -2,6 +2,7 @@ self, config, pkgs, + bootFiles, }: let pkgs2storeContents = map (x: { object = x; @@ -16,10 +17,9 @@ in source = let cmd = pkgs.runCommandNoCC "rootfs" {} '' mkdir -p $out/boot + cp -r ${bootFiles}/* $out/boot/ ln -s ${config.system.build.toplevel}/init $out/init - ${pkgs.gcc}/bin/strip ${config.system.build.kernel.dev}/vmlinux -o $out/boot/vmlinuz - cp ${config.system.build.initialRamdisk}/initrd $out/boot/initrd.img ''; in "${cmd}/."; target = "./"; @@ -31,7 +31,6 @@ in config.system.build.toplevel pkgs.stdenvNoCC - # TODO: find out why `systemctl reboot dbus` is needed to make `nixos-rebuild` work # these are also needed on the target for nixos-rebuild to work # pkgs.path