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