key: Compute full path to key file in Nix

This commit is contained in:
Zhaofeng Li 2022-01-25 14:22:26 -08:00
parent e58dde1be0
commit f674ddf173
4 changed files with 15 additions and 5 deletions

View file

@ -212,7 +212,7 @@ let
}; };
}; };
keyType = { lib, name, ... }: let keyType = { lib, name, config, ... }: let
inherit (lib) types; inherit (lib) types;
in { in {
options = { options = {
@ -255,7 +255,15 @@ let
Destination directory on the host. Destination directory on the host.
''; '';
default = "/run/keys"; default = "/run/keys";
type = types.str; type = types.path;
};
path = lib.mkOption {
description = ''
Full path to the destination.
'';
default = "${config.destDir}/${config.name}";
type = types.path;
internal = true;
}; };
user = lib.mkOption { user = lib.mkOption {
description = '' description = ''

View file

@ -119,7 +119,7 @@ impl Local {
} }
let path = key.path(); let path = key.path();
let key_script = format!("'{}'", key_uploader::generate_script(key, &path, require_ownership)); let key_script = format!("'{}'", key_uploader::generate_script(key, path, require_ownership));
let mut command = Command::new("sh"); let mut command = Command::new("sh");

View file

@ -220,7 +220,7 @@ impl Ssh {
} }
let path = key.path(); let path = key.path();
let key_script = key_uploader::generate_script(key, &path, require_ownership); let key_script = key_uploader::generate_script(key, path, require_ownership);
let mut command = self.ssh(&["sh", "-c", &key_script]); let mut command = self.ssh(&["sh", "-c", &key_script]);

View file

@ -91,6 +91,8 @@ pub enum UploadAt {
pub struct Key { pub struct Key {
name: String, name: String,
path: PathBuf,
#[serde(flatten)] #[serde(flatten)]
source: KeySource, source: KeySource,
@ -146,7 +148,7 @@ impl Key {
} }
} }
pub fn path(&self) -> PathBuf { self.dest_dir.join(&self.name) } pub fn path(&self) -> &Path { &self.path }
pub fn user(&self) -> &str { &self.user } pub fn user(&self) -> &str { &self.user }
pub fn group(&self) -> &str { &self.group } pub fn group(&self) -> &str { &self.group }
pub fn permissions(&self) -> &str { &self.permissions } pub fn permissions(&self) -> &str { &self.permissions }