tests/vmTest: fix and de-duplicate code

Ironically, I did not properly test that I had made the local and remote
tests distinct. So the exampleFlake was hardcoded to 'local' only.  This
meant that building local and remote tests would return the same
results. This commit fixes that. Additionally, I've made
tests/vmTests/common.nix to deduplicate some of the code between nodes.
This commit is contained in:
matthewcroughan 2022-05-24 02:39:45 +01:00
parent 783dcfbb9e
commit 3e9dddd88b
2 changed files with 88 additions and 75 deletions

14
tests/vmTest/common.nix Normal file
View file

@ -0,0 +1,14 @@
# Configuration that will be added to both the nixinatee node and the nixinator
# node.
{ inputs }:
{
nix = {
extraOptions =
let empty_registry = builtins.toFile "empty-flake-registry.json" ''{"flakes":[],"version":2}''; in
''
experimental-features = nix-command flakes
flake-registry = ${empty_registry}
'';
registry.nixpkgs.flake = inputs.nixpkgs;
};
}

View file

@ -22,6 +22,8 @@ let
((import (path + "/flake.nix")).outputs (inputs // {self = r;})); ((import (path + "/flake.nix")).outputs (inputs // {self = r;}));
in in
r; r;
mkNixinateTest = buildOn:
let
exampleFlake = pkgs.writeTextFile { exampleFlake = pkgs.writeTextFile {
name = "nixinate-example-flake"; name = "nixinate-example-flake";
destination = "/flake.nix"; destination = "/flake.nix";
@ -38,7 +40,7 @@ let
_module.args.nixinate = { _module.args.nixinate = {
host = "nixinatee"; host = "nixinatee";
sshUser = "nixinator"; sshUser = "nixinator";
buildOn = "local"; # valid args are "local" or "remote" buildOn = "${buildOn}"; # valid args are "local" or "remote"
}; };
} }
]; ];
@ -54,32 +56,29 @@ let
}; };
deployScript = inputs.self.nixinate.${pkgs.hostPlatform.system} (callLocklessFlake "${exampleFlake}" { nixpkgs = inputs.nixpkgs; }); deployScript = inputs.self.nixinate.${pkgs.hostPlatform.system} (callLocklessFlake "${exampleFlake}" { nixpkgs = inputs.nixpkgs; });
exampleSystem = (callLocklessFlake "${exampleFlake}" { nixpkgs = inputs.nixpkgs; }).nixosConfigurations.nixinatee.config.system.build.toplevel; exampleSystem = (callLocklessFlake "${exampleFlake}" { nixpkgs = inputs.nixpkgs; }).nixosConfigurations.nixinatee.config.system.build.toplevel;
mkNixinateTest = buildOn: makeTest { in
makeTest {
nodes = { nodes = {
nixinatee = { ... }: { nixinatee = { ... }: {
imports = [ imports = [
./nixinateeBase.nix ./nixinateeBase.nix
(import ./common.nix { inherit inputs; })
]; ];
virtualisation = { virtualisation = {
writableStore = true; writableStore = true;
additionalPaths = [] ++ pkgs.lib.optional (buildOn == "remote") (allDrvOutputs exampleSystem);
}; };
}; };
nixinator = { ... }: { nixinator = { ... }: {
imports = [
(import ./common.nix { inherit inputs; })
];
virtualisation = { virtualisation = {
additionalPaths = [ additionalPaths = [
(allDrvOutputs exampleSystem) (allDrvOutputs exampleSystem)
] ]
++ pkgs.lib.optional (buildOn == "remote") exampleFlake; ++ pkgs.lib.optional (buildOn == "remote") exampleFlake;
}; };
nix = {
extraOptions =
let empty_registry = builtins.toFile "empty-flake-registry.json" ''{"flakes":[],"version":2}''; in
''
experimental-features = nix-command flakes
flake-registry = ${empty_registry}
'';
registry.nixpkgs.flake = inputs.nixpkgs;
};
}; };
}; };
testScript = testScript =