Skip to content

Commit

Permalink
feat(tfgrid): split into base and devnet-vm0 profiles and install ker…
Browse files Browse the repository at this point in the history
…nel/initrd to rootfs
  • Loading branch information
steveej committed Apr 8, 2024
1 parent ccbcd17 commit 1326f65
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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";
}
14 changes: 14 additions & 0 deletions modules/flake-parts/nixosConfigurations.tfgrid-base/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
];

Expand All @@ -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";
}
2 changes: 1 addition & 1 deletion modules/flake-parts/packages.zos-utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
...
}: {
packages = let
configName = "tfgrid-devnet-vm0";
configName = "tfgrid-base";
in
{
zos-vm-build = pkgs.writeShellApplication {
Expand Down
20 changes: 15 additions & 5 deletions modules/flake-parts/tfgrid-microvm/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
# 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,
lib,
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.<name>.config.system.build.zosVmDir
system.build.zosVmDir = mkZosVmDir {inherit self pkgs config;};
system.build.zosVmDir = mkZosVmDir {inherit self pkgs config bootFiles;};

fileSystems."/" = {
device = "vroot";
Expand All @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions modules/flake-parts/tfgrid-microvm/mk-zos-vm-dir.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
self,
config,
pkgs,
bootFiles,
}: let
pkgs2storeContents = map (x: {
object = x;
Expand All @@ -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 = "./";
Expand All @@ -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
Expand Down

0 comments on commit 1326f65

Please sign in to comment.