mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +01:00
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:
parent
3c710201d5
commit
931e610552
7 changed files with 101 additions and 63 deletions
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
5
tests/modules/programs/nushell/config-expected.nu
Normal file
5
tests/modules/programs/nushell/config-expected.nu
Normal file
|
@ -0,0 +1,5 @@
|
|||
let $config = {
|
||||
filesize_metric: false
|
||||
table_mode: rounded
|
||||
use_ls_colors: true
|
||||
}
|
|
@ -1 +1 @@
|
|||
{ nushell-settings = ./settings.nix; }
|
||||
{ nushell-example-settings = ./example-settings.nix; }
|
||||
|
|
1
tests/modules/programs/nushell/env-expected.nu
Normal file
1
tests/modules/programs/nushell/env-expected.nu
Normal file
|
@ -0,0 +1 @@
|
|||
let-env FOO = 'BAR'
|
30
tests/modules/programs/nushell/example-settings.nix
Normal file
30
tests/modules/programs/nushell/example-settings.nix
Normal 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}
|
||||
'';
|
||||
}
|
|
@ -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 }"]
|
|
@ -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}
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue