1# This module defines global configuration for the xonsh.
2
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let
8
9 cfg = config.programs.xonsh;
10
11in
12
13{
14
15 options = {
16
17 programs.xonsh = {
18
19 enable = mkOption {
20 default = false;
21 description = ''
22 Whether to configure xonsh as an interactive shell.
23 '';
24 type = types.bool;
25 };
26
27 package = mkOption {
28 type = types.package;
29 default = pkgs.xonsh;
30 example = literalExample "pkgs.xonsh.override { configFile = \"/path/to/xonshrc\"; }";
31 description = ''
32 xonsh package to use.
33 '';
34 };
35
36 config = mkOption {
37 default = "";
38 description = "Control file to customize your shell behavior.";
39 type = types.lines;
40 };
41
42 };
43
44 };
45
46 config = mkIf cfg.enable {
47
48 environment.etc.xonshrc.text = ''
49 # /etc/xonshrc: DO NOT EDIT -- this file has been generated automatically.
50
51
52 if not ''${...}.get('__NIXOS_SET_ENVIRONMENT_DONE'):
53 # The NixOS environment and thereby also $PATH
54 # haven't been fully set up at this point. But
55 # `source-bash` below requires `bash` to be on $PATH,
56 # so add an entry with bash's location:
57 $PATH.add('${pkgs.bash}/bin')
58
59 # Stash xonsh's ls alias, so that we don't get a collision
60 # with Bash's ls alias from environment.shellAliases:
61 _ls_alias = aliases.pop('ls', None)
62
63 # Source the NixOS environment config.
64 source-bash "${config.system.build.setEnvironment}"
65
66 # Restore xonsh's ls alias, overriding that from Bash (if any).
67 if _ls_alias is not None:
68 aliases['ls'] = _ls_alias
69 del _ls_alias
70
71
72 ${cfg.config}
73 '';
74
75 environment.systemPackages = [ cfg.package ];
76
77 environment.shells =
78 [ "/run/current-system/sw/bin/xonsh"
79 "${cfg.package}/bin/xonsh"
80 ];
81
82 };
83
84}
85