After setting up the flake, use dk.mkNuApplication to package a Nushell source tree. Put <entry>.nu at the root of src and import sibling modules with relative paths. The entry defaults to pname, so the package below starts at src/my-tool.nu.
packages.default = dk.mkNuApplication {
pname = "my-tool";
version = "0.1.0";
src = ./src;
};List the packages that provide external commands in runtimeInputs and any skill directories to ship in skills, as in the packaging example. To keep test code and skill fixtures out of the package, put test code in .test.nu, .testlib.nu, or .stub.nu files and fixtures under fixtures/ in each skill. See the builder for the packaging rules.
Use dk.writeNuApplication for a standalone script without a source tree.
packages.my-command = dk.writeNuApplication {
name = "my-command";
text = builtins.readFile ./my-command.nu;
runtimeInputs = [ pkgs.git ];
};Nushell resolves named imports at parse time, so each environment needs the same module directories for use config-file.nu to find the same file.
| Where | Setting |
|---|---|
| Both package builders | libDirs, in search order |
| Nix test check | libDirs in the call to dk.nuTests |
| Dev shell | NU_LIB_DIRS, absolute paths joined by : |
| Pre-commit hook, which runs outside the dev shell | hooks.nu-check.settings.libDirs |
The package and test example shows how to share module directories. If a directory also contains files the package should exclude, pass a filtered source built with lib.fileset.toSource.
Both builders accept application defaults through flags, mapping each attribute name to --<name>.
| Value | Effect |
|---|---|
| String, integer, path, or derivation | Supplies one value for --<name> |
true |
Enables the switch |
false or null |
Omits the flag |
| List | Repeats the option in the order given |
Callers can override these defaults, including turning off a switch with --verbose=false. To fix an environment value in writeNuApplication, pass --set through makeWrapperArgs, as in the single-file example.
Nushell parses some script arguments as code, so the wrapper rejects malformed long options, bare redirection operators, and arguments starting with ...$. Arguments supplied by flags or makeWrapperArgs bypass this check and must be trusted. For untrusted data, use stdin, an environment variable, or a file as described in the Nushell argument conventions.
The skill helpers define the Home Manager option and create the file links. Set name to the packaged skill directory's basename so the links point to that directory.
options.programs.my-tool.skillDirectories = lib.mkOption devkit.lib.skillDirectoriesOption;
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
home.file = devkit.lib.skillLinks {
inherit (cfg) package;
name = "my-tool";
directories = cfg.skillDirectories;
};
};