2020-07-24 17:15:55 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.nushell;
|
|
|
|
|
2022-11-24 00:37:08 +01:00
|
|
|
configDir = if pkgs.stdenv.isDarwin then
|
|
|
|
"Library/Application Support/nushell"
|
|
|
|
else
|
|
|
|
"${config.xdg.configHome}/nushell";
|
|
|
|
|
2022-05-13 17:20:42 +02:00
|
|
|
linesOrSource = name:
|
|
|
|
types.submodule ({ config, ... }: {
|
|
|
|
options = {
|
|
|
|
text = mkOption {
|
|
|
|
type = types.lines;
|
2022-10-23 19:11:21 +02:00
|
|
|
default = if config.source != null then
|
|
|
|
builtins.readFile config.source
|
|
|
|
else
|
|
|
|
"";
|
|
|
|
defaultText = literalExpression
|
|
|
|
"if source is defined, the content of source, otherwise empty";
|
2022-05-13 17:20:42 +02:00
|
|
|
description = ''
|
|
|
|
Text of the nushell <filename>${name}</filename> file.
|
|
|
|
If unset then the source option will be preferred.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
source = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
2022-10-23 19:11:21 +02:00
|
|
|
default = null;
|
2022-05-13 17:20:42 +02:00
|
|
|
description = ''
|
|
|
|
Path of the nushell <filename>${name}</filename> file to use.
|
2022-10-23 19:11:21 +02:00
|
|
|
If the text option is set, it will be preferred.
|
2022-05-13 17:20:42 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
2020-07-24 17:15:55 +02:00
|
|
|
in {
|
|
|
|
meta.maintainers = [ maintainers.Philipp-M ];
|
|
|
|
|
2022-05-13 17:20:42 +02:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "programs" "nushell" "settings" ] ''
|
|
|
|
Please use
|
|
|
|
|
|
|
|
'programs.nushell.configFile' and 'programs.nushell.envFile'
|
|
|
|
|
|
|
|
instead.
|
|
|
|
'')
|
|
|
|
];
|
|
|
|
|
2020-07-24 17:15:55 +02:00
|
|
|
options.programs.nushell = {
|
|
|
|
enable = mkEnableOption "nushell";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.nushell;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.nushell";
|
2020-07-24 17:15:55 +02:00
|
|
|
description = "The package to use for nushell.";
|
|
|
|
};
|
|
|
|
|
2022-05-13 17:20:42 +02:00
|
|
|
configFile = mkOption {
|
2022-07-07 08:49:50 +02:00
|
|
|
type = types.nullOr (linesOrSource "config.nu");
|
|
|
|
default = null;
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2022-05-13 17:20:42 +02:00
|
|
|
{ text = '''
|
|
|
|
let $config = {
|
|
|
|
filesize_metric: false
|
|
|
|
table_mode: rounded
|
|
|
|
use_ls_colors: true
|
|
|
|
}
|
|
|
|
''';
|
2020-07-24 17:15:55 +02:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
2022-05-13 17:20:42 +02:00
|
|
|
The configuration file to be used for nushell.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
See <link xlink:href="https://www.nushell.sh/book/configuration.html#configuration" /> for more information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
envFile = mkOption {
|
2022-07-07 08:49:50 +02:00
|
|
|
type = types.nullOr (linesOrSource "env.nu");
|
|
|
|
default = null;
|
2022-05-13 17:20:42 +02:00
|
|
|
example = ''
|
|
|
|
let-env FOO = 'BAR'
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
The environment variables file to be used for nushell.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
See <link xlink:href="https://www.nushell.sh/book/configuration.html#configuration" /> for more information.
|
2020-07-24 17:15:55 +02:00
|
|
|
'';
|
|
|
|
};
|
2022-10-23 19:11:21 +02:00
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Additional configuration to add to the nushell configuration file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraEnv = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Additional configuration to add to the nushell environment variables file.
|
|
|
|
'';
|
|
|
|
};
|
2022-12-27 17:29:16 +01:00
|
|
|
|
|
|
|
shellAliases = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
|
|
|
example = { ll = "ls -l"; };
|
|
|
|
description = ''
|
|
|
|
An attribute set that maps aliases (the top level attribute names in
|
|
|
|
this option) to command strings or directly to build outputs.
|
|
|
|
'';
|
|
|
|
};
|
2023-05-04 00:12:21 +02:00
|
|
|
|
|
|
|
environmentVariables = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
|
|
|
example = { FOO = "BAR"; };
|
|
|
|
description = ''
|
|
|
|
An attribute set that maps an environment variable to a shell interpreted string.
|
|
|
|
'';
|
|
|
|
};
|
2020-07-24 17:15:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
home.packages = [ cfg.package ];
|
2022-12-27 17:29:16 +01:00
|
|
|
|
2022-11-24 00:37:08 +01:00
|
|
|
home.file = mkMerge [
|
2022-12-27 17:29:16 +01:00
|
|
|
(let
|
|
|
|
writeConfig = cfg.configFile != null || cfg.extraConfig != ""
|
|
|
|
|| aliasesStr != "";
|
|
|
|
|
|
|
|
aliasesStr = concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (k: v: "alias ${k} = ${v}") cfg.shellAliases);
|
|
|
|
in mkIf writeConfig {
|
2022-11-24 00:37:08 +01:00
|
|
|
"${configDir}/config.nu".text = mkMerge [
|
2022-10-23 19:11:21 +02:00
|
|
|
(mkIf (cfg.configFile != null) cfg.configFile.text)
|
|
|
|
cfg.extraConfig
|
2022-12-27 17:29:16 +01:00
|
|
|
aliasesStr
|
2022-10-23 19:11:21 +02:00
|
|
|
];
|
|
|
|
})
|
2022-12-27 17:29:16 +01:00
|
|
|
|
2023-05-04 00:12:21 +02:00
|
|
|
(let
|
|
|
|
envVarsStr = concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (k: v: "let-env ${k} = ${v}")
|
|
|
|
cfg.environmentVariables);
|
|
|
|
in mkIf (cfg.envFile != null || cfg.extraEnv != "" || envVarsStr != "") {
|
2022-11-24 00:37:08 +01:00
|
|
|
"${configDir}/env.nu".text = mkMerge [
|
2022-10-23 19:11:21 +02:00
|
|
|
(mkIf (cfg.envFile != null) cfg.envFile.text)
|
|
|
|
cfg.extraEnv
|
2023-05-04 00:12:21 +02:00
|
|
|
envVarsStr
|
2022-10-23 19:11:21 +02:00
|
|
|
];
|
|
|
|
})
|
2022-07-07 08:49:50 +02:00
|
|
|
];
|
2020-07-24 17:15:55 +02:00
|
|
|
};
|
|
|
|
}
|