git.delta.rocks / jrsonnet / refs/commits / 11af00be5405

difftreelog

fix do not check nixos config for secret management

Lach2025-04-24parent: #1658981.patch.diff
in: trunk

2 files changed

modifiedcrates/fleet-base/src/host.rsdiffbeforeafterboth
--- a/crates/fleet-base/src/host.rs
+++ b/crates/fleet-base/src/host.rs
@@ -97,6 +97,7 @@
 
 	pub host_config: Option<Value>,
 	pub nixos_config: OnceCell<Value>,
+	pub nixos_unchecked_config: OnceCell<Value>,
 	pub pkgs_override: Option<Value>,
 
 	// TODO: Move command helpers away with connectivity refactor
@@ -377,9 +378,22 @@
 
 		Ok(nixos_config)
 	}
+	pub async fn nixos_unchecked_config(&self) -> Result<Value> {
+		if let Some(v) = self.nixos_unchecked_config.get() {
+			return Ok(v.clone());
+		}
+		let Some(host_config) = &self.host_config else {
+			bail!("local host has no nixos_config");
+		};
+		let nixos_config = nix_go!(host_config.nixos_unchecked.config);
+
+		let _ = self.nixos_unchecked_config.set(nixos_config.clone());
+
+		Ok(nixos_config)
+	}
 
 	pub async fn list_configured_secrets(&self) -> Result<Vec<String>> {
-		let nixos = self.nixos_config().await?;
+		let nixos = self.nixos_unchecked_config().await?;
 		let secrets = nix_go!(nixos.secrets);
 		let mut out = Vec::new();
 		for name in secrets.list_fields().await? {
@@ -393,7 +407,7 @@
 		Ok(out)
 	}
 	pub async fn secret_field(&self, name: &str) -> Result<Value> {
-		let nixos = self.nixos_config().await?;
+		let nixos = self.nixos_unchecked_config().await?;
 		Ok(nix_go!(nixos.secrets[{ name }]))
 	}
 
@@ -434,6 +448,7 @@
 			name: "<virtual localhost>".to_owned(),
 			host_config: None,
 			nixos_config: OnceCell::new(),
+			nixos_unchecked_config: OnceCell::new(),
 			groups: {
 				let cell = OnceCell::new();
 				let _ = cell.set(vec![]);
@@ -456,6 +471,7 @@
 			name: name.to_owned(),
 			host_config: Some(host_config),
 			nixos_config: OnceCell::new(),
+			nixos_unchecked_config: OnceCell::new(),
 			groups: OnceCell::new(),
 			pkgs_override: None,
 
modifiedmodules/nixos.nixdiffbeforeafterboth
9}: let9}: let
10 inherit (lib.attrsets) mapAttrs;10 inherit (lib.attrsets) mapAttrs;
11 inherit (lib.options) mkOption;11 inherit (lib.options) mkOption;
12 inherit (lib.types) deferredModule;12 inherit (lib.types) deferredModule unspecified;
13 inherit (lib.modules) mkRemovedOptionModule;13 inherit (lib.modules) mkRemovedOptionModule;
14 inherit (lib.strings) escapeNixIdentifier;14 inherit (lib.strings) escapeNixIdentifier;
15 inherit (fleetLib.options) mkHostsOption;15 inherit (fleetLib.options) mkHostsOption;
54 };54 };
55 };55 };
56 };56 };
57 nixos_unchecked = mkOption {
58 type = unspecified;
59 };
57 };60 };
58 config = {61 config = {
59 # imports = [62 # imports = [
60 # (mkRemovedOptionModule ["nixosModules"] "replaced with hosts.*.nixos.imports.")63 # (mkRemovedOptionModule ["nixosModules"] "replaced with hosts.*.nixos.imports.")
61 # ];64 # ];
62 nixos = {65 nixos = {
63 config._module.args = {66 config._module.args = {
64 nixosHosts = mapAttrs (_: value: value.nixos.config) config.hosts;67 nixosHosts = mapAttrs (_: value: value.nixos_unchecked.config) config.hosts;
65 hosts = config.hosts;68 hosts = config.hosts;
66 host = hostArgs.config;69 host = hostArgs.config;
67 };70 };
68 };71 };
72 nixos_unchecked = hostArgs.config.nixos.extendModules {
73 modules = [
74 {
75 _module.check = false;
76 }
77 ];
78 };
69 };79 };
70 });80 });
71 };81 };