Files

101 lines
2.3 KiB
Nix
Raw Permalink Normal View History

2024-10-03 15:21:56 -05:00
{ config, lib, ... }:
2022-04-29 10:58:31 -05:00
let
cfg = config.programs.xonsh;
2022-04-29 10:58:31 -05:00
in
2024-10-19 01:19:59 -05:00
with lib;
{
options = {
programs.xonsh = {
enable = mkEnableOption "Enable the xonsh program";
2022-04-29 10:58:31 -05:00
sessionVariables = mkOption {
type = types.attrs;
default = { };
2024-10-19 01:19:59 -05:00
example = {
XONSH_TRACE_SUBPROC = true;
};
description = ''
2024-10-19 01:19:59 -05:00
Environment variables that will be set for the Xonsh session.
'';
};
2022-04-29 10:58:31 -05:00
aliases = mkOption {
type = types.attrsOf types.str;
default = { };
example = literalExpression ''
2024-10-19 01:19:59 -05:00
{
ll = "ls -l";
la = "ls -a";
}
'';
description = ''
2024-10-19 01:19:59 -05:00
An attribute set that maps aliases (the top level attribute names in
this option) to command strings or directly to build outputs.
'';
};
2022-04-29 10:58:31 -05:00
configHeader = mkOption {
type = types.lines;
default = "";
example = literalExpression ''
2024-10-19 01:19:59 -05:00
import os
import sys
'';
description = "An arbitrary string to put at the top of the config file";
};
2022-04-29 10:58:31 -05:00
configFooter = mkOption {
type = types.lines;
default = "";
example = literalExpression ''
2024-10-19 01:19:59 -05:00
def _some_method(args):
do_command()
some_other_thing()
aliases['some_method'] = _some_method
'';
description = "An arbitrary string to put at the end of the config file";
};
};
};
2022-04-29 10:58:31 -05:00
config =
let
2024-10-19 01:19:59 -05:00
shortAliases = concatStringsSep "\n" (mapAttrsToList (k: v: "aliases['${k}']=r'${v}'") cfg.aliases);
2022-04-29 10:58:31 -05:00
listToPythonList =
let
2024-10-19 01:19:59 -05:00
listInternals = args: concatStringsSep "\n" (map (v: "'${v}'") args);
in
list: "[${listInternals list}]";
2022-04-29 10:58:31 -05:00
sessionVars = concatStringsSep "\n" (
2024-10-19 01:19:59 -05:00
mapAttrsToList (
k: v:
if builtins.typeOf v == "string" then
"\$${k} = '${v}'"
else if builtins.typeOf v == "list" then
"\$${k} = ${listToPythonList}"
else if builtins.typeOf v == "int" then
"\$${k} = ${toString v}"
else
""
) cfg.sessionVariables
);
2022-04-29 10:58:31 -05:00
in
mkIf cfg.enable {
2022-04-29 10:58:31 -05:00
home.file.".xonshrc".text = ''
${cfg.configHeader}
2022-04-29 10:58:31 -05:00
${sessionVars}
2022-04-29 10:58:31 -05:00
${shortAliases}
2022-04-29 10:58:31 -05:00
${cfg.configFooter}
'';
};
2022-04-29 10:58:31 -05:00
}