diff --git a/modules/programs/nushell.nix b/modules/programs/nushell.nix
index 4d6ab43a7..d413a43f5 100644
--- a/modules/programs/nushell.nix
+++ b/modules/programs/nushell.nix
@@ -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 ${name} 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 ${name} 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
- $XDG_CONFIG_HOME/nushell/config.toml.
-
- See for the full list
- of options.
+ The configuration file to be used for nushell.
+
+
+ See for more information.
+ '';
+ };
+
+ envFile = mkOption {
+ type = linesOrSource "env.nu";
+ example = ''
+ let-env FOO = 'BAR'
+ '';
+ description = ''
+ The environment variables file to be used for nushell.
+
+
+ See 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;
};
}
diff --git a/tests/modules/programs/nushell/config-expected.nu b/tests/modules/programs/nushell/config-expected.nu
new file mode 100644
index 000000000..7fa807238
--- /dev/null
+++ b/tests/modules/programs/nushell/config-expected.nu
@@ -0,0 +1,5 @@
+let $config = {
+ filesize_metric: false
+ table_mode: rounded
+ use_ls_colors: true
+}
diff --git a/tests/modules/programs/nushell/default.nix b/tests/modules/programs/nushell/default.nix
index 5b3bfa1a5..52d9b3c7b 100644
--- a/tests/modules/programs/nushell/default.nix
+++ b/tests/modules/programs/nushell/default.nix
@@ -1 +1 @@
-{ nushell-settings = ./settings.nix; }
+{ nushell-example-settings = ./example-settings.nix; }
diff --git a/tests/modules/programs/nushell/env-expected.nu b/tests/modules/programs/nushell/env-expected.nu
new file mode 100644
index 000000000..5a820ca81
--- /dev/null
+++ b/tests/modules/programs/nushell/env-expected.nu
@@ -0,0 +1 @@
+let-env FOO = 'BAR'
diff --git a/tests/modules/programs/nushell/example-settings.nix b/tests/modules/programs/nushell/example-settings.nix
new file mode 100644
index 000000000..d1eca3202
--- /dev/null
+++ b/tests/modules/programs/nushell/example-settings.nix
@@ -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}
+ '';
+}
diff --git a/tests/modules/programs/nushell/settings-expected.toml b/tests/modules/programs/nushell/settings-expected.toml
deleted file mode 100644
index 87c5de250..000000000
--- a/tests/modules/programs/nushell/settings-expected.toml
+++ /dev/null
@@ -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 }"]
diff --git a/tests/modules/programs/nushell/settings.nix b/tests/modules/programs/nushell/settings.nix
deleted file mode 100644
index 7eef0909c..000000000
--- a/tests/modules/programs/nushell/settings.nix
+++ /dev/null
@@ -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}
- '';
- };
-}