diff options
| author | tv <tv@krebsco.de> | 2026-11-14 04:18:14 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-14 06:25:54 +0100 |
| commit | 41833dc11d75718c279e682593580a46dcec0c73 (patch) | |
| tree | 523c5ab1bdaed02de674222e9f9cb7c1f7039d77 /tests | |
| parent | 7198af72e3490015cb229f75abaf0e1b9a3108f0 (diff) | |
krops: leave targets to populate, also in pure evaluation
writeDeploy, writeCommand, and writeTest pass target strings to
pkgs.populate as they are, so populate fills in what they leave out, and
decides whether the target is local, when it runs. runShell runs
populate shell, which decides that for running nixos-rebuild and
writeCommand's commands, so rebuild's unbuffer for local targets with
allocateTTY depends on $1, and runShell returns shell code, also for
remote targets. Target attribute sets get mkTarget's defaults and
whether they're local during evaluation, as before, unless that's pure:
then mkTarget leaves the user and the host null, instead of reading
/etc/hostname, which pure evaluation pretends doesn't exist, and
pkgs.populate and populate shell leave them, and whether the target is
local, to populate, which also refuses copying flakes to targets using
sudo then. writeTest checks that its target is local during evaluation,
unless that's pure, and with populate shell --local-only before
populating. writeDeploy needs a target's host for a separate
buildTarget in pure evaluation. pkgs/krops/target.nix has what
pkgs.populate and pkgs.krops need of targets.
pkgs.populate's derivations stay the same, for strings and attribute
sets. The deploy scenarios get target strings too, for the local and
the remote target, and so does the allocateTTY scenario.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/default.nix | 3 | ||||
| -rw-r--r-- | tests/scenarios.nix | 44 |
2 files changed, 34 insertions, 13 deletions
diff --git a/tests/default.nix b/tests/default.nix index fa82e3a..08f95a6 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -70,7 +70,8 @@ let # Names of the scenarios of the smoke test, besides populate's. smokeNames = import (populateTests + "/smoke.nix") ++ [ - "deploy-local-buildTarget0-etcFlake0-flakefile" + "deploy-local-buildTarget0-etcFlake0-flakefile-targetString0" + "deploy-remote-buildTarget0-etcFlake0-flakenone-targetString1" "deploy-sudo-allocateTTY" ]; diff --git a/tests/scenarios.nix b/tests/scenarios.nix index e61d25b..0e90284 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -5,10 +5,17 @@ { targets, ... }@args: let - inherit (args) lib gitHead gitUrl; - inherit (lib) concatStringsSep optional optionalAttrs optionals optionalString; + inherit (args) lib gitHead gitUrl remoteHost; + inherit (lib) concatMap concatStringsSep optional optionalAttrs optionals optionalString; inherit (import ../pkgs/populate/tests/builder.nix (removeAttrs args [ "targets" ])) alt drawInputs matrix scenario targetKinds twice; + + # The target of a kind for a path, as a string, which can't say to use + # sudo. + targetString = targetKind: path: { + local = path; + remote = "root@${remoteHost}${path}"; + }.${targetKind}; in { @@ -16,11 +23,13 @@ in # writeDeploy's arguments to nixos-rebuild, which a stand-in records. # flake is what gets deployed: nothing, or a flake from a file, git, or # flake source, or one whose inputs get drawn from a source, by rewriting - # its lock file or through a generated flake. + # its lock file or through a generated flake. targetString gives the + # target as a string, which populate and populate shell get as it is. deploy = matrix "deploy" { flake = [ "none" "file" "git" "source" "rewrite" "generated" ]; etcFlake = [ false true ]; buildTarget = [ false true ]; + targetString = [ false true ]; } (flags: ctx: let target = targets.${ctx.targetKind} ctx.path; buildTarget = targets.local "${ctx.path}-build"; @@ -42,11 +51,15 @@ in if flags.flake == "generated" then ".populate/flakes/x" else "x"; scheme = if flags.flake == "git" then "git+file" else "path"; in - # The local target can't have another build target. - if flags.buildTarget && ctx.targetKind == "local" then null else { + # The local target can't have another build target, and a string can't + # say to use sudo. + if flags.buildTarget && ctx.targetKind == "local" || + flags.targetString && ctx.targetKind == "sudo" then null else { node = if flags.buildTarget then "deployer" else null; - # /etc/nixos/flake.nix only matters if no flake gets deployed. - exhaustive = flags.etcFlake && flags.flake != "none"; + # /etc/nixos/flake.nix only matters if no flake gets deployed, and + # how the target is given not for what gets deployed. + exhaustive = flags.etcFlake && flags.flake != "none" || + flags.targetString && flags.flake != "none"; # Each scenario creates or removes /etc/nixos/flake.nix. prepare = '' rm -f /tmp/nixos-rebuild.log @@ -74,6 +87,8 @@ in flake = if flags.flake == "none" then null else "x"; } // optionalAttrs flags.buildTarget { inherit buildTarget; + } // optionalAttrs flags.targetString { + target = targetString ctx.targetKind ctx.path; }; check = '' expect_eq user "$(sed -n 1p /tmp/nixos-rebuild.log)" 0 @@ -91,16 +106,21 @@ in # writeDeploy with allocateTTY: nixos-rebuild's output is a terminal on # the local target. ssh allocates one on remote targets only if its own - # input is a terminal, which the tests' isn't. - ++ map (targetKind: scenario { - name = "deploy-${targetKind}-allocateTTY"; + # input is a terminal, which the tests' isn't. Whether the target is + # local, populate shell decides, also for a target string. + ++ concatMap (targetKind: map (string: scenario (rec { + name = "deploy-${targetKind}${optionalString string "-string"}-allocateTTY"; inherit targetKind; prepare = '' rm -f /tmp/nixos-rebuild.log /etc/nixos/flake.nix ''; phases = [{ sources.x.file = "/fixtures/alt"; - deploy.allocateTTY = true; + deploy = { + allocateTTY = true; + } // optionalAttrs string { + target = targetString targetKind "/var/krops/${name}"; + }; check = '' expect_eq arguments "$(sed -n 3p /tmp/nixos-rebuild.log)" switch expect_eq terminal "$(sed -n 4p /tmp/nixos-rebuild.log)" ${ @@ -108,6 +128,6 @@ in } ''; }]; - }) targetKinds; + })) (if targetKind == "sudo" then [ false ] else [ false true ])) targetKinds; } |
