1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-04-09 10:42:53 +00:00

Merge pull request #111 from thefloweringash/shell-child-env

Unify environment configuration and don't run in child shells
This commit is contained in:
Daiderd Jordan 2018-10-29 11:32:10 +00:00 committed by GitHub
commit 2412c7f9f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 53 additions and 51 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -108,10 +108,10 @@ let
tests.services-synergy = makeTest ./tests/services-synergy.nix;
tests.services-privoxy = makeTest ./tests/services-privoxy.nix;
tests.system-defaults-write = makeTest ./tests/system-defaults-write.nix;
tests.system-environment = makeTest ./tests/system-environment.nix;
tests.system-keyboard-mapping = makeTest ./tests/system-keyboard-mapping.nix;
tests.system-packages = makeTest ./tests/system-packages.nix;
tests.system-path-bash = makeTest ./tests/system-path-bash.nix;
tests.system-path-fish = makeTest ./tests/system-path-fish.nix;
tests.system-path = makeTest ./tests/system-path.nix;
tests.system-shells = makeTest ./tests/system-shells.nix;
tests.users-groups = makeTest ./tests/users-groups.nix;
tests.fonts = makeTest ./tests/fonts.nix;

View file

@ -3,13 +3,11 @@
with lib;
{
programs.bash.enable = true;
test = ''
echo checking /run/current-system/sw/bin in systemPath >&2
grep 'export PATH=.*:/run/current-system/sw/bin' ${config.out}/etc/bashrc
echo checking /run/current-system/sw/bin in setEnvironment >&2
grep 'export PATH=.*:/run/current-system/sw/bin' ${config.system.build.setEnvironment}
echo checking /bin and /sbin in systemPath >&2
grep 'export PATH=.*:/usr/bin:/usr/sbin:/bin:/sbin' ${config.out}/etc/bashrc
echo checking /bin and /sbin in setEnvironment >&2
grep 'export PATH=.*:/usr/bin:/usr/sbin:/bin:/sbin' ${config.system.build.setEnvironment}
'';
}

View file

@ -20,10 +20,10 @@
echo >&2 "checking for share/zsh in /sw"
test -e ${config.out}/sw/share/zsh
echo >&2 "checking environment.systemPath in /etc/zshenv"
grep 'export PATH=${pkgs.hello}/bin' ${config.out}/etc/zshenv
echo >&2 "checking SHELL in /etc/zshenv"
grep 'export SHELL="${pkgs.zsh}/bin/zsh"' ${config.out}/etc/zshenv
echo >&2 "checking setEnvironment in /etc/zshenv"
fgrep '. ${config.system.build.setEnvironment}' ${config.out}/etc/zshenv
echo >&2 "checking SHELL in setEnvironment"
grep 'export SHELL="${pkgs.zsh}/bin/zsh"' ${config.system.build.setEnvironment}
echo >&2 "checking nix-shell return /etc/zshenv"
grep 'if test -n "$IN_NIX_SHELL"; then return; fi' ${config.out}/etc/zshenv
echo >&2 "checking zshenv.d in /etc/zshenv"

View file

@ -8,8 +8,6 @@ in
services.nix-daemon.enable = true;
nix.package = nix;
programs.zsh.enable = true;
test = ''
echo checking nix-daemon service in /Library/LaunchDaemons >&2
grep "<string>org.nixos.nix-daemon</string>" ${config.out}/Library/LaunchDaemons/org.nixos.nix-daemon.plist
@ -20,9 +18,7 @@ in
echo checking nix-daemon reload in /activate >&2
grep "pkill -HUP nix-daemon" ${config.out}/activate
echo checking NIX_REMOTE=daemon in /etc/bashrc >&2
grep "NIX_REMOTE=daemon" ${config.out}/etc/bashrc
echo "checking NIX_REMOTE=daemon in /etc/zshenv" >&2
grep 'export NIX_REMOTE=daemon' ${config.out}/etc/zshenv
echo checking NIX_REMOTE=daemon in setEnvironment >&2
grep "NIX_REMOTE=daemon" ${config.system.build.setEnvironment}
'';
}

View file

@ -0,0 +1,18 @@
{ config, pkgs, ... }:
{
programs.bash.enable = true;
programs.fish.enable = true;
programs.zsh.enable = true;
test = ''
echo checking setEnvironment in /etc/bashrc >&2
fgrep '. ${config.system.build.setEnvironment}' ${config.out}/etc/bashrc
echo checking setEnvironment in /etc/fish/nixos-env-preinit.fish >&2
grep 'fenv source ${config.system.build.setEnvironment}' ${config.out}/etc/fish/nixos-env-preinit.fish
echo checking setEnvironment in /etc/zshenv >&2
fgrep '. ${config.system.build.setEnvironment}' ${config.out}/etc/zshenv
'';
}

View file

@ -1,12 +0,0 @@
{ config, pkgs, ... }:
{
environment.systemPath = [ pkgs.hello ];
programs.bash.enable = true;
test = ''
echo checking systemPath in /etc/bashrc >&2
grep 'export PATH=${pkgs.hello}/bin' ${config.out}/etc/bashrc
'';
}

View file

@ -1,12 +0,0 @@
{ config, pkgs, ... }:
{
environment.systemPath = [ pkgs.hello ];
programs.fish.enable = true;
test = ''
echo checking systemPath in /etc/fish/config.fish >&2
grep 'fenv export PATH=${pkgs.hello}/bin' ${config.out}/etc/fish/nixos-env-preinit.fish
'';
}

10
tests/system-path.nix Normal file
View file

@ -0,0 +1,10 @@
{ config, pkgs, ... }:
{
environment.systemPath = [ pkgs.hello ];
test = ''
echo checking systemPath in setEnvironment >&2
grep 'export PATH=${pkgs.hello}/bin' ${config.system.build.setEnvironment}
'';
}