Skip to content

Commit 11af00b

Browse files
committed
fix: do not check nixos config for secret management
1 parent 1658981 commit 11af00b

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

crates/fleet-base/src/host.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub struct ConfigHost {
9797

9898
pub host_config: Option<Value>,
9999
pub nixos_config: OnceCell<Value>,
100+
pub nixos_unchecked_config: OnceCell<Value>,
100101
pub pkgs_override: Option<Value>,
101102

102103
// TODO: Move command helpers away with connectivity refactor
@@ -377,9 +378,22 @@ impl ConfigHost {
377378

378379
Ok(nixos_config)
379380
}
381+
pub async fn nixos_unchecked_config(&self) -> Result<Value> {
382+
if let Some(v) = self.nixos_unchecked_config.get() {
383+
return Ok(v.clone());
384+
}
385+
let Some(host_config) = &self.host_config else {
386+
bail!("local host has no nixos_config");
387+
};
388+
let nixos_config = nix_go!(host_config.nixos_unchecked.config);
389+
390+
let _ = self.nixos_unchecked_config.set(nixos_config.clone());
391+
392+
Ok(nixos_config)
393+
}
380394

381395
pub async fn list_configured_secrets(&self) -> Result<Vec<String>> {
382-
let nixos = self.nixos_config().await?;
396+
let nixos = self.nixos_unchecked_config().await?;
383397
let secrets = nix_go!(nixos.secrets);
384398
let mut out = Vec::new();
385399
for name in secrets.list_fields().await? {
@@ -393,7 +407,7 @@ impl ConfigHost {
393407
Ok(out)
394408
}
395409
pub async fn secret_field(&self, name: &str) -> Result<Value> {
396-
let nixos = self.nixos_config().await?;
410+
let nixos = self.nixos_unchecked_config().await?;
397411
Ok(nix_go!(nixos.secrets[{ name }]))
398412
}
399413

@@ -434,6 +448,7 @@ impl Config {
434448
name: "<virtual localhost>".to_owned(),
435449
host_config: None,
436450
nixos_config: OnceCell::new(),
451+
nixos_unchecked_config: OnceCell::new(),
437452
groups: {
438453
let cell = OnceCell::new();
439454
let _ = cell.set(vec![]);
@@ -456,6 +471,7 @@ impl Config {
456471
name: name.to_owned(),
457472
host_config: Some(host_config),
458473
nixos_config: OnceCell::new(),
474+
nixos_unchecked_config: OnceCell::new(),
459475
groups: OnceCell::new(),
460476
pkgs_override: None,
461477

modules/nixos.nix

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}: let
1010
inherit (lib.attrsets) mapAttrs;
1111
inherit (lib.options) mkOption;
12-
inherit (lib.types) deferredModule;
12+
inherit (lib.types) deferredModule unspecified;
1313
inherit (lib.modules) mkRemovedOptionModule;
1414
inherit (lib.strings) escapeNixIdentifier;
1515
inherit (fleetLib.options) mkHostsOption;
@@ -54,18 +54,28 @@ in {
5454
};
5555
};
5656
};
57+
nixos_unchecked = mkOption {
58+
type = unspecified;
59+
};
5760
};
5861
config = {
5962
# imports = [
6063
# (mkRemovedOptionModule ["nixosModules"] "replaced with hosts.*.nixos.imports.")
6164
# ];
6265
nixos = {
6366
config._module.args = {
64-
nixosHosts = mapAttrs (_: value: value.nixos.config) config.hosts;
67+
nixosHosts = mapAttrs (_: value: value.nixos_unchecked.config) config.hosts;
6568
hosts = config.hosts;
6669
host = hostArgs.config;
6770
};
6871
};
72+
nixos_unchecked = hostArgs.config.nixos.extendModules {
73+
modules = [
74+
{
75+
_module.check = false;
76+
}
77+
];
78+
};
6979
};
7080
});
7181
};

0 commit comments

Comments
 (0)