Skip to content

Commit 6aa98ed

Browse files
mention emulating nix run
Signed-off-by: cinereal <cinereal@riseup.net>
1 parent 55f92ea commit 6aa98ed

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

source/concepts/flakes.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,24 @@ Cons:
117117

118118
Alternatives:
119119

120-
- The [v2 command line interface] (e.g. [nix-build], [nix-shell]) is used to interfaces with traditional Nix files.
120+
- The [v2 command line interface] (e.g. [`nix-build`], [`nix-shell`]) is used to interfaces with traditional Nix files.
121121
- The [`--file` flag] allows the v3 commands to operate on traditional Nix files.
122122
- In {term}`NixOS`, to use the v3 commands with a package set `pkgs` rather than
123123
with a flake NixOS configuration's {term}`Nixpkgs` instantiation,
124124
one may use [`nixpkgs.flake.source = pkgs.path;`].
125+
- Using [`builtins.fetchTree`] from experimental feature [`fetch-tree`], the [`nix run`] may be emulated[^emulated] for non-flake entrypoints.
125126

126127
[Git]: https://git-scm.com/
127128
[v2 command line interface]: https://nix.dev/manual/nix/stable/command-ref/main-commands
128129
[`--file` flag]: https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-build.html#options-that-change-the-interpretation-of-installables
129-
[nix-build]: https://nix.dev/manual/nix/stable/command-ref/nix-build.html
130-
[nix-shell]: https://nix.dev/manual/nix/stable/command-ref/nix-shell.html
130+
[`nix-build`]: https://nix.dev/manual/nix/stable/command-ref/nix-build.html
131+
[`nix-shell`]: https://nix.dev/manual/nix/stable/command-ref/nix-shell.html
131132
[`nixpkgs.flake.source = pkgs.path;`]: https://search.nixos.org/options?channel=unstable&show=nixpkgs.flake.source&query=nixpkgs.flake.source
133+
[`builtins.fetchTree`]: https://noogle.dev/f/builtins/fetchTree
134+
[`fetch-tree`]: https://nix.dev/manual/nix/stable/development/experimental-features#xp-feature-fetch-tree
135+
[`nix run`]: https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-run.html
136+
137+
[^emulated]: `nix run github:NixOS/nixpkgs#hello` for non-flake projects may look like `nix-shell -p '(import (builtins.fetchTree "github:NixOS/nixpkgs").outPath { }).hello' --run 'hello'`. A drop-in command `nix-run` using the `nix run` syntax could be defined using a Bash alias like `alias nix-run='run() { $(nix-instantiate --raw --impure --eval --expr "(import <nixpkgs> {}).lib.getExe (import (builtins.fetchTree \"$(cut -d "#" -f 1 <<< "$1")\").outPath { }).$([[ "$1" == *"#"* ]] && echo "$(cut -d "#" -f 2 <<< "$1")" || echo "default")"); }; run'`.
132138

133139
### Dependency management
134140

0 commit comments

Comments
 (0)