Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions modules/programs/nushell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
))
];
};
}
Loading