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.
This commit is contained in:
SaiProton 2023-03-20 17:07:24 -04:00 committed by Robert Helgesson
parent 24805d3ca7
commit e15010ee6e
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
3 changed files with 46 additions and 0 deletions

View file

@ -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.
</para>
<para>
See <link xlink:href="https://www.nushell.sh/book/configuration.html#configuring-nu-as-a-login-shell" /> 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
];
})
];
};
}

View file

@ -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}
'';
}

View file

@ -0,0 +1,5 @@
# Prints "Hello, World" upon logging into tty1
if (tty) == "/dev/tty1" {
echo "Hello, World"
}