dynix/tests/default.nix
2026-03-05 15:45:36 +01:00

81 lines
2.9 KiB
Nix

{
pkgs ? import <nixpkgs> { },
qpkgs ? let
src = fetchTarball "https://github.com/Qyriad/nur-packages/archive/main.tar.gz";
in import src { inherit pkgs; },
callPackage ? qpkgs.callPackage,
lib ? qpkgs.lib,
dynix ? qpkgs.callPackage ../package.nix { },
}: let
mkDynixConfigurationDotNix = callPackage ./mk-test-configuration-dot-nix.nix { };
runDynixTest = testModule: pkgs.testers.runNixOSTest {
imports = [ testModule ];
# NOTE: these are arguments to each *test module*.
# Not the NixOS modules of the test's nodes.
_module.args = { inherit mkDynixConfigurationDotNix; };
# Why is this argument called "extraBaseModule**s**" but take a single module argument...
# Also note this is an extra base module for each node of the test,
# not an extra test module.
extraBaseModules = { name, config, options, modulesPath, ... }: {
/**
* Everything in this module will disappear once nixos-rebuild switch happens.
* So each test will need to use `mkDynixConfigurationDotNix` to get
* ./dynix-vm-configuration included in the in-VM configuration.
*/
imports = (import "${modulesPath}/module-list.nix") ++ [
# For the VM node, but not the in-VM configuration.nix
./module-allow-rebuild-in-vm.nix
# For the VM node, and the in-VM configuration.nix
./dynix-vm-configuration.nix
# NOTE: if `dynix` is a package (which it usually is), then
# this is IFD.
dynix.dynix
];
systemd.services."install-dynix" = {
enable = true;
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;
path = [ config.system.path ];
wantedBy = [ "multi-user.target" ];
requiredBy = [ "multi-user.target" ];
after = [ "default.target" ];
script = ''
if [[ -e /etc/nixos/hardware-configuration.nix ]]; then
echo "install-dynix: configuration already copied; nothing to do"
exit 0
fi
nix profile install -vv "${dynix.drvPath}^*" # "
mkdir -vp /etc/nixos
nixos-generate-config
cp -rv --dereference /run/current-system/sw/share/nixos/*.nix /etc/nixos/
if ! [[ -e /etc/nixos/dynix-vm-configuration.nix ]]; then
echo "FAILURE"
echo "FAILURE" >&2
fi
'';
};
passthru = { inherit options; };
environment.systemPackages = [ config.passthru.configurationDotNix ];
# Just making something in this strict in `name`,
# which is only present as an argument for nodes and I don't want to
# confuse that with the test modules.
warnings = builtins.seq name [ ];
};
};
in lib.makeScope lib.callPackageWith (self: {
gotosocial = runDynixTest ./gotosocial/test.nix;
harmonia = runDynixTest ./harmonia/test.nix;
distccd = runDynixTest ./distccd/test.nix;
})