Skip to content

Commit

Permalink
draft: test for non-flake build regressions
Browse files Browse the repository at this point in the history
this adds a nixos vm test doing a deploy on a nix which does not have
flakes enabled, to guard against this breaking as it has done before [1].

The existing test infrastructure is changed slightly to make enabling
flakes configurable inside the vm's config.

[1] serokell#272
  • Loading branch information
stuebinm committed Jun 11, 2024
1 parent e82e5d5 commit fb54886
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
5 changes: 3 additions & 2 deletions nix/tests/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#
# SPDX-License-Identifier: MPL-2.0

{inputs, pkgs, ...}: {
{inputs, pkgs, flakes, ...}: {
nix = {
registry.nixpkgs.flake = inputs.nixpkgs;
nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
extraOptions = ''
experimental-features = nix-command flakes
experimental-features = ${if flakes then "nix-command flakes" else "nix-command"}
'';
settings = {
trusted-users = [ "root" "@wheel" ];
Expand Down
35 changes: 30 additions & 5 deletions nix/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ let
done <$refs
'';

mkTest = { name ? "", user ? "root", isLocal ? true, deployArgs }: let
mkTest = { name ? "", user ? "root", flakes ? true, isLocal ? true, deployArgs }: let
nodes = {
server = { nodes, ... }: {
imports = [
./server.nix
(import ./common.nix { inherit inputs pkgs; })
(import ./common.nix { inherit inputs pkgs flakes; })
];
virtualisation.additionalPaths = lib.optionals (!isLocal) [
pkgs.hello
Expand All @@ -35,8 +35,9 @@ let
];
};
client = { nodes, ... }: {
imports = [ (import ./common.nix { inherit inputs pkgs; }) ];
imports = [ (import ./common.nix { inherit inputs pkgs flakes; }) ];
environment.systemPackages = [ pkgs.deploy-rs.deploy-rs ];
virtualisation.memorySize = lib.mkForce 4096;
virtualisation.additionalPaths = lib.optionals isLocal [
pkgs.hello
pkgs.figlet
Expand All @@ -56,11 +57,29 @@ let
systems.url = "${inputs.utils.inputs.systems}";
flake-compat.url = "${inputs.flake-compat}";
flake-compat.flake = false;
enable-flakes.url = "${builtins.toFile "use-flakes" (if flakes then "true" else "false")}";
enable-flakes.flake = false;
'';

flake = builtins.toFile "flake.nix"
(lib.replaceStrings [ "##inputs##" ] [ flakeInputs ] (builtins.readFile ./deploy-flake.nix));

flakeCompat = builtins.toFile "default.nix" ''
(import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://not-used-we-fetch-by-hash";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix
'';

in pkgs.nixosTest {
inherit nodes name;

Expand All @@ -73,11 +92,11 @@ let
# Prepare
client.succeed("mkdir tmp && cd tmp")
client.succeed("cp ${flake} ./flake.nix")
client.succeed("cp ${flakeCompat} ./default.nix")
client.succeed("cp ${./server.nix} ./server.nix")
client.succeed("cp ${./common.nix} ./common.nix")
client.succeed("cp ${serverNetworkJSON} ./network.json")
client.succeed("nix flake lock")
client.succeed("nix --extra-experimental-features flakes flake lock")
# Setup SSH key
client.succeed("mkdir -m 700 /root/.ssh")
Expand Down Expand Up @@ -131,4 +150,10 @@ in {
user = "deploy";
deployArgs = "-s .#profile -- --offline";
};
# Deployment using a non-flake nix
non-flake-build = mkTest {
name = "local-build";
flakes = false;
deployArgs = "-s .#server";
};
}
2 changes: 1 addition & 1 deletion nix/tests/deploy-flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
in {
nixosConfigurations.server = nixpkgs.lib.nixosSystem {
inherit system pkgs;
specialArgs = { inherit inputs; };
specialArgs = { inherit inputs; flakes = import inputs.enable-flakes; };
modules = [
./server.nix
./common.nix
Expand Down

0 comments on commit fb54886

Please sign in to comment.