session-init: only add to NIX_PATH if value is not present yet

This commit is contained in:
Tobias Happ 2021-12-14 20:11:57 +01:00
parent dcd8c07cd8
commit bb8470da1d

View file

@ -11,6 +11,12 @@ let
exportAll = vars: concatStringsSep "\n" (mapAttrsToList export vars);
addToNixPath = nixPathEntry: ''
if [[ ":$NIX_PATH:" != *":${nixPathEntry}:"* ]]; then
export NIX_PATH="${nixPathEntry}''${NIX_PATH:+:}$NIX_PATH"
fi
'';
sessionInit = pkgs.writeTextFile {
name = "nix-on-droid-session-init.sh";
destination = "/etc/profile.d/nix-on-droid-session-init.sh";
@ -22,7 +28,9 @@ let
. $HOME/.nix-profile/etc/profile.d/nix.sh
# workaround for nix 2.4, see https://github.com/NixOS/nixpkgs/issues/149791
export NIX_PATH=$HOME/.nix-defexpr/channels''${NIX_PATH:+:}$NIX_PATH
${addToNixPath "${config.user.home}/.nix-defexpr/channels"}
# Workaround for https://github.com/NixOS/nix/issues/1865
${addToNixPath "nixpkgs=${config.user.home}/.nix-defexpr/channels/nixpkgs/"}
${optionalString (config.home-manager.config != null) ''
if [ -e "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then
@ -30,9 +38,6 @@ let
fi
''}
# Workaround for https://github.com/NixOS/nix/issues/1865
export NIX_PATH=nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs/:$NIX_PATH
${exportAll cfg.sessionVariables}
'';
};