difftreelog
refactor shell abstraction
in: trunk
6 files changed
cmds/fleet/src/better_nix_eval.rsdiffbeforeafterboth--- a/cmds/fleet/src/better_nix_eval.rs
+++ b/cmds/fleet/src/better_nix_eval.rs
@@ -472,7 +472,7 @@
($field:ident $($tt:tt)*) => {{
use $crate::{better_nix_eval::NixExprBuilder, nix_expr_inner};
#[allow(unused_mut, reason = "might be used if indexed")]
- let mut out = NixExprBuilder::field($field);
+ let mut out = NixExprBuilder::field($field.clone());
nix_expr_inner!(@field(out) $($tt)*);
out
}};
cmds/fleet/src/cmds/build_systems.rsdiffbeforeafterboth--- a/cmds/fleet/src/cmds/build_systems.rs
+++ b/cmds/fleet/src/cmds/build_systems.rs
@@ -291,9 +291,11 @@
info!("building");
let action = Action::from(self.subcommand.clone());
let fleet_field = &config.fleet_field;
- let drv = nix_go!(fleet_field.buildSystems(Obj {
- localSystem: { config.local_system.clone() }
- }));
+ let drv = nix_go!(
+ fleet_field.buildSystems(Obj {
+ localSystem: { config.local_system.clone() }
+ })[{ action.build_attr() }][{ host }]
+ );
let outputs = drv.build().await.map_err(|e| {
if action.build_attr() == "sdImage" {
info!("sd-image build failed");
cmds/fleet/src/cmds/secrets/mod.rsdiffbeforeafterboth--- a/cmds/fleet/src/cmds/secrets/mod.rs
+++ b/cmds/fleet/src/cmds/secrets/mod.rs
@@ -1,4 +1,5 @@
use crate::{
+ command::MyCommand,
fleetdata::{FleetSecret, FleetSharedSecret},
host::Config,
nix_go, nix_go_json,
@@ -12,6 +13,7 @@
collections::HashSet,
io::{self, Cursor, Read},
path::PathBuf,
+ sync::Arc,
};
use tabled::{Table, Tabled};
use tokio::fs::read_to_string;
@@ -97,8 +99,9 @@
Secret::InvokeGenerator => {
let config_field = &config.config_unchecked_field;
- let generate_impure =
- nix_go!(config_field.sharedSecrets["kube-apiserver.pem"].generateImpure);
+ let secret =
+ nix_go!(config_field.configUnchecked.sharedSecrets["kube-apiserver.pem"]);
+ let generate_impure = nix_go!(secret.generateImpure);
let on = nix_go!(generate_impure.on);
let call_package = nix_go!(
config_field.buildableSystems(Obj {
@@ -106,13 +109,62 @@
})[on]
.config
.nixpkgs
- .pkgs
+ .resolvedPkgs
.callPackage
);
- let generator = nix_go!(call_package(generate_impure.generator));
- let built = generator.build().await?;
- // .as_json().await?;
- dbg!(&built);
+ let generator = nix_go!(call_package(generate_impure.generator)(Obj {}));
+ let built = &generator.build().await?["out"];
+ let mut nix = MyCommand::new("nix");
+ let on: String = on.as_json().await?;
+ nix.arg("copy")
+ .arg("--substitute-on-destination")
+ .comparg("--to", format!("ssh-ng://{on}"))
+ .arg(built);
+ nix.run_nix().await?;
+
+ let session = config.host(&on).await?;
+
+ let owners: Vec<String> = nix_go_json!(secret.expectedOwners);
+ dbg!(&owners);
+
+ let mut recipients = String::new();
+ for owner in owners {
+ let key = config.key(&owner).await?;
+ recipients.push_str(&format!("-r \"{key}\" "));
+ }
+ recipients.push_str("-e");
+
+ // FIXME: security: created directory might be accessible to other users
+ // This shouldn't be much of a concern, as data is encrypted right after creation, yet
+ // still better to have.
+ let tempdir = session.mktemp_dir().await?;
+
+ let mut gen = session.cmd(built).await?;
+ gen.env("rageArgs", recipients).env("out", &tempdir);
+ gen.run().await?;
+
+ {
+ let marker = session.read_file_text(format!("{tempdir}/marker")).await?;
+ ensure!(marker == "SUCCESS", "generation not succeeded");
+ }
+
+ let public = session
+ .read_file_bin(format!("{tempdir}/public"))
+ .await
+ .ok();
+ let secret = session
+ .read_file_bin(format!("{tempdir}/secret"))
+ .await
+ .ok();
+ if let Some(secret) = &secret {
+ ensure!(
+ age::Decryptor::new(Cursor::new(&secret)).is_ok(),
+ "builder produced non-encrypted value as secret, this is highly insecure"
+ );
+ }
+ dbg!(&secret);
+ // // .as_json().await?;
+ // dbg!(&built);
}
Secret::ForceKeys => {
for host in config.list_hosts().await? {
@@ -249,7 +301,8 @@
if secret.secret.is_empty() {
bail!("no secret {name}");
}
- let data = config.decrypt_on_host(&machine, secret.secret).await?;
+ let host = config.host(&machine).await?;
+ let data = host.decrypt(secret.secret).await?;
if plaintext {
let s = String::from_utf8(data).context("output is not utf8")?;
print!("{s}");
cmds/fleet/src/command.rsdiffbeforeafterboth--- a/cmds/fleet/src/command.rs
+++ b/cmds/fleet/src/command.rs
@@ -1,6 +1,7 @@
use std::{
collections::HashMap,
ffi::OsStr,
+ pin,
process::Stdio,
sync::{Arc, Mutex},
task::Poll,
@@ -10,7 +11,7 @@
use futures::StreamExt;
use itertools::Either;
use once_cell::sync::Lazy;
-use openssh::{OverSsh, Session};
+use openssh::{OverSsh, OwningCommand, Session};
use regex::Regex;
use serde::{de::Visitor, Deserialize};
use tokio::{io::AsyncRead, process::Command, select};
@@ -44,6 +45,15 @@
ssh_session: Option<Arc<Session>>,
}
impl MyCommand {
+ pub fn new_on(cmd: impl AsRef<OsStr>, session: Arc<Session>) -> Self {
+ assert!(!cmd.as_ref().is_empty());
+ Self {
+ command: ostoutf8(cmd),
+ args: vec![],
+ env: vec![],
+ ssh_session: Some(session),
+ }
+ }
pub fn new(cmd: impl AsRef<OsStr>) -> Self {
assert!(!cmd.as_ref().is_empty());
Self {
@@ -66,6 +76,29 @@
out.extend(self.args);
out
}
+
+ /// Translates environment variables into env command execution.
+ /// Required for ssh, as ssh don't allow to send environment variables (at least by default).
+ ///
+ /// FIXME: Insecure, as arguments might be seen by other users on the same machine.
+ /// Figure out some way to transfer environment using stdio?
+ fn translate_env_into_env(self) -> Self {
+ if self.env.is_empty() {
+ return self;
+ }
+ let mut out = Self::new("env");
+ if let Some(session) = self.ssh_session {
+ out = out.ssh_session(session);
+ }
+ for (k, v) in self.env {
+ assert!(!k.contains('='));
+ out.arg(format!("{k}={v}"));
+ }
+ out.arg(self.command);
+ out.args(self.args);
+
+ out
+ }
fn into_string(self) -> String {
let mut out = String::new();
if !self.env.is_empty() {
@@ -98,7 +131,7 @@
}
fn into_command_new(self) -> Result<Either<Command, openssh::OwningCommand<Arc<Session>>>> {
Ok(if let Some(session) = self.ssh_session.clone() {
- let cmd = self.into_command();
+ let cmd = self.translate_env_into_env().into_command();
Either::Right(
cmd.over_ssh(session)
.map_err(|e| anyhow!("ssh error: {e}"))?,
@@ -126,6 +159,11 @@
self.arg(value);
self
}
+ pub fn env(&mut self, name: impl AsRef<str>, value: impl AsRef<str>) -> &mut Self {
+ self.env
+ .push((name.as_ref().to_owned(), value.as_ref().to_owned()));
+ self
+ }
pub fn args<V: AsRef<OsStr>>(&mut self, args: impl IntoIterator<Item = V>) -> &mut Self {
for arg in args.into_iter() {
let arg = arg.as_ref();
@@ -133,9 +171,10 @@
}
self
}
- pub fn sudo(self) -> Self {
+ pub fn sudo(mut self) -> Self {
if std::env::var_os("NO_SUDO").is_some() {
let mut out = Self::new("su");
+ out.ssh_session = self.ssh_session.take();
out.arg("-c").arg(self.into_string());
out
} else {
@@ -144,27 +183,38 @@
out
}
}
- pub fn ssh(self, on: impl AsRef<OsStr>) -> Self {
+ pub fn ssh_session(mut self, on: Arc<Session>) -> Self {
+ self.ssh_session = Some(on);
+ self
+ }
+ pub fn ssh(mut self, on: impl AsRef<OsStr>) -> Self {
let mut out = Self::new("ssh");
+ out.ssh_session = self.ssh_session.take();
out.arg(on).arg("--");
out.arg(self.into_string());
out
}
- pub fn over_ssh(mut self, session: Arc<Session>) -> Self {
- self.ssh_session = Some(session);
- self
- }
pub async fn run(self) -> Result<()> {
let str = self.clone().into_string();
- let cmd = self.into_command();
- run_nix_inner(str, cmd, &mut PlainHandler).await?;
+ let cmd = self.into_command_new()?;
+ match cmd {
+ Either::Left(cmd) => run_nix_inner(str, cmd, &mut PlainHandler).await?,
+ Either::Right(cmd) => run_nix_inner_ssh(str, cmd, &mut PlainHandler).await?,
+ };
Ok(())
}
pub async fn run_string(self) -> Result<String> {
+ let bytes = self.run_bytes().await?;
+ Ok(String::from_utf8(bytes)?)
+ }
+ pub async fn run_bytes(self) -> Result<Vec<u8>> {
let str = self.clone().into_string();
- let cmd = self.into_command();
- let v = run_nix_inner_stdout(str, cmd, &mut PlainHandler).await?;
+ let cmd = self.into_command_new()?;
+ let v = match cmd {
+ Either::Left(cmd) => run_nix_inner_stdout(str, cmd, &mut PlainHandler).await?,
+ Either::Right(cmd) => run_nix_inner_stdout_ssh(str, cmd, &mut PlainHandler).await?,
+ };
Ok(v)
}
@@ -172,7 +222,8 @@
let str = self.clone().into_string();
let mut cmd = self.into_command();
cmd.arg("--log-format").arg("internal-json");
- run_nix_inner_stdout(str, cmd, &mut NixHandler::default()).await
+ let bytes = run_nix_inner_stdout(str, cmd, &mut NixHandler::default()).await?;
+ Ok(String::from_utf8(bytes)?)
}
pub async fn run_nix(self) -> Result<()> {
let str = self.clone().into_string();
@@ -198,7 +249,7 @@
str: String,
cmd: Command,
handler: &mut dyn Handler,
-) -> Result<String> {
+) -> Result<Vec<u8>> {
Ok(run_nix_inner_raw(str, cmd, true, handler, None)
.await?
.expect("has out"))
@@ -208,6 +259,24 @@
assert!(v.is_none());
Ok(())
}
+async fn run_nix_inner_stdout_ssh(
+ str: String,
+ cmd: OwningCommand<Arc<Session>>,
+ handler: &mut dyn Handler,
+) -> Result<Vec<u8>> {
+ Ok(run_nix_inner_raw_ssh(str, cmd, true, handler, None)
+ .await?
+ .expect("has out"))
+}
+async fn run_nix_inner_ssh(
+ str: String,
+ cmd: OwningCommand<Arc<Session>>,
+ handler: &mut dyn Handler,
+) -> Result<()> {
+ let v = run_nix_inner_raw_ssh(str, cmd, false, handler, None).await?;
+ assert!(v.is_none());
+ Ok(())
+}
pub trait Handler: Send {
fn handle_line(&mut self, e: &str);
@@ -468,7 +537,7 @@
want_stdout: bool,
err_handler: &mut dyn Handler,
mut out_handler: Option<&mut dyn Handler>,
-) -> Result<Option<String>> {
+) -> Result<Option<Vec<u8>>> {
cmd.stderr(Stdio::piped());
cmd.stdout(Stdio::piped());
let mut child = cmd.spawn()?;
@@ -522,7 +591,71 @@
}
}
- Ok(out_buf.map(String::from_utf8).transpose()?)
+ Ok(out_buf)
+}
+async fn run_nix_inner_raw_ssh(
+ str: String,
+ mut cmd: OwningCommand<Arc<Session>>,
+ want_stdout: bool,
+ err_handler: &mut dyn Handler,
+ mut out_handler: Option<&mut dyn Handler>,
+) -> Result<Option<Vec<u8>>> {
+ cmd.stderr(openssh::Stdio::piped());
+ cmd.stdout(openssh::Stdio::piped());
+ let mut child = cmd.spawn().await?;
+ let mut stderr = child.stderr().take().unwrap();
+ let stdout = child.stdout().take().unwrap();
+ let mut err = FramedRead::new(&mut stderr, LinesCodec::new());
+ let mut out: Option<Box<dyn AsyncRead + Unpin>> = Some(Box::new(stdout));
+ let mut ob = want_stdout
+ .then(|| out.take().unwrap())
+ .unwrap_or_else(|| Box::new(EmptyAsyncRead));
+ let mut ol = (!want_stdout)
+ .then(|| out.take().unwrap())
+ .unwrap_or_else(|| Box::new(EmptyAsyncRead));
+ let mut ob = FramedRead::new(&mut ob, BytesCodec::new());
+ let mut ol = FramedRead::new(&mut ol, LinesCodec::new());
+
+ // while let Some(line) = read.next().await? {}
+
+ let mut out_buf = if want_stdout { Some(vec![]) } else { None };
+
+ let mut wait_future = pin::pin!(child.wait());
+ loop {
+ select! {
+ e = err.next() => {
+ if let Some(e) = e {
+ let e = e?;
+ err_handler.handle_line(&e);
+ }
+ },
+ o = ob.next() => {
+ if let Some(o) = o {
+ out_buf.as_mut().expect("stdout == wants_stdout").extend_from_slice(&o?);
+ }
+ },
+ o = ol.next() => {
+ if let Some(o) = o {
+ let o = o?;
+ if let Some(out) = out_handler.as_mut() {
+ out.handle_line(&o)
+ } else {
+ err_handler.handle_line(&o)
+ }
+ // out_handler.handle_info(&o);
+ }
+ },
+ code = &mut wait_future => {
+ let code = code?;
+ if !code.success() {
+ anyhow::bail!("command '{str}' failed with status {}", code);
+ }
+ break;
+ }
+ }
+ }
+
+ Ok(out_buf)
}
pub trait ErrorRecorder: Send {
cmds/fleet/src/host.rsdiffbeforeafterboth1use std::{2 env::current_dir,3 ffi::{OsStr, OsString},4 io::Write,5 ops::Deref,6 path::PathBuf,7 sync::{Arc, Mutex, MutexGuard, OnceLock},8};910use anyhow::{anyhow, bail, Context, Result};11use clap::{ArgGroup, Parser};12use openssh::SessionBuilder;13use tempfile::NamedTempFile;1415use crate::{16 better_nix_eval::{Field, NixSessionPool},17 command::MyCommand,18 fleetdata::{FleetData, FleetSecret, FleetSharedSecret},19 nix_go, nix_go_json,20};2122pub struct FleetConfigInternals {23 pub local_system: String,24 pub directory: PathBuf,25 pub opts: FleetOpts,26 pub data: Mutex<FleetData>,27 pub nix_args: Vec<OsString>,28 /// fleetConfigurations.<name>.<localSystem>29 pub fleet_field: Field,30 /// fleet_config.configUnchecked31 pub config_field: Field,32 /// fleet_config.unchecked33 pub config_unchecked_field: Field,34}3536#[derive(Clone)]37pub struct Config(Arc<FleetConfigInternals>);3839impl Deref for Config {40 type Target = FleetConfigInternals;4142 fn deref(&self) -> &Self::Target {43 &self.044 }45}4647pub struct ConfigHost {48 pub name: String,49 pub session: OnceLock<Arc<openssh::Session>>,50}51impl ConfigHost {52 pub async fn open_session(&self) -> Result<Arc<openssh::Session>> {53 // FIXME: TOCTOU54 if let Some(session) = &self.session.get() {55 return Ok((*session).clone());56 };57 let session = SessionBuilder::default();5859 let session = session60 .connect(&self.name)61 .await62 .map_err(|e| anyhow!("ssh error: {e}"))?;63 let session = Arc::new(session);64 self.session.set(session.clone()).expect("TOCTOU happened");65 Ok(session)66 }67 pub async fn mktemp_dir(&self) -> Result<String> {68 let mut cmd = self.cmd("mktemp").await?;69 cmd.arg("-d");70 let path = cmd.run_string().await?;71 Ok(path.trim_end().to_owned())72 }73 pub async fn read_file_bin(&self, path: impl AsRef<OsStr>) -> Result<Vec<u8>> {74 let mut cmd = self.cmd("cat").await?;75 cmd.arg(path);76 cmd.run_bytes().await77 }78 pub async fn read_file_text(&self, path: impl AsRef<OsStr>) -> Result<String> {79 let mut cmd = self.cmd("cat").await?;80 cmd.arg(path);81 cmd.run_string().await82 }83 pub async fn cmd(&self, cmd: impl AsRef<OsStr>) -> Result<MyCommand> {84 let session = self.open_session().await?;85 Ok(MyCommand::new_on(cmd, session))86 }8788 pub async fn decrypt(&self, data: Vec<u8>) -> Result<Vec<u8>> {89 let mut cmd = self.cmd("fleet-install-secrets").await?;90 cmd.arg("decrypt").eqarg("--secret", z85::encode(&data));91 let encoded = cmd92 .sudo()93 .run_string()94 .await95 .context("failed to call remote host for decrypt")?;96 z85::decode(encoded.trim_end()).context("bad encoded data? outdated host?")97 }98}99100impl Config {101 pub fn should_skip(&self, host: &str) -> bool {102 if !self.opts.skip.is_empty() {103 self.opts.skip.iter().any(|h| h as &str == host)104 } else if !self.opts.only.is_empty() {105 !self.opts.only.iter().any(|h| h as &str == host)106 } else {107 false108 }109 }110 pub fn is_local(&self, host: &str) -> bool {111 self.opts.localhost.as_ref().map(|s| s as &str) == Some(host)112 }113114 pub async fn run_on(&self, host: &str, mut command: MyCommand, sudo: bool) -> Result<()> {115 if sudo {116 command = command.sudo();117 }118 if !self.is_local(host) {119 command = command.ssh(host);120 }121 command.run().await122 }123 pub async fn run_string_on(124 &self,125 host: &str,126 mut command: MyCommand,127 sudo: bool,128 ) -> Result<String> {129 if sudo {130 command = command.sudo();131 }132 if !self.is_local(host) {133 command = command.ssh(host);134 }135 command.run_string().await136 }137138 pub async fn host(&self, name: &str) -> Result<ConfigHost> {139 Ok(ConfigHost {140 name: name.to_owned(),141 session: OnceLock::new(),142 })143 }144 pub async fn list_hosts(&self) -> Result<Vec<ConfigHost>> {145 let fleet_field = &self.fleet_field;146 let names = nix_go!(fleet_field.configuredHosts).list_fields().await?;147 let mut out = vec![];148 for name in names {149 out.push(ConfigHost {150 name,151 session: OnceLock::new(),152 })153 }154 Ok(out)155 }156 pub async fn system_config(&self, host: &str) -> Result<Field> {157 let fleet_field = &self.fleet_field;158 Ok(nix_go!(fleet_field.configuredSystems[{ host }].config))159 }160161 pub(super) fn data(&self) -> MutexGuard<FleetData> {162 self.data.lock().unwrap()163 }164 pub(super) fn data_mut(&self) -> MutexGuard<FleetData> {165 self.data.lock().unwrap()166 }167 /// Shared secrets configured in fleet.nix or in flake168 pub async fn list_configured_shared(&self) -> Result<Vec<String>> {169 let config_field = &self.config_field;170 nix_go!(config_field.sharedSecrets).list_fields().await171 }172 /// Shared secrets configured in fleet.nix173 pub fn list_shared(&self) -> Vec<String> {174 let data = self.data();175 data.shared_secrets.keys().cloned().collect()176 }177 pub fn has_shared(&self, name: &str) -> bool {178 let data = self.data();179 data.shared_secrets.contains_key(name)180 }181 pub fn replace_shared(&self, name: String, shared: FleetSharedSecret) {182 let mut data = self.data_mut();183 data.shared_secrets.insert(name.to_owned(), shared);184 }185 pub fn remove_shared(&self, secret: &str) {186 let mut data = self.data_mut();187 data.shared_secrets.remove(secret);188 }189190 pub fn has_secret(&self, host: &str, secret: &str) -> bool {191 let data = self.data();192 let Some(host_secrets) = data.host_secrets.get(host) else {193 return false;194 };195 host_secrets.contains_key(secret)196 }197 pub fn insert_secret(&self, host: &str, secret: String, value: FleetSecret) {198 let mut data = self.data_mut();199 let host_secrets = data.host_secrets.entry(host.to_owned()).or_default();200 host_secrets.insert(secret, value);201 }202203 pub async fn reencrypt_on_host(204 &self,205 host: &str,206 data: Vec<u8>,207 targets: Vec<String>,208 ) -> Result<Vec<u8>> {209 let data = z85::encode(&data);210 let mut recmd = MyCommand::new("fleet-install-secrets");211 recmd.arg("reencrypt").eqarg("--secret", data);212 for target in targets {213 recmd.eqarg("--targets", target);214 }215 recmd = recmd.sudo().ssh(host);216 let encoded = recmd217 .run_string()218 .await219 .context("failed to call remote host for decrypt")?220 .trim()221 .to_owned();222 z85::decode(encoded).context("bad encoded data? outdated host?")223 }224225 pub fn host_secret(&self, host: &str, secret: &str) -> Result<FleetSecret> {226 let data = self.data();227 let Some(host_secrets) = data.host_secrets.get(host) else {228 bail!("no secrets for machine {host}");229 };230 let Some(secret) = host_secrets.get(secret) else {231 bail!("machine {host} has no secret {secret}");232 };233 Ok(secret.clone())234 }235 pub fn shared_secret(&self, secret: &str) -> Result<FleetSharedSecret> {236 let data = self.data();237 let Some(secret) = data.shared_secrets.get(secret) else {238 bail!("no shared secret {secret}");239 };240 Ok(secret.clone())241 }242 pub async fn shared_secret_expected_owners(&self, secret: &str) -> Result<Vec<String>> {243 let config_field = &self.config_field;244 Ok(nix_go_json!(245 config_field.sharedSecrets[{ secret }].expectedOwners246 ))247 }248249 pub fn save(&self) -> Result<()> {250 let mut tempfile = NamedTempFile::new_in(self.directory.clone())?;251 let data = nixlike::serialize(&self.data() as &FleetData)?;252 tempfile.write_all(253 format!(254 "# This file contains fleet state and shouldn't be edited by hand\n\n{}\n\n# vim: ts=2 et nowrap\n",255 data256 )257 .as_bytes(),258 )?;259 let mut fleet_data_path = self.directory.clone();260 fleet_data_path.push("fleet.nix");261 tempfile.persist(fleet_data_path)?;262 Ok(())263 }264}265266#[derive(Parser, Clone)]267#[clap(group = ArgGroup::new("target_hosts"))]268pub struct FleetOpts {269 /// All hosts except those would be skipped270 #[clap(long, number_of_values = 1, group = "target_hosts")]271 only: Vec<String>,272273 /// Hosts to skip274 #[clap(long, number_of_values = 1, group = "target_hosts")]275 skip: Vec<String>,276277 /// Host, which should be threaten as current machine278 #[clap(long)]279 pub localhost: Option<String>,280281 /// Override detected system for host, to perform builds via282 /// binfmt-declared qemu instead of trying to crosscompile283 #[clap(long, default_value = "detect")]284 pub local_system: String,285}286287impl FleetOpts {288 pub async fn build(mut self, nix_args: Vec<OsString>) -> Result<Config> {289 if self.localhost.is_none() {290 self.localhost291 .replace(hostname::get().unwrap().to_str().unwrap().to_owned());292 }293 let directory = current_dir()?;294295 let pool = NixSessionPool::new(directory.as_os_str().to_owned(), nix_args.clone()).await?;296 let root_field = pool.get().await?;297298 if self.local_system == "detect" {299 let builtins_field = Field::field(root_field.clone(), "builtins").await?;300 self.local_system = nix_go_json!(builtins_field.currentSystem);301 }302 let local_system = self.local_system.clone();303304 let fleet_root = Field::field(root_field, "fleetConfigurations").await?;305306 let fleet_field = nix_go!(fleet_root.default);307 let config_field = nix_go!(fleet_field.configUnchecked);308 let config_unchecked_field = nix_go!(fleet_field.unchecked);309310 let mut fleet_data_path = directory.clone();311 fleet_data_path.push("fleet.nix");312 let bytes = std::fs::read_to_string(fleet_data_path)?;313 let data = nixlike::parse_str(&bytes)?;314315 Ok(Config(Arc::new(FleetConfigInternals {316 opts: self,317 directory,318 data,319 local_system,320 nix_args,321 fleet_field,322 config_field,323 config_unchecked_field,324 })))325 }326}nixos/meta.nixdiffbeforeafterboth--- a/nixos/meta.nix
+++ b/nixos/meta.nix
@@ -1,11 +1,18 @@
-{ lib, ... }:
-with lib;
{
+ lib,
+ pkgs,
+ ...
+}:
+with lib; {
options = with types; {
+ nixpkgs.resolvedPkgs = mkOption {
+ type = types.pkgs // {description = "nixpkgs.pkgs";};
+ description = "Value of pkgs";
+ };
tags = mkOption {
type = listOf str;
description = "Host tags";
- default = [ ];
+ default = [];
};
network = mkOption {
type = submodule {
@@ -13,12 +20,12 @@
internalIps = mkOption {
type = listOf str;
description = "Internal ips";
- default = [ ];
+ default = [];
};
externalIps = mkOption {
type = listOf str;
description = "External ips";
- default = [ ];
+ default = [];
};
};
};
@@ -29,7 +36,8 @@
};
};
config = {
- tags = [ "all" ];
- network = { };
+ tags = ["all"];
+ network = {};
+ nixpkgs.resolvedPkgs = pkgs;
};
}