diff --git a/.forgejo/ci-files/border.nix b/.forgejo/ci-files/border.nix new file mode 100644 index 0000000..5521c96 --- /dev/null +++ b/.forgejo/ci-files/border.nix @@ -0,0 +1,4 @@ +{ lib, pkgs, ... }: +{ + networking.hostName = "border-vm"; +} diff --git a/.forgejo/ci-files/client.nix b/.forgejo/ci-files/client.nix new file mode 100644 index 0000000..a17faa6 --- /dev/null +++ b/.forgejo/ci-files/client.nix @@ -0,0 +1,4 @@ +{ lib, pkgs, ... }: +{ + networking.hostName = "client-vm"; +} diff --git a/.forgejo/ci-files/default.nix b/.forgejo/ci-files/default.nix new file mode 100644 index 0000000..04cbc6b --- /dev/null +++ b/.forgejo/ci-files/default.nix @@ -0,0 +1,40 @@ +{ + pkgs ? (import { }), + lib ? pkgs.lib, +}: +let + base-cmd = vm: '' + ${pkgs.qemu}/bin/qemu-system-x86_64 -m 4G \ + -kernel ${vm.kernel}/bzImage \ + -initrd ${vm.ramdisk}/initrd \ + -append "init=${vm.toplevel}/init loglevel=4 console=ttyS0" \ + -display none -serial mon:stdio + ''; + + border-vm = + (import (pkgs.path + "/nixos/lib/eval-config.nix") { + system = "x86_64-linux"; + modules = [ + ./border.nix + ./vm-base.nix + ]; + }).config.system.build; + + client-vm = + (import (pkgs.path + "/nixos/lib/eval-config.nix") { + system = "x86_64-linux"; + modules = [ + ./client.nix + ./vm-base.nix + ]; + }).config.system.build; + + border-launch = pkgs.writeShellScript "lauch-border" '' + ${base-cmd border-vm} + ''; + + client-launch = pkgs.writeShellScript "lauch-client" '' + ${base-cmd client-vm} + ''; +in +{ } diff --git a/.forgejo/ci-files/vm-base.nix b/.forgejo/ci-files/vm-base.nix new file mode 100644 index 0000000..9886c1f --- /dev/null +++ b/.forgejo/ci-files/vm-base.nix @@ -0,0 +1,92 @@ +{ + config, + lib, + pkgs, + ... +}: +let + sqshStore = pkgs.callPackage (pkgs.path + /nixos/lib/make-squashfs.nix) { + storeContents = [ + config.system.build.toplevel + ]; + comp = null; # no time for this + }; +in +{ + system.build.ramdisk = pkgs.makeInitrdNG { + inherit (config.boot.initrd) compressor; + prepend = [ "${config.system.build.initialRamdisk}/initrd" ]; + + contents = [ + { + source = sqshStore; + target = "/nix-store.squashfs"; + } + ]; + }; + + fileSystems = { + "/" = { + fsType = "tmpfs"; + options = [ "mode=0755" ]; + }; + + "/nix/.ro-store" = { + fsType = "squashfs"; + device = "../nix-store.squashfs"; + options = [ "loop" ]; + neededForBoot = true; + }; + + "/nix/.rw-store" = { + fsType = "tmpfs"; + options = [ "mode=0755" ]; + neededForBoot = true; + }; + + "/nix/store" = { + overlay = { + lowerdir = [ "/nix/.ro-store" ]; + upperdir = "/nix/.rw-store/store"; + workdir = "/nix/.rw-store/work"; + }; + neededForBoot = true; + }; + }; + + boot = { + loader.grub.enable = false; + initrd = { + availableKernelModules = [ + "squashfs" + "overlay" + ]; + + kernelModules = [ + "loop" + "overlay" + ]; + }; + postBootCommands = '' + # After booting, register the contents of the Nix store + # in the Nix database in the tmpfs. + ${config.nix.package}/bin/nix-store --load-db < /nix/store/nix-path-registration + ''; + }; + + services = { + getty.autologinUser = lib.mkForce "root"; + openssh.enable = true; + qemuGuest.enable = true; + }; + nix = { + nixPath = [ + "nixpkgs=${builtins.storePath pkgs.path}" + "nixos=${builtins.storePath pkgs.path}" + ]; + channel.enable = false; + settings.nix-path = config.nix.nixPath; + package = pkgs.lix; + }; + console.keyMap = "fr"; +}