diff options
| author | tv <tv@krebsco.de> | 2026-11-14 03:45:10 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-14 04:56:34 +0100 |
| commit | 3e2116f153077186556c01ae1fc89923abfea265 (patch) | |
| tree | b3dcebd146ceba4691ea7546e5d0937ac6591707 /pkgs | |
| parent | feda621a3a6b29c55c179059259d938d83e30f6e (diff) | |
populate: passage sources default identities_file when populate runs
The default, toString ~/.passage/identities, is a path relative to the
home directory, which Nix resolves when parsing the file defining it,
populate's Nix library's types, so evaluating any sources failed in pure
mode, e.g. in a flake. identities_file defaults to null, which leaves it
out of the sources, and populate defaults it to ~/.passage/identities,
in HOME, when it runs.
The passage scenarios also run without identities_file, with HOME a
directory that has .passage/identities.
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/populate/README.md | 2 | ||||
| -rw-r--r-- | pkgs/populate/lib/types/populate.nix | 6 | ||||
| -rw-r--r-- | pkgs/populate/src/check.rs | 2 | ||||
| -rw-r--r-- | pkgs/populate/src/populate.rs | 17 | ||||
| -rwxr-xr-x | pkgs/populate/tests/fixtures.sh | 4 | ||||
| -rw-r--r-- | pkgs/populate/tests/scenarios.nix | 6 | ||||
| -rw-r--r-- | pkgs/populate/tests/smoke.nix | 2 |
7 files changed, 29 insertions, 10 deletions
diff --git a/pkgs/populate/README.md b/pkgs/populate/README.md index fd7de6d..e85b502 100644 --- a/pkgs/populate/README.md +++ b/pkgs/populate/README.md @@ -473,7 +473,7 @@ Supported attributes: * `identities_file` (optional) - Path to the identities file. - Defaults to `~/.passage/identities`. + Defaults to `~/.passage/identities`, of the user running populate. * `age` (optional) - Path of the age binary. diff --git a/pkgs/populate/lib/types/populate.nix b/pkgs/populate/lib/types/populate.nix index 56b0292..8e74c5e 100644 --- a/pkgs/populate/lib/types/populate.nix +++ b/pkgs/populate/lib/types/populate.nix @@ -294,9 +294,11 @@ dir = lib.mkOption { type = lib.types.pathname; }; + # Populate defaults to ~/.passage/identities when it runs, which + # evaluation can't tell in pure mode. identities_file = lib.mkOption { - default = toString ~/.passage/identities; - type = lib.types.pathname; + default = null; + type = lib.types.nullOr lib.types.pathname; }; }; }; diff --git a/pkgs/populate/src/check.rs b/pkgs/populate/src/check.rs index 5b73deb..155565f 100644 --- a/pkgs/populate/src/check.rs +++ b/pkgs/populate/src/check.rs @@ -104,7 +104,7 @@ fn known_settings(kind: &str) -> &'static [(&'static str, Kind, bool)] { "passage" => &[ ("age", String, true), ("dir", String, true), - ("identities_file", String, true), + ("identities_file", String, false), ], "pipe" => &[("command", Absolute, true)], "symlink" => &[("target", String, true), ("inputs", Inputs, false)], diff --git a/pkgs/populate/src/populate.rs b/pkgs/populate/src/populate.rs index 47a9099..a488cfd 100644 --- a/pkgs/populate/src/populate.rs +++ b/pkgs/populate/src/populate.rs @@ -195,13 +195,20 @@ fn deliver( "passage" => { let host = context.target.host.split('.').next().unwrap_or_default(); let mut command = run::local_shell(sh::local::PASSAGE, &[host], &workdir); - for (variable, key) in [ - ("PASSAGE_AGE", "age"), - ("PASSAGE_DIR", "dir"), - ("PASSAGE_IDENTITIES_FILE", "identities_file"), - ] { + for (variable, key) in [("PASSAGE_AGE", "age"), ("PASSAGE_DIR", "dir")] { command.env(variable, string(settings, key)?); } + let identities = match settings.get("identities_file").and_then(Value::as_str) { + Some(file) => file.to_string(), + None => match std::env::var("HOME") { + Ok(home) if !home.is_empty() => format!("{home}/.passage/identities"), + _ => return Err(Failure::Message( + "populate: HOME isn't set, so the passage source has no identities_file" + .to_string(), + )), + }, + }; + command.env("PASSAGE_IDENTITIES_FILE", identities); run::status(&mut command)?; rsync::transfer( context, diff --git a/pkgs/populate/tests/fixtures.sh b/pkgs/populate/tests/fixtures.sh index 85701a1..93b302d 100755 --- a/pkgs/populate/tests/fixtures.sh +++ b/pkgs/populate/tests/fixtures.sh @@ -346,6 +346,10 @@ printf 'secret-a\n' | PASSAGE_DIR=/fixtures/passage/store \ PASSAGE_IDENTITIES_FILE=/fixtures/passage/identities \ passage insert -m x/a >/dev/null +# A home directory with the identities where passage sources look for them +# by default. +mkdir -p /fixtures/passage-home/.passage +cp /fixtures/passage/identities /fixtures/passage-home/.passage/identities # pipe: a command for the pipe source type. cat > /fixtures/pipe <<'SH' diff --git a/pkgs/populate/tests/scenarios.nix b/pkgs/populate/tests/scenarios.nix index 2ab2d0e..223839b 100644 --- a/pkgs/populate/tests/scenarios.nix +++ b/pkgs/populate/tests/scenarios.nix @@ -432,17 +432,23 @@ with import ./builder.nix args; }; }); + # identities_file defaults to the identities in the home directory. passage = matrix "passage" { age = [ "default" "path" ]; dir = [ "store" "subdir" ]; + identities = [ "file" "home" ]; } (flags: _: { + exhaustive = flags.identities == "home" && + (flags.age != "default" || flags.dir != "store"); phases = twice { sources.x.passage = { dir = "/fixtures/passage/store" + optionalString (flags.dir == "subdir") "/x"; + } // optionalAttrs (flags.identities == "file") { identities_file = "/fixtures/passage/identities"; } // optionalAttrs (flags.age == "path") { age = agePath; }; + env = optionalString (flags.identities == "home") "HOME=/fixtures/passage-home"; check = '' expect_eq a "$(cat "$T"/x/${optionalString (flags.dir == "store") "x/"}a)" secret-a ''; diff --git a/pkgs/populate/tests/smoke.nix b/pkgs/populate/tests/smoke.nix index 45510a0..0765c7c 100644 --- a/pkgs/populate/tests/smoke.nix +++ b/pkgs/populate/tests/smoke.nix @@ -7,7 +7,7 @@ "git-local-shallow1-refs" "symlink-local-absolute0-inputs0" "pass-remote-storepass" - "passage-sudo-agedefault-dirstore" + "passage-sudo-agedefault-dirstore-identitieshome" "pipe-local" "derivation-remote" "flake-local-fetchOnTarget0-inputsrewrite-kindgit-materialize0" |
