forked from DGNum/liminix
feat(ci): base for VMs for better testing
This commit is contained in:
parent
013e4c396c
commit
ca41e04e7d
4 changed files with 140 additions and 0 deletions
4
.forgejo/ci-files/border.nix
Normal file
4
.forgejo/ci-files/border.nix
Normal file
|
@ -0,0 +1,4 @@
|
|||
{ lib, pkgs, ... }:
|
||||
{
|
||||
networking.hostName = "border-vm";
|
||||
}
|
4
.forgejo/ci-files/client.nix
Normal file
4
.forgejo/ci-files/client.nix
Normal file
|
@ -0,0 +1,4 @@
|
|||
{ lib, pkgs, ... }:
|
||||
{
|
||||
networking.hostName = "client-vm";
|
||||
}
|
40
.forgejo/ci-files/default.nix
Normal file
40
.forgejo/ci-files/default.nix
Normal file
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
pkgs ? (import <nixpkgs> { }),
|
||||
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
|
||||
{ }
|
92
.forgejo/ci-files/vm-base.nix
Normal file
92
.forgejo/ci-files/vm-base.nix
Normal file
|
@ -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";
|
||||
}
|
Loading…
Reference in a new issue