From a30773abedd43e5aa21d3855f5807cb33d185277 Mon Sep 17 00:00:00 2001 From: Tom van Dijk <18gatenmaker6@gmail.com> Date: Sat, 19 Jul 2025 19:52:13 +0200 Subject: [PATCH] feat: use `nix3-profile` if it has to with `-i` Because `nix-env` and `nix3-profile` cannot be used together, I added a check for `~/.local/state/nix/profiles/profile` and if it exists, it will install the target package through `nix profile install` instead of `nix-env -iA`. --- src/main.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index cdd04a0..663ea49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -324,9 +324,27 @@ fn main() -> ExitCode { .contains("nixpkgs="); if args.install { - let _ = Command::new("nix-env") - .args(["-f", "", "-iA", basename]) - .exec(); + if Command::new("nix") + .args(["profile", "list"]) + .output() + .is_ok_and(|x| !x.stdout.trim_ascii().is_empty()) + { + let _ = Command::new("nix") + .args([ + "profile", + "install", + format!("{}#{basename}", args.nixpkgs_flake).as_str(), + ]) + .env( + "NIX_CONFIG", + "extra-experimental-features = nix-command flakes", + ) + .exec(); + } else { + let _ = Command::new("nix-env") + .args(["-f", "", "-iA", basename]) + .exec(); + } } else if args.shell { // TODO: use cache here, but this is tricky since it actually depends in `nix-shell` let shell_cmd = shell::select_shell_from_pid(process::id()).unwrap_or("bash".into());