# Nix-run: run nix derivations without nix3 or flakes

**URL:** https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072
**Category:** Announcements
**Created:** [February 6, 2026, 8:42am UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072 "2026-02-06T08:42:45Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![WeetHet](https://discourse.nixos.org/user_avatar/discourse.nixos.org/weethet/32/36482_2.png) [@WeetHet](https://discourse.nixos.org/u/WeetHet)
#### Post date: [February 6, 2026, 8:42am UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/1 "2026-02-06T08:42:46Z")

</div>

> **[weethet.bsky.social/nix-run](https://tangled.org/weethet.bsky.social/nix-run)**
>
> A stable replacement for nix run in haskell

I don’t use flakes or nix3-command, so it was always a bit uncomfortable to repeat the package name twice when writing `nix-shell -p name --run “name args”`, which also doesn’t support properly running derivations from remotes/local directories, since it would instead create a dev shell for the derivation.

The solution is to write a wrapper that uses `nix-instantiate` to extract `meta.mainProgram` and then `nix-build` to build the derivation, the output of which could afterwards be ran.

The important part here is to not use expressions since it breaks building remote tarballs, which is supported by `nix-build` by default (as in you can do `nix-build "https://github.com/nixos/nixpkgs/archive/refs/heads/master.tar.gz" -A hello`). To replicate `lib.getExe`, you also need to parse the derivation to get the `bin` output if it exists, and thanks to the @Gabriella439‘s `nix-derivation` library it is possible to do so.

Basically, anything that can be `nix-build`-t can be `nix-run`-ed, even if you don’t have a `meta.mainProgram` you can manually specify `-B/--binary` instead.

There’s also a special case for `<nixpkgs>`, so instead of writing `nix-run "<nixpkgs>" -A something` you can just write `nix-run -p something`

It’s in `nixpkgs-unstable`, just add it to your `configuration.nix` or use via `nix-shell -p nix-run`

The small disadvantage compared to `nix run` is the need to write `--` before the program arguments since I wasn’t exactly able to imitate the `nix` argument parsing 1 to 1, but it is supported:

```bash
$ nix-run -p stress-ng -- \
        --cpu 12 \
        --vm 8 \
        --vm-bytes 240% \
        --timeout 5m \
        --page-in

```

---

<div class="post-metadata">

### Author: ![kiara](https://discourse.nixos.org/user_avatar/discourse.nixos.org/kiara/32/37249_2.png) [@kiara](https://discourse.nixos.org/u/kiara)
#### Post date: [February 6, 2026, 12:22pm UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/2 "2026-02-06T12:22:07Z")

</div>

nice, thanks!

i previously had a barebones version using `fetchTree` [documented](https://nix.dev/concepts/flakes#emulated) as an alternative to `nix run`, and now opened a [PR](https://github.com/NixOS/nix.dev/pull/1207) to mention `nix-run` as well.

(nitpick: i kinda like tree references’ terser syntax better than `https://github.com/nixos/nixpkgs/archive/refs/heads/master.tar.gz` 🙈, while they also seem able to handle the remote fetches.)

ideally tho, i hope we could get a command like this [built-in](https://github.com/NixOS/nix/issues/14992), so libraries would feel more comfortable documenting remote invocation using it.

---

<div class="post-metadata">

### Author: ![WeetHet](https://discourse.nixos.org/user_avatar/discourse.nixos.org/weethet/32/36482_2.png) [@WeetHet](https://discourse.nixos.org/u/WeetHet)
#### Post date: [February 6, 2026, 2:19pm UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/3 "2026-02-06T14:19:24Z")

</div>

Fetch-tree is experimental AFAIK, so there isn’t much of an advantage to using it over just using nix3-command

---

<div class="post-metadata">

### Author: ![kiara](https://discourse.nixos.org/user_avatar/discourse.nixos.org/kiara/32/37249_2.png) [@kiara](https://discourse.nixos.org/u/kiara)
#### Post date: [February 6, 2026, 2:43pm UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/4 "2026-02-06T14:43:56Z")

</div>

right, my goal wasn’t so much to avoid any use of experimental features: i consider fetchTree boring enough that i wouldn’t mind dealing with it even if something changes in the future.

rather, with `-f default.nix`, for non-flake use i think the v3 cli offers only second-class UX without the built-in fetch-tree references, to a point where i’m not sure what value it adds when one can do without - i.e. when you need neither flakes’ evaluation caching, their `outputs` schema, nor dependency management using its `inputs` over alternatives.

---

<div class="post-metadata">

### Author: ![lenny](https://discourse.nixos.org/user_avatar/discourse.nixos.org/lenny/32/27229_2.png) [@lenny](https://discourse.nixos.org/u/lenny)
#### Post date: [February 9, 2026, 12:14am UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/5 "2026-02-09T00:14:09Z")

</div>

```auto
nix-run -p bluetui nix-shell-env 
error: unrecognised flag '--raw'
Try 'nix-instantiate --help' for more information.
readCreateProcess: nix-instantiate "<nixpkgs>" "--eval" "--raw" "-A" "bluetui.meta.mainProgram" "--read-write-mode" (exit 1): failed

```

Does this require a newer version of nixos? I’m on nixos 25.11 and got it from unstable.

---

<div class="post-metadata">

### Author: ![WeetHet](https://discourse.nixos.org/user_avatar/discourse.nixos.org/weethet/32/36482_2.png) [@WeetHet](https://discourse.nixos.org/u/WeetHet)
#### Post date: [February 9, 2026, 7:10am UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/6 "2026-02-09T07:10:03Z")

</div>

Not NixOS but CppNix 2.26 IIRC or Lix 2.94

---

<div class="post-metadata">

### Author: ![balint](https://discourse.nixos.org/user_avatar/discourse.nixos.org/balint/32/15960_2.png) [@balint](https://discourse.nixos.org/u/balint)
#### Post date: [February 16, 2026, 10:16am UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/7 "2026-02-16T10:16:14Z")

</div>

Can this be used to run a custom command in a local default.nix, eg. by defining an attribute with writeScriptBin?

---

<div class="post-metadata">

### Author: ![WeetHet](https://discourse.nixos.org/user_avatar/discourse.nixos.org/weethet/32/36482_2.png) [@WeetHet](https://discourse.nixos.org/u/WeetHet)
#### Post date: [February 16, 2026, 1:11pm UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/8 "2026-02-16T13:11:02Z")

</div>

Yes, absolutely, `nix-run` uses local `default.nix` by default, same as `nix-build`

---

<div class="post-metadata">

### Author: ![balint](https://discourse.nixos.org/user_avatar/discourse.nixos.org/balint/32/15960_2.png) [@balint](https://discourse.nixos.org/u/balint)
#### Post date: [February 16, 2026, 2:54pm UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/9 "2026-02-16T14:54:03Z")

</div>

Nice. It would make it a bit cleaner in CI workflows if it was part of the nixos/nix container or an alternative one. Currently my strategy is to define a minimal shell just for CI and then call it with nix-shell -A … –run “…” in places where it doesn’t make sense to define a derivation for the output, eg using static site generators.

---

<div class="post-metadata">

### Author: ![toastal](https://discourse.nixos.org/user_avatar/discourse.nixos.org/toastal/32/3454_2.png) [@toastal](https://discourse.nixos.org/u/toastal)
#### Post date: [March 19, 2026, 10:54am UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/10 "2026-03-19T10:54:42Z")

</div>

The source is a 404?

---

<div class="post-metadata">

### Author: ![WeetHet](https://discourse.nixos.org/user_avatar/discourse.nixos.org/weethet/32/36482_2.png) [@WeetHet](https://discourse.nixos.org/u/WeetHet)
#### Post date: [March 19, 2026, 12:25pm UTC](https://discourse.nixos.org/t/nix-run-run-nix-derivations-without-nix3-or-flakes/75072/11 "2026-03-19T12:25:50Z")

</div>

I’ve changed my PDS: [weethet.eurosky.social/nix-run at main](https://tangled.org/weethet.eurosky.social/nix-run)

PR to update the url: [nix-run: fix url by WeetHet · Pull Request #498571 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/498571)
