Skip to content

Commit

Permalink
BREAKING: don't load etc/profile.d/*.sh by default (#155)
Browse files Browse the repository at this point in the history
Fixes #26

To get the old behaviour back, set `devshell.load_profiles` to
`true`.

Future improvements might be to explicitly list which profiles should be
loaded.
  • Loading branch information
zimbatm authored Dec 13, 2021
1 parent 0e56ef2 commit 850f838
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
20 changes: 11 additions & 9 deletions modules/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ in
'';
};

load_profiles = mkEnableOption "load etc/profiles.d/*.sh in the shell";

name = mkOption {
type = types.str;
default = "devshell";
Expand Down Expand Up @@ -231,14 +233,6 @@ in
package = devshell_dir;

startup = {
load_profiles = noDepEntry ''
# Load installed profiles
for file in "$DEVSHELL_DIR/etc/profile.d/"*.sh; do
# If that folder doesn't exist, bash loves to return the whole glob
[[ -f "$file" ]] && source "$file"
done
'';

motd = noDepEntry ''
__devshell-motd() {
cat <<DEVSHELL_PROMPT
Expand All @@ -261,7 +255,15 @@ in
PROMPT_COMMAND=__devshell-prompt''${PROMPT_COMMAND+;$PROMPT_COMMAND}
fi
'';
};
} // (optionalAttrs cfg.load_profiles {
load_profiles = lib.noDepEntry ''
# Load installed profiles
for file in "$DEVSHELL_DIR/etc/profile.d/"*.sh; do
# If that folder doesn't exist, bash loves to return the whole glob
[[ -f "$file" ]] && source "$file"
done
'';
});

interactive = {
PS1_util = noDepEntry ''
Expand Down
25 changes: 25 additions & 0 deletions tests/core/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,29 @@
# Adds packages to the PATH
type -p git
'';

# Only load profiles
devshell-load-profiles-1 =
let
fakeProfile = pkgs.writeTextFile {
name = "fake_profile.sh";
destination = "/etc/profile.d/fake_profile.sh";
text = ''
export FAKE_PROFILE=1
'';
};

shell = devshell.mkShell {
devshell.name = "devshell-1";
devshell.load_profiles = true;
devshell.packages = [ fakeProfile ];
};
in
runTest "devshell-load-profiles-1" { } ''
# Load the devshell
source ${shell}/env.bash
# Check that the profile got loaded
assert "$FAKE_PROFILE" == "1"
'';
}

0 comments on commit 850f838

Please sign in to comment.