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.

refactoring

cswimr (Jul 13, 2026, 11:56 AM EDT) 451c7720 aa9f4c29

+16 -11
+16 -11
mkNuScript.nix
··· 3 3 lib ? pkgs.lib, 4 4 self ? null, 5 5 inputs ? { }, 6 - src, 7 - file, 8 - name ? baseNameOf (lib.removeSuffix ".nu" file), 6 + script, 7 + name ? lib.removeSuffix ".nu" (baseNameOf script), 8 + version ? null, 9 9 meta ? { }, 10 10 system ? pkgs.stdenv.hostPlatform.system, 11 11 nushell ? pkgs.nushell, 12 + extraPackages ? [ ], 12 13 }: 13 14 let 14 15 resolveDependency = ··· 29 30 else 30 31 pkgs.${dep}; 31 32 32 - extraDependencies = 33 + externalDependencies = 33 34 let 34 - script = builtins.readFile file; 35 - lines = lib.splitString "\n" script; 35 + scriptText = builtins.readFile script; 36 + lines = lib.splitString "\n" scriptText; 36 37 start = lib.lists.findFirstIndex (line: line == "# START: External Dependencies") null lines; 37 38 end = lib.lists.findFirstIndex (line: line == "# END: External Dependencies") null lines; 38 39 deps = 39 40 if (start != null && end != null) then 40 - map (line: lib.removePrefix "# " (lib.removePrefix "# " line)) ( 41 + map (line: lib.removePrefix "# " line) ( 41 42 builtins.filter (line: lib.hasPrefix "#" line && line != "#") ( 42 43 lib.sublist (start + 1) (end - start - 1) lines 43 44 ) ··· 47 48 in 48 49 map resolveDependency deps; 49 50 50 - deps = extraDependencies ++ [ nushell ]; 51 + deps = externalDependencies ++ extraDependencies ++ [ nushell ]; 51 52 in 52 53 pkgs.stdenv.mkDerivation { 53 - inherit name src; 54 - nativeBuildInputs = with pkgs; [ makeWrapper ]; 54 + pname = name; 55 + inherit version; 56 + 57 + nativeBuildInputs = [ pkgs.makeWrapper ]; 58 + 55 59 installPhase = '' 56 60 runHook preInstall 57 61 58 62 mkdir -p $out/bin 59 - cp $src/${file} $out/bin/${name} 63 + cp ${script} $out/bin/${name} 60 64 chmod +x $out/bin/${name} 61 65 62 66 substituteInPlace $out/bin/${name} \ ··· 67 71 68 72 runHook postInstall 69 73 ''; 74 + 70 75 meta = meta // { 71 76 mainProgram = name; # override so that mainProgram always matches what the name of the script in $out/bin is 72 77 };