Skip to content

Commit

Permalink
add test-vm
Browse files Browse the repository at this point in the history
  • Loading branch information
marenz2569 committed Nov 22, 2023
1 parent 5498d6e commit 7094415
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
result
.direnv
nixos.qcow2
50 changes: 48 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,33 @@
rustc = toolchain;
}).buildPackage;
};

test-vm-pkg = self.nixosConfigurations.lizard-mctest.config.system.build.vm;
in
rec {
checks = packages;
packages = {
lizard = package;
test-vm = test-vm-pkg;
test-vm-wrapper = pkgs.writeScript "trekkie-test-vm-wrapper"
''
set -e
echo Trekkie-McTest: enterprise-grade, free-range, grass fed testing vm
echo
echo "ALL RELEVANT SERVICES WILL BE EXPOSED TO THE HOST:"
echo -e "Service\t\tPort"
echo -e "SSH:\t\t2222\troot:lol"
echo -e "lizard:\t8060"
echo -e "redis:\t\t8061"
echo
set -x
export QEMU_NET_OPTS="hostfwd=tcp::2222-:22,hostfwd=tcp::8060-:8060,hostfwd=tcp::8061-:6379"
echo "running the vm now..."
${self.packages.${system}.test-vm}/bin/run-nixos-vm
'';
default = package;
docs = (pkgs.nixosOptionsDoc {
options = (nixpkgs.lib.nixosSystem {
Expand All @@ -47,6 +69,14 @@
}).optionsCommonMark;
};

# to get yourself a virtualized testing playground:
# nix run .\#mctest
apps = {
mctest = {
type = "app";
program = "${self.packages.${system}.test-vm-wrapper}";
};
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = (with packages.lizard; nativeBuildInputs ++ buildInputs);
};
Expand All @@ -57,12 +87,28 @@
};
}) // {
nixosModules = rec {
default = funnel;
funnel = import ./nixos-module;
default = lizard;
lizard = import ./nixos-module;
};
overlays.default = final: prev: {
inherit (self.packages.${prev.system})
lizard;
};

# qemu vm for testing
nixosConfigurations.lizard-mctest = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
self.nixosModules.default
./tests/vm

{
nixpkgs.overlays = [
self.overlays.default
];
}
];
};
};
}
55 changes: 55 additions & 0 deletions tests/vm/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# add-hoc config for a test VM.
{ inputs, modulesPath, ... }:
{
imports = [
"${modulesPath}/virtualisation/qemu-vm.nix"
./lizard.nix
];

fileSystems = {
"/" = {
device = "/dev/disk/by-label/nixos";
fsType = "ext4";
};
};

boot = {
kernelParams = [ "console=ttyS0" "boot.shell_on_fail" ];
loader.timeout = 5;
};

virtualisation = {
diskSize = 512;
memorySize = 512;
graphics = false;
};

services.getty = {
autologinUser = "root";
};
users.motd = ''
Trekkie-McTest: enterprise-grade, free-range, grass-fed testing vm
Now with 100% less graphics!
Services exposed to the host:
lizard: 8060
SSH: 2222
redis: 8061
root password is "lol"
have fun!
'';


networking.firewall.enable = false;

users.mutableUsers = false;
users.users.root.password = "lol";
services.openssh = {
enable = true;
permitRootLogin = "yes";
};

system.stateVersion = "22.11";
}
29 changes: 29 additions & 0 deletions tests/vm/lizard.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ config, inputs, ... }:
{
TLMS.lizard = {
# Unlike the production, we do not reverse-proxy the lizard, we just expose
# port directly to the host vm.
enable = true;
http = {
host = "0.0.0.0";
port = 8060;
};
redis = {
port = 6379;
host = "localhost";
};
logLevel = "info";
};
systemd.services."lizard" = {
after = [ "redis-lizard.service" ];
wants = [ "redis-lizard.service" ];
};

services = {
redis.servers."lizard" = {
enable = true;
bind = config.TLMS.lizard.redis.host;
port = config.TLMS.lizard.redis.port;
};
};
}

0 comments on commit 7094415

Please sign in to comment.