nushell: update configuration management

Recent versions of nushell uses a different configuration setup. This
commit adjusts the module to match.

Fixes #2952
Fixes #2837
This commit is contained in:
Philipp Mildenberger 2022-05-13 17:20:42 +02:00 committed by Robert Helgesson
parent 3c710201d5
commit 931e610552
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
7 changed files with 101 additions and 63 deletions

View file

@ -8,9 +8,45 @@ let
tomlFormat = pkgs.formats.toml { };
linesOrSource = name:
types.submodule ({ config, ... }: {
options = {
text = mkOption {
type = types.lines;
default = "";
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;
default = pkgs.writeTextFile {
inherit (config) text;
name = hm.strings.storeFileName name;
};
defaultText = literalExpression "file containing text";
description = ''
Path of the nushell <filename>${name}</filename> file to use.
'';
};
};
});
in {
meta.maintainers = [ maintainers.Philipp-M ];
imports = [
(mkRemovedOptionModule [ "programs" "nushell" "settings" ] ''
Please use
'programs.nushell.configFile' and 'programs.nushell.envFile'
instead.
'')
];
options.programs.nushell = {
enable = mkEnableOption "nushell";
@ -21,31 +57,36 @@ in {
description = "The package to use for nushell.";
};
settings = mkOption {
type = with types;
let
prim = oneOf [ bool int str ];
primOrPrimAttrs = either prim (attrsOf prim);
entry = either prim (listOf primOrPrimAttrs);
entryOrAttrsOf = t: either entry (attrsOf t);
entries = entryOrAttrsOf (entryOrAttrsOf entry);
in attrsOf entries // { description = "Nushell configuration"; };
default = { };
configFile = mkOption {
type = linesOrSource "config.nu";
example = literalExpression ''
{
edit_mode = "vi";
startup = [ "alias la [] { ls -a }" "alias e [msg] { echo $msg }" ];
key_timeout = 10;
completion_mode = "circular";
no_auto_pivot = true;
{ text = '''
let $config = {
filesize_metric: false
table_mode: rounded
use_ls_colors: true
}
''';
}
'';
description = ''
Configuration written to
<filename>$XDG_CONFIG_HOME/nushell/config.toml</filename>.
</para><para>
See <link xlink:href="https://www.nushell.sh/book/configuration.html" /> for the full list
of options.
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 {
type = linesOrSource "env.nu";
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.
'';
};
};
@ -53,8 +94,7 @@ in {
config = mkIf cfg.enable {
home.packages = [ cfg.package ];
xdg.configFile."nu/config.toml" = mkIf (cfg.settings != { }) {
source = tomlFormat.generate "nushell-config" cfg.settings;
};
xdg.configFile."nushell/config.nu" = cfg.configFile;
xdg.configFile."nushell/env.nu" = cfg.envFile;
};
}

View file

@ -0,0 +1,5 @@
let $config = {
filesize_metric: false
table_mode: rounded
use_ls_colors: true
}

View file

@ -1 +1 @@
{ nushell-settings = ./settings.nix; }
{ nushell-example-settings = ./example-settings.nix; }

View file

@ -0,0 +1 @@
let-env FOO = 'BAR'

View file

@ -0,0 +1,30 @@
{ ... }:
{
programs.nushell = {
enable = true;
configFile.text = ''
let $config = {
filesize_metric: false
table_mode: rounded
use_ls_colors: true
}
'';
envFile.text = ''
let-env FOO = 'BAR'
'';
};
test.stubs.nushell = { };
nmt.script = ''
assertFileContent \
home-files/.config/nushell/config.nu \
${./config-expected.nu}
assertFileContent \
home-files/.config/nushell/env.nu \
${./env-expected.nu}
'';
}

View file

@ -1,5 +0,0 @@
completion_mode = "circular"
edit_mode = "vi"
key_timeout = 10
no_auto_pivot = true
startup = ["alias la [] { ls -a }", "alias e [msg] { echo $msg }"]

View file

@ -1,33 +0,0 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
programs.nushell = {
enable = true;
settings = mkMerge [
{
edit_mode = "vi";
startup = [ "alias la [] { ls -a }" ];
completion_mode = "circular";
key_timeout = 10;
}
{
startup = [ "alias e [msg] { echo $msg }" ];
no_auto_pivot = true;
}
];
};
test.stubs.nushell = { };
nmt.script = ''
assertFileContent \
home-files/.config/nu/config.toml \
${./settings-expected.toml}
'';
};
}