From 4a12f304e0abc3f24c3c7d36423d84d7d8021364 Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Sun, 23 Oct 2022 19:11:21 +0200 Subject: [PATCH] nushell: add options 'extraConfig' and 'extraEnv' --- modules/programs/nushell.nix | 47 ++++++++++++++----- .../programs/nushell/config-expected.nu | 1 + .../modules/programs/nushell/env-expected.nu | 1 + 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/modules/programs/nushell.nix b/modules/programs/nushell.nix index 58b477989..c31c6c65f 100644 --- a/modules/programs/nushell.nix +++ b/modules/programs/nushell.nix @@ -6,14 +6,17 @@ let cfg = config.programs.nushell; - tomlFormat = pkgs.formats.toml { }; - linesOrSource = name: types.submodule ({ config, ... }: { options = { text = mkOption { type = types.lines; - default = ""; + default = if config.source != null then + builtins.readFile config.source + else + ""; + defaultText = literalExpression + "if source is defined, the content of source, otherwise empty"; description = '' Text of the nushell ${name} file. If unset then the source option will be preferred. @@ -22,18 +25,14 @@ let source = mkOption { type = types.nullOr types.path; - default = pkgs.writeTextFile { - inherit (config) text; - name = hm.strings.storeFileName name; - }; - defaultText = literalExpression "file containing text"; + default = null; description = '' Path of the nushell ${name} file to use. + If the text option is set, it will be preferred. ''; }; }; }); - in { meta.maintainers = [ maintainers.Philipp-M ]; @@ -91,14 +90,40 @@ in { See for more information. ''; }; + + 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. + ''; + }; }; config = mkIf cfg.enable { home.packages = [ cfg.package ]; xdg.configFile = mkMerge [ - (mkIf (cfg.configFile != null) { "nushell/config.nu" = cfg.configFile; }) - (mkIf (cfg.envFile != null) { "nushell/env.nu" = cfg.envFile; }) + (mkIf (cfg.configFile != null || cfg.extraConfig != "") { + "nushell/config.nu".text = mkMerge [ + (mkIf (cfg.configFile != null) cfg.configFile.text) + cfg.extraConfig + ]; + }) + (mkIf (cfg.envFile != null || cfg.extraEnv != "") { + "nushell/env.nu".text = mkMerge [ + (mkIf (cfg.envFile != null) cfg.envFile.text) + cfg.extraEnv + ]; + }) ]; }; } diff --git a/tests/modules/programs/nushell/config-expected.nu b/tests/modules/programs/nushell/config-expected.nu index 7fa807238..c70286d70 100644 --- a/tests/modules/programs/nushell/config-expected.nu +++ b/tests/modules/programs/nushell/config-expected.nu @@ -3,3 +3,4 @@ let $config = { table_mode: rounded use_ls_colors: true } + diff --git a/tests/modules/programs/nushell/env-expected.nu b/tests/modules/programs/nushell/env-expected.nu index 5a820ca81..280b59bfa 100644 --- a/tests/modules/programs/nushell/env-expected.nu +++ b/tests/modules/programs/nushell/env-expected.nu @@ -1 +1,2 @@ let-env FOO = 'BAR' +