diff options
| author | Andrew Childs <lorne@cons.org.nz> | 2018-10-25 00:30:34 +0900 |
|---|---|---|
| committer | Andrew Childs <lorne@cons.org.nz> | 2018-10-25 01:00:52 +0900 |
| commit | 676ef103771aa3fc4b150290294b8ad5610d2750 (patch) | |
| tree | a208b52ff962a4f0cfc0041cd5f473f6795a07dc /modules | |
| parent | e6a698a7011487f16dd061d65e36ec330465ed16 (diff) | |
Unify environment configuration and don't run in child shells
This should enable `nix run` to work under shells like fish and zsh,
as well as making child shells not needlessly reset any environment
that should be inherited.
Implementation adapted from NixOS.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/environment/default.nix | 4 | ||||
| -rw-r--r-- | modules/programs/bash/default.nix | 5 | ||||
| -rw-r--r-- | modules/programs/fish.nix | 5 | ||||
| -rw-r--r-- | modules/programs/zsh/default.nix | 8 |
4 files changed, 13 insertions, 9 deletions
diff --git a/modules/environment/default.nix b/modules/environment/default.nix index 6d77cd6..8ba0735 100644 --- a/modules/environment/default.nix +++ b/modules/environment/default.nix @@ -184,6 +184,10 @@ in { }; system.build.setEnvironment = pkgs.writeText "set-environment" '' + # Prevent this file from being sourced by child shells. + export __NIX_DARWIN_SET_ENVIRONMENT_DONE=1 + + export PATH=${config.environment.systemPath} ${concatStringsSep "\n" exportVariables} # Extra initialisation diff --git a/modules/programs/bash/default.nix b/modules/programs/bash/default.nix index ea5afe2..6f5c8e7 100644 --- a/modules/programs/bash/default.nix +++ b/modules/programs/bash/default.nix @@ -61,8 +61,9 @@ in # Don't execute this file when running in a pure nix-shell. if test -n "$IN_NIX_SHELL"; then return; fi - export PATH=${config.environment.systemPath} - ${config.system.build.setEnvironment.text} + if [ -z "$__NIX_DARWIN_SET_ENVIRONMENT_DONE" ]; then + . ${config.system.build.setEnvironment} + fi # Return early if not running interactively, but after basic nix setup. [[ $- != *i* ]] && return diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix index 6ee5355..470dcac 100644 --- a/modules/programs/fish.nix +++ b/modules/programs/fish.nix @@ -109,8 +109,9 @@ in set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $__fish_datadir/functions # source the NixOS environment config - fenv export PATH=${config.environment.systemPath} - fenv source ${config.system.build.setEnvironment} + if [ -z "$__NIX_DARWIN_SET_ENVIRONMENT_DONE" ] + fenv source ${config.system.build.setEnvironment} + end # clear fish_function_path so that it will be correctly set when we return to $__fish_datadir/config.fish set -e fish_function_path diff --git a/modules/programs/zsh/default.nix b/modules/programs/zsh/default.nix index de90433..4d5559a 100644 --- a/modules/programs/zsh/default.nix +++ b/modules/programs/zsh/default.nix @@ -120,8 +120,9 @@ in # Don't execute this file when running in a pure nix-shell. if test -n "$IN_NIX_SHELL"; then return; fi - export PATH=${config.environment.systemPath} - ${config.system.build.setEnvironment.text} + if [ -z "$__NIX_DARWIN_SET_ENVIRONMENT_DONE" ]; then + . ${config.system.build.setEnvironment} + fi ${cfg.shellInit} @@ -158,9 +159,6 @@ in if [ -n "$__ETC_ZSHRC_SOURCED" -o -n "$NOSYSZSHRC" ]; then return; fi __ETC_ZSHRC_SOURCED=1 - # Also set to fix `nix run` shells. - __ETC_BASHRC_SOURCED=1 - # history defaults SAVEHIST=2000 HISTSIZE=2000 |
