Skip to content

Commit

Permalink
Export $__ETC_PROFILE_NIX_SOURCED when running nix and nix-shell (
Browse files Browse the repository at this point in the history
#31)

Partial fix for #25.

Ping @rrbutani @P1n3appl3.
  • Loading branch information
9999years authored Jul 6, 2023
1 parent 5fe66d4 commit 2bd9b33
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ mod shell;
use shell::Shell;
use shell::ShellKind;

/// Environment variable that indicates that the Nix profile has already been sourced.
///
/// This is set when a Nix profile script is sourced:
/// - `$HOME/.nix-profile/etc/profile.d/nix.sh`
/// - `/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh`
///
/// We export this variable to prevent the profile script from being sourced twice, clobbering the
/// `$PATH`.
///
/// See: <https://github.com/MercuryTechnologies/nix-your-shell/issues/25>
const NIX_SOURCED_VAR: &str = "__ETC_PROFILE_NIX_SOURCED";

/// A `nix` and `nix-shell` wrapper for shells other than `bash`.
///
/// Use by adding `nix-your-shell | source` to your shell configuration.
Expand Down Expand Up @@ -110,13 +122,18 @@ fn main() -> eyre::Result<()> {
let new_args = transform_nix_shell(args, shell.path.as_str());
Err(process::Command::new("nix-shell")
.args(new_args)
.env(NIX_SOURCED_VAR, "1")
.exec()
.into())
}

Command::Nix { args } => {
let new_args = transform_nix(args, shell.path.as_str());
Err(process::Command::new("nix").args(new_args).exec().into())
Err(process::Command::new("nix")
.args(new_args)
.env(NIX_SOURCED_VAR, "1")
.exec()
.into())
}
}
}
Expand Down

0 comments on commit 2bd9b33

Please sign in to comment.