Restrict fileset necessary for deployment tests (#450)

Now that we won't depend on the flake.nix anymore, we won't depend on all the flake-part.nix files (necessary to evaluate flake.nix) and all the files they depend on etc., so the Nix dependencies of the tests will be drastically reduced, and I will be able to leverage that by introducing a more subtle src. This will make the test not need to re-run if only things outside that reduced src changed (and the previous run is in the Nix store).

Reviewed-on: Fediversity/Fediversity#450
Reviewed-by: kiara Grouwstra <kiara@procolix.eu>
Reviewed-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Co-authored-by: Nicolas “Niols” Jeannerod <nicolas.jeannerod@moduscreate.com>
Co-committed-by: Nicolas “Niols” Jeannerod <nicolas.jeannerod@moduscreate.com>
This commit is contained in:
Nicolas Jeannerod 2025-07-09 22:57:52 +02:00 committed by Valentin Gagarin
parent de38611572
commit b4e1c5b5b3
4 changed files with 81 additions and 11 deletions

View file

@ -1,10 +1,15 @@
{ inputs, ... }: { inputs, lib, ... }:
{ {
_class = "nixosTest"; _class = "nixosTest";
name = "deployment-basic"; name = "deployment-basic";
sourceFileset = lib.fileset.unions [
./constants.nix
./deployment.nix
];
nodes.deployer = nodes.deployer =
{ pkgs, ... }: { pkgs, ... }:
{ {

View file

@ -1,4 +1,9 @@
{ inputs, hostPkgs, ... }: {
inputs,
hostPkgs,
lib,
...
}:
let let
## Some places need a dummy file that will in fact never be used. We create ## Some places need a dummy file that will in fact never be used. We create
@ -11,6 +16,21 @@ in
name = "deployment-cli"; name = "deployment-cli";
sourceFileset = lib.fileset.unions [
./constants.nix
./deployments.nix
# REVIEW: I would like to be able to grab all of `/deployment` minus
# `/deployment/check`, but I can't because there is a bunch of other files
# in `/deployment`. Maybe we can think of a reorg making things more robust
# here? (comment also in panel test)
../../default.nix
../../options.nix
../../configuration.sample.json
../../../services/fediversity
];
nodes.deployer = nodes.deployer =
{ pkgs, ... }: { pkgs, ... }:
{ {

View file

@ -13,6 +13,7 @@ let
toJSON toJSON
; ;
inherit (lib) inherit (lib)
types
fileset fileset
mkOption mkOption
genAttrs genAttrs
@ -27,14 +28,6 @@ let
forConcat = xs: f: concatStringsSep "\n" (map f xs); forConcat = xs: f: concatStringsSep "\n" (map f xs);
## The whole repository, with the flake at its root.
## FIXME: We could probably have fileset be the union of ./. with flake.nix
## and flake.lock - I doubt we need anything else.
src = fileset.toSource {
fileset = config.pathToRoot;
root = config.pathToRoot;
};
## We will need to override some inputs by the empty flake, so we make one. ## We will need to override some inputs by the empty flake, so we make one.
emptyFlake = runCommandNoCC "empty-flake" { } '' emptyFlake = runCommandNoCC "empty-flake" { } ''
mkdir $out mkdir $out
@ -53,9 +46,39 @@ in
## FIXME: I wish I could just use `testScript` but with something like ## FIXME: I wish I could just use `testScript` but with something like
## `mkOrder` to put this module's string before something else. ## `mkOrder` to put this module's string before something else.
extraTestScript = mkOption { }; extraTestScript = mkOption { };
sourceFileset = mkOption {
## REVIEW: Upstream to nixpkgs?
type = types.mkOptionType {
name = "fileset";
description = "fileset";
descriptionClass = "noun";
check = (x: (builtins.tryEval (fileset.unions [ x ])).success);
merge = (_: defs: fileset.unions (map (x: x.value) defs));
};
description = ''
A fileset that will be copied to the deployer node in the current
working directory. This should contain all the files that are
necessary to run that particular test, such as the NixOS
modules necessary to evaluate a deployment.
'';
};
}; };
config = { config = {
sourceFileset = fileset.unions [
# NOTE: not the flake itself; it will be overridden.
../../../mkFlake.nix
../../../flake.lock
../../../npins
./sharedOptions.nix
./targetNode.nix
./targetResource.nix
(config.pathToCwd + "/flake-under-test.nix")
];
acmeNodeIP = config.nodes.acme.networking.primaryIPAddress; acmeNodeIP = config.nodes.acme.networking.primaryIPAddress;
nodes = nodes =
@ -103,8 +126,16 @@ in
${n}.wait_for_unit("multi-user.target") ${n}.wait_for_unit("multi-user.target")
'')} '')}
## A subset of the repository that is necessary for this test. It will be
## copied inside the test. The smaller this set, the faster our CI, because we
## won't need to re-run when things change outside of it.
with subtest("Unpacking"): with subtest("Unpacking"):
deployer.succeed("cp -r --no-preserve=mode ${src}/* .") deployer.succeed("cp -r --no-preserve=mode ${
fileset.toSource {
root = ../../..;
fileset = config.sourceFileset;
}
}/* .")
with subtest("Configure the network"): with subtest("Configure the network"):
${forConcat config.targetMachines ( ${forConcat config.targetMachines (

View file

@ -125,6 +125,20 @@ in
name = "deployment-panel"; name = "deployment-panel";
sourceFileset = lib.fileset.unions [
./constants.nix
./deployment.nix
# REVIEW: I would like to be able to grab all of `/deployment` minus
# `/deployment/check`, but I can't because there is a bunch of other files
# in `/deployment`. Maybe we can think of a reorg making things more robust
# here? (comment also in CLI test)
../../default.nix
../../options.nix
../../../services/fediversity
];
## The panel's module sets `nixpkgs.overlays` which clashes with ## The panel's module sets `nixpkgs.overlays` which clashes with
## `pkgsReadOnly`. We disable it here. ## `pkgsReadOnly`. We disable it here.
node.pkgsReadOnly = false; node.pkgsReadOnly = false;