Select the types of activity you want to include in your feed.
A simple helper that makes it easy to package Nu scripts with Nix, including inline dependency declarations for external commands and other packaged scripts.
···5566## Why nu2nix?
7788-Nu scripts are great for small utilities and automation tasks, but packaging them with Nix means maintaining a separate Nix expression that actually builds your script into a runnable Nix package. Your dependency information ends up living in that Nix expression instead of with your script. This also ends up making it more difficult to, say, package a directory of scripts using `builtins.readDir` and some mapping magic, which is the original use case I created nu2nix for.
88+Nu scripts are great for small utilities and automation tasks, but packaging them with Nix means maintaining a separate Nix expression that actually builds your script into a runnable Nix package. Your dependency information ends up living in that Nix expression instead of with your script. This also makes it harder to package collections of scripts programmatically, such as using `builtins.readDir` and mapping over the result. That was the original use case that motivated nu2nix.
991010-nu2nix fixes these problems by keeping your dependency information stored inside your Nu scripts themselves. Just point nu2nix at a script file and give it a package set. It'll scan your script for an `External Dependencies` block comment and parse it, then the resulting package will have all of the dependencies you declared in your block comment in `$PATH`. nixpkgs (`pkgs`), flake inputs (`inputs`), and a flake's `self` argument are all supported as dependency sources.
1010+nu2nix fixes these problems by keeping your dependency information stored inside your Nu scripts themselves. Just point nu2nix at a script file and give it a package scope. It'll scan your script for an `External Dependencies` block comment and parse it, then the resulting package will have all of the dependencies you declared in your block comment in `$PATH`. nixpkgs (`pkgs`), flake inputs (`inputs`), and a flake's `self` argument are all supported as dependency sources.
11111212## Try it Out
1313···49495050## External Dependencies
51515252-nu2nix supports a custom format for declaring external dependencies inline in your script files.
5252+nu2nix supports a custom format for declaring external dependencies inline in your script files, using an `External Dependencies` block comment.
5353+5454+The `External Dependencies` block comment must:
5555+5656+- start with `START: External Dependencies`.
5757+- end with `END: External Dependencies`.
5858+- contain no more than one (1) dependency per line.
5959+5360All declared dependencies are automatically added to the script's `$PATH` when executed, using a wrapper script.
54615562```nu
···6774```
68756976> [!WARNING]
7070-> Only dependencies you declare in the `External Dependencies` comment or the `extraDependencies` argument to `mkNuScript` will be included in the script's `$PATH` wrapper. `$PATH` is completely overridden, not appended to. This helps with reproducibility; if an external command isn't explicitly included in the wrapper, Nushell won't be able to find it at runtime. The only exception to this is Nushell itself, as Nushell is implicitly added to the script's `$PATH` wrapper by `mkNuScript`.
7777+> Only dependencies declared in the `External Dependencies` block comment or passed through `mkNuScript`'s `extraDependencies` argument are available at runtime.
7878+> nu2nix replaces `$PATH` entirely instead of extending it. This makes scripts reproducible; if a command is not explicitly declared, it will not be available.
7979+> Nushell itself is the exception, as it's automatically added by `mkNuScript`.
71807281### Dependency Formats
73827474-| Scope | Usage Example | Resolves to | `mkNuScript` Argument |
7575-| :---------------: | :----------------------: | :-----------------------------------------: | :-----------------------------------------------: |
7676-| _`<unqualified>`_ | `git` | `pkgs.git` | `pkgs` (raises error when missing) |
7777-| `inputs` | `inputs.vicinae.default` | `inputs.vicinae.packages.${system}.default` | `inputs` (raises error when missing & referenced) |
7878-| `self` | `self.helper-script` | `self.packages.${system}.helper-script` | `self` (raises error when missing & referenced) |
8383+| Scope | Usage Example | Resolves to | `mkNuScript` Argument |
8484+| :--------------: | :----------------------: | :-----------------------------------------: | :-----------------------------------------------: |
8585+| Default (`pkgs`) | `git` | `pkgs.git` | `pkgs` (raises error when missing) |
8686+| `inputs` | `inputs.vicinae.default` | `inputs.vicinae.packages.${system}.default` | `inputs` (raises error when missing & referenced) |
8787+| `self` | `self.helper-script` | `self.packages.${system}.helper-script` | `self` (raises error when missing & referenced) |