dynix/tests/default.nix

86 lines
3 KiB
Nix
Raw Normal View History

# SPDX-FileCopyrightText: 2026 Qyriad <qyriad@qyriad.me>
#
# SPDX-License-Identifier: EUPL-1.1
2026-02-06 17:12:02 +01:00
{
pkgs ? import <nixpkgs> { },
2026-02-09 14:32:56 +01:00
qpkgs ? let
2026-02-18 14:01:39 +01:00
src = fetchTarball "https://github.com/Qyriad/nur-packages/archive/main.tar.gz";
2026-02-09 14:32:56 +01:00
in import src { inherit pkgs; },
2026-02-11 13:19:59 +01:00
callPackage ? qpkgs.callPackage,
2026-02-09 14:32:56 +01:00
lib ? qpkgs.lib,
2026-02-11 13:16:54 +01:00
dynix ? qpkgs.callPackage ../package.nix { },
2026-02-09 14:32:56 +01:00
}: let
2026-02-11 13:19:59 +01:00
mkDynixConfigurationDotNix = callPackage ./mk-test-configuration-dot-nix.nix { };
2026-02-09 14:32:56 +01:00
runDynixTest = testModule: pkgs.testers.runNixOSTest {
imports = [ testModule ];
2026-02-11 13:19:59 +01:00
# NOTE: these are arguments to each *test module*.
# Not the NixOS modules of the test's nodes.
_module.args = { inherit mkDynixConfigurationDotNix; };
2026-02-09 14:32:56 +01:00
# Why is this argument called "extraBaseModule**s**" but take a single module argument...
2026-02-10 14:59:44 +01:00
# Also note this is an extra base module for each node of the test,
# not an extra test module.
extraBaseModules = { name, config, options, modulesPath, ... }: {
2026-02-11 13:19:59 +01:00
/**
* 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.
*/
2026-02-10 14:59:44 +01:00
imports = (import "${modulesPath}/module-list.nix") ++ [
2026-02-13 17:19:54 +01:00
# For the VM node, but not the in-VM configuration.nix
2026-02-10 14:59:44 +01:00
./module-allow-rebuild-in-vm.nix
2026-02-13 17:19:54 +01:00
# For the VM node, and the in-VM configuration.nix
2026-02-11 13:19:59 +01:00
./dynix-vm-configuration.nix
2026-03-05 15:44:58 +01:00
# NOTE: if `dynix` is a package (which it usually is), then
# this is IFD.
2026-02-16 18:02:39 +01:00
dynix.dynix
2026-02-10 14:59:44 +01:00
];
systemd.services."install-dynix" = {
enable = true;
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;
path = [ config.system.path ];
wantedBy = [ "multi-user.target" ];
2026-02-16 18:02:39 +01:00
requiredBy = [ "multi-user.target" ];
2026-02-10 14:59:44 +01:00
after = [ "default.target" ];
script = ''
2026-02-16 18:02:39 +01:00
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}^*" # "
2026-02-11 13:19:59 +01:00
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
2026-02-10 14:59:44 +01:00
'';
};
passthru = { inherit options; };
2026-02-16 18:02:39 +01:00
environment.systemPackages = [ config.passthru.configurationDotNix ];
2026-02-09 14:32:56 +01:00
# 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.
2026-02-10 14:59:44 +01:00
warnings = builtins.seq name [ ];
2026-02-09 14:32:56 +01:00
};
};
in lib.makeScope lib.callPackageWith (self: {
2026-02-10 14:19:55 +01:00
gotosocial = runDynixTest ./gotosocial/test.nix;
2026-02-10 14:59:44 +01:00
harmonia = runDynixTest ./harmonia/test.nix;
2026-02-13 21:12:55 +01:00
distccd = runDynixTest ./distccd/test.nix;
2026-02-06 17:12:02 +01:00
})