I setup a next.js project with pkgs.mkshell, and used nix develop to automatically build the project. However, when I leave the shell, the files persist. How should/can(?) I setup my shell.nix so that files in the directory it drops down into are automatically removed when leaving the ephemeral shell?

3 points

WDYM by “directory it drops down into”? nix develop stays in your current working directory.

If I wanted to clean up state, I’d create a clean task in the build system or build a clean script that I’d wire up to the flake outputs such that you could run nix run .#clean.

permalink
report
reply
0 points

I see, thanks

As for “drop down”, I was loosely referring to the newly spawned terminal

clean scripts get the job done. I was thinking of persisting changes to the filesystem state only while the ephemeral shell was live, that way every time I ran nix develop i would check to make sure my project could automatically build, and If there was any state that needed persisting, I would have to commit/push and label those changes somewhere before ending my session

permalink
report
parent
reply
2 points

You could achieve something like that using bubblewrap; effectively a container. You can tell it to mount tmpfs wherever you like. That has other issues though.

That’s a big of a complex setup which other people potentially working with you may not want to have. A clean task is just better. If you’re using git anyways, you can also just use git clean.

permalink
report
parent
reply

NixOS

!nixos@infosec.pub

Create post

NixOS is a Linux distribution built on top of the Nix package manager. Its declarative configuration allows reliable system upgrades via several official channels of stability and size.

This community discusses NixOS, Nix, and everything related.

Community stats

  • 24

    Monthly active users

  • 99

    Posts

  • 165

    Comments

Community moderators