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 = lib.mdDoc ''
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 defaultText = literalExpression "pkgs.xonsh";
31 example = literalExpression "pkgs.xonsh.override { configFile = \"/path/to/xonshrc\"; }";
32 description = lib.mdDoc ''
33 xonsh package to use.
34 '';
35 };
36
37 config = mkOption {
38 default = "";
39 description = lib.mdDoc "Control file to customize your shell behavior.";
40 type = types.lines;
41 };
42
43 };
44
45 };
46
47 config = mkIf cfg.enable {
48
49 environment.etc."xonsh/xonshrc".text = ''
50 # /etc/xonsh/xonshrc: DO NOT EDIT -- this file has been generated automatically.
51
52
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')
59
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)
63
64 # Source the NixOS environment config.
65 source-bash "${config.system.build.setEnvironment}"
66
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
71
72
73 ${cfg.config}
74 '';
75
76 environment.systemPackages = [ cfg.package ];
77
78 environment.shells =
79 [ "/run/current-system/sw/bin/xonsh"
80 "${cfg.package}/bin/xonsh"
81 ];
82
83 };
84
85}
86