typioca: 2.7.0 -> 2.8.0
[NixPkgs.git] / nixos / modules / programs / xonsh.nix
blob167c953f5ffd03a38a9db846afe46e5f716e00ee
1 # This module defines global configuration for the xonsh.
3 { config, lib, pkgs, ... }:
5 with lib;
7 let
9   cfg = config.programs.xonsh;
15   options = {
17     programs.xonsh = {
19       enable = mkOption {
20         default = false;
21         description = lib.mdDoc ''
22           Whether to configure xonsh as an interactive shell.
23         '';
24         type = types.bool;
25       };
27       package = mkOption {
28         type = types.package;
29         default = pkgs.xonsh;
30         defaultText = literalExpression "pkgs.xonsh";
31         example = literalExpression "pkgs.xonsh.override { extraPackages = ps: [ ps.requests ]; }";
32         description = lib.mdDoc ''
33           xonsh package to use.
34         '';
35       };
37       config = mkOption {
38         default = "";
39         description = lib.mdDoc "Control file to customize your shell behavior.";
40         type = types.lines;
41       };
43     };
45   };
47   config = mkIf cfg.enable {
49     environment.etc."xonsh/xonshrc".text = ''
50       # /etc/xonsh/xonshrc: DO NOT EDIT -- this file has been generated automatically.
53       if not ''${...}.get('__NIXOS_SET_ENVIRONMENT_DONE'):
54           # The NixOS environment and thereby also $PATH
55           # haven't been fully set up at this point. But
56           # `source-bash` below requires `bash` to be on $PATH,
57           # so add an entry with bash's location:
58           $PATH.add('${pkgs.bash}/bin')
60           # Stash xonsh's ls alias, so that we don't get a collision
61           # with Bash's ls alias from environment.shellAliases:
62           _ls_alias = aliases.pop('ls', None)
64           # Source the NixOS environment config.
65           source-bash "${config.system.build.setEnvironment}"
67           # Restore xonsh's ls alias, overriding that from Bash (if any).
68           if _ls_alias is not None:
69               aliases['ls'] = _ls_alias
70           del _ls_alias
73       ${cfg.config}
74     '';
76     environment.systemPackages = [ cfg.package ];
78     environment.shells =
79       [ "/run/current-system/sw/bin/xonsh"
80         "${cfg.package}/bin/xonsh"
81       ];
83   };