diff --git a/README.md b/README.md index 30de82f..8103137 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ Inspired by Python's [Inline Script Metadata](https://packaging.python.org/en/la ## Why nu2nix? -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. +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. -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. +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. ## Try it Out @@ -49,7 +49,14 @@ Then, you can use [`inputs.nu2nix.lib.mkNuScript`](./lib/mkNuScript.nix) to pack ## External Dependencies -nu2nix supports a custom format for declaring external dependencies inline in your script files. +nu2nix supports a custom format for declaring external dependencies inline in your script files, using an `External Dependencies` block comment. + +The `External Dependencies` block comment must: + +- start with `START: External Dependencies`. +- end with `END: External Dependencies`. +- contain no more than one (1) dependency per line. + All declared dependencies are automatically added to the script's `$PATH` when executed, using a wrapper script. ```nu @@ -67,12 +74,14 @@ All declared dependencies are automatically added to the script's `$PATH` when e ``` > [!WARNING] -> 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`. +> Only dependencies declared in the `External Dependencies` block comment or passed through `mkNuScript`'s `extraDependencies` argument are available at runtime. +> nu2nix replaces `$PATH` entirely instead of extending it. This makes scripts reproducible; if a command is not explicitly declared, it will not be available. +> Nushell itself is the exception, as it's automatically added by `mkNuScript`. ### Dependency Formats -| Scope | Usage Example | Resolves to | `mkNuScript` Argument | -| :---------------: | :----------------------: | :-----------------------------------------: | :-----------------------------------------------: | -| _``_ | `git` | `pkgs.git` | `pkgs` (raises error when missing) | -| `inputs` | `inputs.vicinae.default` | `inputs.vicinae.packages.${system}.default` | `inputs` (raises error when missing & referenced) | -| `self` | `self.helper-script` | `self.packages.${system}.helper-script` | `self` (raises error when missing & referenced) | +| Scope | Usage Example | Resolves to | `mkNuScript` Argument | +| :--------------: | :----------------------: | :-----------------------------------------: | :-----------------------------------------------: | +| Default (`pkgs`) | `git` | `pkgs.git` | `pkgs` (raises error when missing) | +| `inputs` | `inputs.vicinae.default` | `inputs.vicinae.packages.${system}.default` | `inputs` (raises error when missing & referenced) | +| `self` | `self.helper-script` | `self.packages.${system}.helper-script` | `self` (raises error when missing & referenced) |