From e15010ee6e9bd356a6746ff9b9f9a9097ee8ddcf Mon Sep 17 00:00:00 2001 From: SaiProton Date: Mon, 20 Mar 2023 17:07:24 -0400 Subject: [PATCH] nushell: add login.nu configuration option Nushell has the option to source from the login.nu file in the case that nushell is used as a login shell. This commit adds the login file alongside the existing config and env files as another configuration option. --- modules/programs/nushell.nix | 31 +++++++++++++++++++ .../programs/nushell/example-settings.nix | 10 ++++++ .../programs/nushell/login-expected.nu | 5 +++ 3 files changed, 46 insertions(+) create mode 100644 tests/modules/programs/nushell/login-expected.nu diff --git a/modules/programs/nushell.nix b/modules/programs/nushell.nix index a977bd4a..b72cbb69 100644 --- a/modules/programs/nushell.nix +++ b/modules/programs/nushell.nix @@ -96,6 +96,23 @@ in { ''; }; + loginFile = mkOption { + type = types.nullOr (linesOrSource "login.nu"); + default = null; + example = '' + # Prints "Hello, World" upon logging into tty1 + if (tty) == "/dev/tty1" { + echo "Hello, World" + } + ''; + description = '' + The login file to be used for nushell upon logging in. + + + See for more information. + ''; + }; + extraConfig = mkOption { type = types.lines; default = ""; @@ -112,6 +129,14 @@ in { ''; }; + extraLogin = mkOption { + type = types.lines; + default = ""; + description = '' + Additional configuration to add to the nushell login file. + ''; + }; + shellAliases = mkOption { type = types.attrsOf types.str; default = { }; @@ -161,6 +186,12 @@ in { envVarsStr ]; }) + (mkIf (cfg.loginFile != null || cfg.extraLogin != "") { + "${configDir}/login.nu".text = mkMerge [ + (mkIf (cfg.loginFile != null) cfg.loginFile.text) + cfg.extraLogin + ]; + }) ]; }; } diff --git a/tests/modules/programs/nushell/example-settings.nix b/tests/modules/programs/nushell/example-settings.nix index d8cb01a7..7259db6d 100644 --- a/tests/modules/programs/nushell/example-settings.nix +++ b/tests/modules/programs/nushell/example-settings.nix @@ -16,6 +16,13 @@ let-env FOO = 'BAR' ''; + loginFile.text = '' + # Prints "Hello, World" upon logging into tty1 + if (tty) == "/dev/tty1" { + echo "Hello, World" + } + ''; + shellAliases = { "lsname" = "(ls | get name)"; "ll" = "ls -a"; @@ -38,5 +45,8 @@ assertFileContent \ "${configDir}/env.nu" \ ${./env-expected.nu} + assertFileContent \ + "${configDir}/login.nu" \ + ${./login-expected.nu} ''; } diff --git a/tests/modules/programs/nushell/login-expected.nu b/tests/modules/programs/nushell/login-expected.nu new file mode 100644 index 00000000..9c21789d --- /dev/null +++ b/tests/modules/programs/nushell/login-expected.nu @@ -0,0 +1,5 @@ +# Prints "Hello, World" upon logging into tty1 +if (tty) == "/dev/tty1" { + echo "Hello, World" +} +