A simple helper that makes it easy to package Nu scripts with Nix, including inline dependency declarations for external commands and other packaged scripts.
flake nu nushell nix
1

Configure Feed

Select the types of activity you want to include in your feed.

improve dependency resolution logic; make `inputs` have a safer default

cswimr (Jul 13, 2026, 1:11 PM EDT) 47a248b3 cc602b27

+21 -5
+21 -5
mkNuScript.nix
··· 2 2 pkgs, 3 3 lib ? pkgs.lib, 4 4 self ? null, 5 - inputs ? { }, 5 + inputs ? null, 6 6 script, 7 7 name ? lib.removeSuffix ".nu" (baseNameOf script), 8 8 version ? "unstable", ··· 18 18 segments = lib.splitString "." dep; 19 19 scope = builtins.head segments; 20 20 rest = builtins.tail segments; 21 - joinSegments = lib.concatStringsSep "."; 21 + error = "Dependency `${dep}` not found"; 22 22 in 23 23 if (scope == "self" && rest != [ ]) then 24 24 if self != null then 25 - self.packages.${system}.${joinSegments rest} 25 + lib.attrByPath ( 26 + [ 27 + "packages" 28 + system 29 + ] 30 + ++ rest 31 + ) (throw error) self 26 32 else 27 33 throw "`self` was not passed to `mkNuScript` or is `null`, but a script references a dependency with the `self.` scope." 28 34 else if (scope == "inputs" && rest != [ ]) then 29 - inputs.${builtins.head rest}.packages.${system}.${joinSegments (builtins.tail rest)} 35 + if inputs != null then 36 + lib.attrByPath ( 37 + [ 38 + (builtins.head rest) 39 + "packages" 40 + system 41 + ] 42 + ++ (builtins.tail rest) 43 + ) (throw error) inputs 44 + else 45 + throw "`inputs` was not passed to `mkNuScript` or is `null`, but a script references a dependency with the `inputs.` scope." 30 46 else 31 - pkgs.${dep}; 47 + lib.attrByPath segments (throw error) pkgs; 32 48 33 49 externalDependencies = 34 50 let