diff --git a/src/installable.rs b/src/installable.rs index e9d4cb5..307585b 100644 --- a/src/installable.rs +++ b/src/installable.rs @@ -1,5 +1,5 @@ -use std::env; use std::path::PathBuf; +use std::{env, fs}; use clap::error::ErrorKind; use clap::{Arg, ArgAction, Args, FromArgMatches}; @@ -17,10 +17,9 @@ pub enum Installable { path: PathBuf, attribute: Vec, }, - // TODO: - // Store { - // path: PathBuf, - // }, + Store { + path: PathBuf, + }, Expression { expression: String, attribute: Vec, @@ -38,6 +37,16 @@ impl FromArgMatches for Installable { let file = matches.get_one::("file"); let expr = matches.get_one::("expr"); + if let Some(i) = installable { + let canonincal = fs::canonicalize(i); + + if let Ok(p) = canonincal { + if p.starts_with("/nix/store") { + return Ok(Self::Store { path: p }); + } + } + } + if let Some(f) = file { return Ok(Self::File { path: PathBuf::from(f), @@ -123,6 +132,9 @@ Nix accepts various kinds of installables: {}, {} [ATTRPATH] Nix expression with an optional attribute path. + +[PATH] + Path or symlink to a /nix/store path "#, env::var("NH_FLAKE").unwrap_or_default(), "-f".yellow(), @@ -181,6 +193,7 @@ impl Installable { res.push(expression.to_string()); res.push(join_attribute(attribute)); } + Installable::Store { path } => res.push(path.to_str().unwrap().to_string()), } res diff --git a/src/nixos.rs b/src/nixos.rs index 1bd8e57..0601553 100644 --- a/src/nixos.rs +++ b/src/nixos.rs @@ -185,6 +185,7 @@ fn toplevel_for>(hostname: S, installable: Installable) -> Install } => { attribute.extend(toplevel); } + Installable::Store { .. } => {} } res @@ -194,6 +195,10 @@ impl OsReplArgs { fn run(self) -> Result<()> { let mut target_installable = self.installable; + if matches!(target_installable, Installable::Store { .. }) { + bail!("Nix doesn't support nix store installables."); + } + let hostname = self .hostname .unwrap_or_else(|| hostname::get().unwrap().to_str().unwrap().to_string());