From d273db48c6e95d6547f02845f1921211f113c0c0 Mon Sep 17 00:00:00 2001 From: Tor Hedin Brønner Date: Wed, 29 Aug 2018 16:05:48 +0000 Subject: nixos/shells: avoid overriding the environment for child shells A shared exported guard `__NIXOS_SET_ENVIRONMENT_DONE` is introduced that can be used to prevent child shells from sourcing `system.build.setEnvironment` the second time. This fixes e.g. `nix run derivation` when run from e.g. ZSH through the console or ssh. Before this Bash would resource the common environment resetting the `PATH` environment variable. We also export `system.build.setEnvironment` to `/etc/set-environment` making it easy to reset the common environment with `. /etc/set-environment` when needed and to grep for environment variables in `/etc` (which was the motivation of #30418). This reverts changes made in b00a3fc6fd82834114771f2115a2b032f0ebfe29 (the original #30418). --- nixos/modules/config/shells-environment.nix | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'nixos/modules/config') diff --git a/nixos/modules/config/shells-environment.nix b/nixos/modules/config/shells-environment.nix index 9dc4749b08d1e..41b1b32768ffc 100644 --- a/nixos/modules/config/shells-environment.nix +++ b/nixos/modules/config/shells-environment.nix @@ -162,8 +162,17 @@ in /bin/sh ''; + # For resetting environment with `. /etc/set-environment` when needed + # and discoverability (see motivation of #30418). + environment.etc."set-environment".source = config.system.build.setEnvironment; + system.build.setEnvironment = pkgs.writeText "set-environment" '' + # DO NOT EDIT -- this file has been generated automatically. + + # Prevent this file from being sourced by child shells. + export __NIXOS_SET_ENVIRONMENT_DONE=1 + ${exportedEnvVars} ${cfg.extraInit} -- cgit 1.4.1 From 8952375b484ecb65593be4e81fb8cc5ffde09428 Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Wed, 29 Aug 2018 16:05:53 +0000 Subject: nixos/shells: fix indent everywhere to comply with `doc/coding-conventions.xml` --- nixos/modules/config/shells-environment.nix | 18 +++++++++--------- nixos/modules/programs/bash/bash.nix | 8 ++++---- nixos/modules/programs/fish.nix | 15 +++++++-------- nixos/modules/programs/zsh/zsh.nix | 10 +++++----- 4 files changed, 25 insertions(+), 26 deletions(-) (limited to 'nixos/modules/config') diff --git a/nixos/modules/config/shells-environment.nix b/nixos/modules/config/shells-environment.nix index 41b1b32768ffc..b6dcb9aed4e7b 100644 --- a/nixos/modules/config/shells-environment.nix +++ b/nixos/modules/config/shells-environment.nix @@ -167,19 +167,19 @@ in environment.etc."set-environment".source = config.system.build.setEnvironment; system.build.setEnvironment = pkgs.writeText "set-environment" - '' - # DO NOT EDIT -- this file has been generated automatically. + '' + # DO NOT EDIT -- this file has been generated automatically. - # Prevent this file from being sourced by child shells. - export __NIXOS_SET_ENVIRONMENT_DONE=1 + # Prevent this file from being sourced by child shells. + export __NIXOS_SET_ENVIRONMENT_DONE=1 - ${exportedEnvVars} + ${exportedEnvVars} - ${cfg.extraInit} + ${cfg.extraInit} - # ~/bin if it exists overrides other bin directories. - export PATH="$HOME/bin:$PATH" - ''; + # ~/bin if it exists overrides other bin directories. + export PATH="$HOME/bin:$PATH" + ''; system.activationScripts.binsh = stringAfter [ "stdio" ] '' diff --git a/nixos/modules/programs/bash/bash.nix b/nixos/modules/programs/bash/bash.nix index e5f5c8d09438d..424e1506b4c5d 100644 --- a/nixos/modules/programs/bash/bash.nix +++ b/nixos/modules/programs/bash/bash.nix @@ -168,11 +168,11 @@ in # Read system-wide modifications. if test -f /etc/profile.local; then - . /etc/profile.local + . /etc/profile.local fi if [ -n "''${BASH_VERSION:-}" ]; then - . /etc/bashrc + . /etc/bashrc fi ''; @@ -193,12 +193,12 @@ in # We are not always an interactive shell. if [ -n "$PS1" ]; then - ${cfg.interactiveShellInit} + ${cfg.interactiveShellInit} fi # Read system-wide modifications. if test -f /etc/bashrc.local; then - . /etc/bashrc.local + . /etc/bashrc.local fi ''; diff --git a/nixos/modules/programs/fish.nix b/nixos/modules/programs/fish.nix index 40b3ff37289fa..c3f742acde2e6 100644 --- a/nixos/modules/programs/fish.nix +++ b/nixos/modules/programs/fish.nix @@ -27,7 +27,7 @@ in ''; type = types.bool; }; - + vendor.config.enable = mkOption { type = types.bool; default = true; @@ -43,7 +43,7 @@ in Whether fish should use completion files provided by other packages. ''; }; - + vendor.functions.enable = mkOption { type = types.bool; default = true; @@ -107,7 +107,7 @@ in # This happens before $__fish_datadir/config.fish sets fish_function_path, so it is currently # unset. We set it and then completely erase it, leaving its configuration to $__fish_datadir/config.fish set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $__fish_datadir/functions - + # source the NixOS environment config if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ] fenv source ${config.system.build.setEnvironment} @@ -125,7 +125,7 @@ in set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path fenv source /etc/fish/foreign-env/shellInit > /dev/null set -e fish_function_path[1] - + ${cfg.shellInit} # and leave a note so we don't source this config section again from @@ -139,7 +139,7 @@ in set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path fenv source /etc/fish/foreign-env/loginShellInit > /dev/null set -e fish_function_path[1] - + ${cfg.loginShellInit} # and leave a note so we don't source this config section again from @@ -151,12 +151,11 @@ in status --is-interactive; and not set -q __fish_nixos_interactive_config_sourced and begin ${fishAliases} - set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path fenv source /etc/fish/foreign-env/interactiveShellInit > /dev/null set -e fish_function_path[1] - + ${cfg.promptInit} ${cfg.interactiveShellInit} @@ -172,7 +171,7 @@ in ++ optional cfg.vendor.config.enable "/share/fish/vendor_conf.d" ++ optional cfg.vendor.completions.enable "/share/fish/vendor_completions.d" ++ optional cfg.vendor.functions.enable "/share/fish/vendor_functions.d"; - + environment.systemPackages = [ pkgs.fish ]; environment.shells = [ diff --git a/nixos/modules/programs/zsh/zsh.nix b/nixos/modules/programs/zsh/zsh.nix index c6ab637160d59..2ef575f8f6424 100644 --- a/nixos/modules/programs/zsh/zsh.nix +++ b/nixos/modules/programs/zsh/zsh.nix @@ -70,7 +70,7 @@ in promptInit = mkOption { default = '' if [ "$TERM" != dumb ]; then - autoload -U promptinit && promptinit && prompt walters + autoload -U promptinit && promptinit && prompt walters fi ''; description = '' @@ -113,7 +113,7 @@ in # Read system-wide modifications. if test -f /etc/zshenv.local; then - . /etc/zshenv.local + . /etc/zshenv.local fi ''; @@ -132,7 +132,7 @@ in # Read system-wide modifications. if test -f /etc/zprofile.local; then - . /etc/zprofile.local + . /etc/zprofile.local fi ''; @@ -158,7 +158,7 @@ in # Tell zsh how to find installed completions for p in ''${(z)NIX_PROFILES}; do - fpath+=($p/share/zsh/site-functions $p/share/zsh/$ZSH_VERSION/functions $p/share/zsh/vendor-completions) + fpath+=($p/share/zsh/site-functions $p/share/zsh/$ZSH_VERSION/functions $p/share/zsh/vendor-completions) done ${optionalString cfg.enableCompletion "autoload -U compinit && compinit"} @@ -173,7 +173,7 @@ in # Read system-wide modifications. if test -f /etc/zshrc.local; then - . /etc/zshrc.local + . /etc/zshrc.local fi ''; -- cgit 1.4.1 From fb0e0dcbc65a7b54bcf98b37b16b06412f0b042f Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Sat, 8 Sep 2018 16:38:51 -0500 Subject: xdg/mime.nix: ensure $out/share/mime/packages exists For update-mime-database to work, you must have to have some mime packages installed. In some DEs like XFCE this is not guaranteed to happen. In that case just skip the update-mime-database call. Fixes #46162 --- nixos/modules/config/xdg/mime.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nixos/modules/config') diff --git a/nixos/modules/config/xdg/mime.nix b/nixos/modules/config/xdg/mime.nix index f1b672234a344..eb8ac2a54ace5 100644 --- a/nixos/modules/config/xdg/mime.nix +++ b/nixos/modules/config/xdg/mime.nix @@ -23,7 +23,7 @@ with lib; ]; environment.extraSetup = '' - if [ -w $out/share/mime ]; then + if [ -w $out/share/mime ] && [ -d $out/share/mime/packages ]; then XDG_DATA_DIRS=$out/share ${pkgs.shared-mime-info}/bin/update-mime-database -V $out/share/mime > /dev/null fi -- cgit 1.4.1 From b23f6a37146aaf7f87788658594585a391da86ce Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Sat, 8 Sep 2018 21:43:42 +0000 Subject: nixos: xdg: fix indent and eol spaces --- nixos/modules/config/xdg/mime.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'nixos/modules/config') diff --git a/nixos/modules/config/xdg/mime.nix b/nixos/modules/config/xdg/mime.nix index eb8ac2a54ace5..4323a49ea1dd0 100644 --- a/nixos/modules/config/xdg/mime.nix +++ b/nixos/modules/config/xdg/mime.nix @@ -7,7 +7,7 @@ with lib; type = types.bool; default = true; description = '' - Whether to install files to support the + Whether to install files to support the XDG Shared MIME-info specification and the XDG MIME Applications specification. ''; @@ -17,18 +17,18 @@ with lib; config = mkIf config.xdg.mime.enable { environment.pathsToLink = [ "/share/mime" ]; - environment.systemPackages = [ - # this package also installs some useful data, as well as its utilities - pkgs.shared-mime-info + environment.systemPackages = [ + # this package also installs some useful data, as well as its utilities + pkgs.shared-mime-info ]; environment.extraSetup = '' if [ -w $out/share/mime ] && [ -d $out/share/mime/packages ]; then - XDG_DATA_DIRS=$out/share ${pkgs.shared-mime-info}/bin/update-mime-database -V $out/share/mime > /dev/null + XDG_DATA_DIRS=$out/share ${pkgs.shared-mime-info}/bin/update-mime-database -V $out/share/mime > /dev/null fi if [ -w $out/share/applications ]; then - ${pkgs.desktop-file-utils}/bin/update-desktop-database $out/share/applications + ${pkgs.desktop-file-utils}/bin/update-desktop-database $out/share/applications fi ''; }; -- cgit 1.4.1