# Saving dev shells from GC: \`nix develop --profile\` VS \`nix build .#devShells\`

**URL:** https://discourse.nixos.org/t/saving-dev-shells-from-gc-nix-develop-profile-vs-nix-build-devshells/80792
**Category:** Help
**Created:** [October 27, 2026, 10:10am UTC](https://discourse.nixos.org/t/saving-dev-shells-from-gc-nix-develop-profile-vs-nix-build-devshells/80792 "2026-10-27T10:10:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![njnj](https://discourse.nixos.org/user_avatar/discourse.nixos.org/njnj/32/39187_2.png) [@njnj](https://discourse.nixos.org/u/njnj)
#### Post date: [October 27, 2026, 10:10am UTC](https://discourse.nixos.org/t/saving-dev-shells-from-gc-nix-develop-profile-vs-nix-build-devshells/80792/1 "2026-10-27T10:10:40Z")

</div>

Hello!

I’ve been exploring different methods for preserving Nix development shells from garbage collection.  
After reading a bit about it, I came across two suggestions that don’t require external tools:

- Using `nix develop --profile`
- Using `nix build .#devShells.${system}.default` \[1\]

If I understand correctly, `nix develop --profile` seems to be the recommended way to do that with the new CLI, and it does work perfectly for me.

However, I was a bit curious and wanted to see if I could achieve the same result by building the `devShells.${system}.default` derivation using regular `nix build` and then manually add a symlink in `/nix/var/nix/gcroots`.

Here’s the command I ran.

```sh
nix build .#devShells.x86_64-linux.default --out-link "devshell"

```

But when I try running

```sh
nix develop ./devshell

```

I get the following error:

```auto
error: argument '/nix/store/hbxw6mlmwbcld9jxamhjcwmigzzbzh5g-nix-shell' did not evaluate to a derivation

```

When comparing the build outputs of `nix develop --profile` and `nix build .#devShells`, I see that:

- the former points to `/nix/store/5v1am6j7rqfd9k3zqdqzd21gg11jz9ha-nix-shell-env` which looks like a JSON file that can be activated
- the latter points to `/nix/store/hbxw6mlmwbcld9jxamhjcwmigzzbzh5g-nix-shell` which looks like a shell script (which I’m assuming is meant to be internal?)

Here’s an excerpt of `./devshell` after running the `nix build` command.

```auto
------------------------------------------------------------
 WARNING: the existence of this path is not guaranteed.
 It is an internal implementation detail for pkgs.mkShell.
------------------------------------------------------------

declare -x AR="ar"
declare -x AS="as"
declare -x CC="gcc"
declare -x CONFIG_SHELL="/nix/store/c9mv5v53f7vy3wd00ah0f77k509mzmn7-bash-5.3p15/bin/bash"
declare -x CXX="g++"
declare -x GZIP_NO_TIMESTAMPS="1"
declare -x HOME="/homeless-shelter"
# ... More `declare` statements ...

```

So, under the hood, what’s the difference between the two?  
Is it possible to make `nix build` behave so that it outputs something that can be interpreted by `nix develop`?

Thanks!

* * *

1. From [this post](https://www.reddit.com/r/NixOS/comments/1as7dp3/comment/kqoukxp/), which seems outdated as it suggests trying to build the `devShell.x86_64-linux` attribute which doesn’t exist in my flake. I’m assuming it used to be exposed by the default flake template at some point but not anymore?
