about summary refs log tree commit diff
path: root/nixos/modules/programs
diff options
context:
space:
mode:
authorMichele Guerini Rocco <rnhmjoj@users.noreply.github.com>2020-05-01 12:26:13 +0200
committerGitHub <noreply@github.com>2020-05-01 12:26:13 +0200
commit6c142fddb12fe43c6b2ecf49fb628982d7811216 (patch)
tree32823a06644ead19abc35733609623c784e5702f /nixos/modules/programs
parent8cb98f9f7102be16d41a4d22d0b540a1b866b770 (diff)
parent347e2512613b08d68909226f2f23763e818857d0 (diff)
downloadnixlib-6c142fddb12fe43c6b2ecf49fb628982d7811216.tar
nixlib-6c142fddb12fe43c6b2ecf49fb628982d7811216.tar.gz
nixlib-6c142fddb12fe43c6b2ecf49fb628982d7811216.tar.bz2
nixlib-6c142fddb12fe43c6b2ecf49fb628982d7811216.tar.lz
nixlib-6c142fddb12fe43c6b2ecf49fb628982d7811216.tar.xz
nixlib-6c142fddb12fe43c6b2ecf49fb628982d7811216.tar.zst
nixlib-6c142fddb12fe43c6b2ecf49fb628982d7811216.zip
Merge pull request #84330 from das-g/xonsh-source-nixos-env
nixos/xonsh: source NixOS environment
Diffstat (limited to 'nixos/modules/programs')
-rw-r--r--nixos/modules/programs/xonsh.nix27
1 files changed, 26 insertions, 1 deletions
diff --git a/nixos/modules/programs/xonsh.nix b/nixos/modules/programs/xonsh.nix
index 1590020f7b64..c06fd1655c20 100644
--- a/nixos/modules/programs/xonsh.nix
+++ b/nixos/modules/programs/xonsh.nix
@@ -45,7 +45,32 @@ in
 
   config = mkIf cfg.enable {
 
-    environment.etc.xonshrc.text = cfg.config;
+    environment.etc.xonshrc.text = ''
+      # /etc/xonshrc: DO NOT EDIT -- this file has been generated automatically.
+
+
+      if not ''${...}.get('__NIXOS_SET_ENVIRONMENT_DONE'):
+          # The NixOS environment and thereby also $PATH
+          # haven't been fully set up at this point. But
+          # `source-bash` below requires `bash` to be on $PATH,
+          # so add an entry with bash's location:
+          $PATH.add('${pkgs.bash}/bin')
+
+          # Stash xonsh's ls alias, so that we don't get a collision
+          # with Bash's ls alias from environment.shellAliases:
+          _ls_alias = aliases.pop('ls', None)
+
+          # Source the NixOS environment config.
+          source-bash "${config.system.build.setEnvironment}"
+
+          # Restore xonsh's ls alias, overriding that from Bash (if any).
+          if _ls_alias is not None:
+              aliases['ls'] = _ls_alias
+          del _ls_alias
+
+
+      ${cfg.config}
+    '';
 
     environment.systemPackages = [ cfg.package ];