From 744efad7d37dfee6a105bd7bfe1352a8492f7701 Mon Sep 17 00:00:00 2001 From: gamemaster2b Date: Wed, 29 Jul 2026 17:26:51 +0300 Subject: [PATCH] nushell: add autoload scripts option Add a new 'programs.nushell.autoload' option for loading '.nu' files at startup from relative paths or inline content. --- modules/programs/nushell.nix | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/modules/programs/nushell.nix b/modules/programs/nushell.nix index 21e9045c51cb..c7344e632f18 100644 --- a/modules/programs/nushell.nix +++ b/modules/programs/nushell.nix @@ -211,6 +211,49 @@ in Inline values can be set with `lib.hm.nushell.mkNushellInline`. ''; }; + + autoload = lib.mkOption { + type = types.listOf ( + types.either (types.pathWith { absolute = false; }) ( + types.submodule { + options = { + name = lib.mkOption { + type = types.strMatching "^[^/\\\\]+\\.nu$"; + description = "The Nushell filename. Must be a single filename ending in `.nu`."; + example = "my-script.nu"; + }; + content = lib.mkOption { + type = types.either (types.pathWith { absolute = false; }) types.lines; + description = "The Nushell script content, either as a relative `.nu` path or inline Nushell text."; + example = lib.literalExpression '' + \'\' + echo "loaded" + let x = 1 + \'\' + ''; + }; + }; + } + ) + ); + default = [ ]; + example = lib.literalExpression '' + [ + ./my-module.nu + { + name = "my-script.nu"; + content = \'\' + echo "loaded" + let x = 1 + \'\'; + } + ] + ''; + description = '' + Files are symlinked into the "autoload/" folder in the config directory. + Nushell loads the files in the autoload folders at startup. + ''; + }; }; config = lib.mkIf cfg.enable { @@ -307,6 +350,28 @@ in "${cfg.configDir}/plugin.msgpackz".source = "${msgPackz}/plugin.msgpackz"; } ) + + (lib.mkMerge ( + map ( + script: + let + fileName = if (lib.isPath script) then baseNameOf (toString script) else script.name; + content = + if (lib.isPath script) then + builtins.readFile script + else if (lib.isPath script.content) then + builtins.readFile script.content + else + script.content; + in + assert ( + builtins.match ".*\\.nu$" (toString fileName) != null + ) "ensure the file name has the extension '.nu'; your current file name is ${fileName}"; + { + "${cfg.configDir}/autoload/${fileName}".text = content; + } + ) cfg.autoload + )) ]; }; }