forked from DGNum/colmena
repl: Add arguments depending on Nix version
This commit is contained in:
parent
741d5c4fbb
commit
3fbc5eeb11
2 changed files with 26 additions and 7 deletions
|
@ -5,6 +5,7 @@ use tempfile::Builder as TempFileBuilder;
|
|||
use tokio::process::Command;
|
||||
|
||||
use crate::error::ColmenaError;
|
||||
use crate::nix::info::NixCheck;
|
||||
use crate::util;
|
||||
|
||||
pub fn subcommand() -> ClapCommand<'static> {
|
||||
|
@ -20,6 +21,9 @@ attribute set."#,
|
|||
}
|
||||
|
||||
pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), ColmenaError> {
|
||||
let nix_check = NixCheck::detect().await;
|
||||
let nix_version = nix_check.version().expect("Could not detect Nix version");
|
||||
|
||||
let hive = util::hive_from_args(local_args).await?;
|
||||
|
||||
let expr = hive.get_repl_expression();
|
||||
|
@ -31,14 +35,21 @@ pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(
|
|||
|
||||
expr_file.write_all(expr.as_bytes())?;
|
||||
|
||||
let status = Command::new("nix")
|
||||
.arg("repl")
|
||||
let mut repl_cmd = Command::new("nix");
|
||||
|
||||
repl_cmd.arg("repl");
|
||||
|
||||
if nix_version.at_least(2, 4) {
|
||||
// `nix repl` is expected to be marked as experimental:
|
||||
// <https://github.com/NixOS/nix/issues/5604>
|
||||
.args(&["--experimental-features", "nix-command flakes"])
|
||||
.arg(expr_file.path())
|
||||
.status()
|
||||
.await?;
|
||||
repl_cmd.args(&["--experimental-features", "nix-command flakes"]);
|
||||
}
|
||||
|
||||
if nix_version.at_least(2, 10) {
|
||||
repl_cmd.arg("--file");
|
||||
}
|
||||
|
||||
let status = repl_cmd.arg(expr_file.path()).status().await?;
|
||||
|
||||
if !status.success() {
|
||||
return Err(status.into());
|
||||
|
|
|
@ -7,7 +7,7 @@ use tokio::process::Command;
|
|||
|
||||
use super::{ColmenaError, ColmenaResult};
|
||||
|
||||
struct NixVersion {
|
||||
pub struct NixVersion {
|
||||
major: usize,
|
||||
minor: usize,
|
||||
string: String,
|
||||
|
@ -37,6 +37,10 @@ impl NixVersion {
|
|||
fn has_flakes(&self) -> bool {
|
||||
self.major > 2 || (self.major == 2 && self.minor >= 4)
|
||||
}
|
||||
|
||||
pub fn at_least(&self, major: usize, minor: usize) -> bool {
|
||||
self.major >= major && self.minor >= minor
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for NixVersion {
|
||||
|
@ -147,4 +151,8 @@ impl NixCheck {
|
|||
pub fn flakes_supported(&self) -> bool {
|
||||
self.flakes_supported
|
||||
}
|
||||
|
||||
pub fn version(&self) -> Option<&NixVersion> {
|
||||
self.version.as_ref()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue