Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline flake development #4250

Open
tpwrules opened this issue Nov 11, 2020 · 10 comments
Open

Offline flake development #4250

tpwrules opened this issue Nov 11, 2020 · 10 comments
Labels
feature Feature request or proposal flakes

Comments

@tpwrules
Copy link
Contributor

In #2890, the flake system was fixed to stop built flakes from being garbage collected. However, "nix develop" outputs still are it seems. I can't figure out how to set it up so I can develop offline if a garbage collection has run.

@edolstra edolstra added flakes feature Feature request or proposal labels Nov 19, 2020
@edolstra
Copy link
Member

Yeah, this has been gone for a while (1b49479). It will need to be revived in a way that doesn't require fetching all flake inputs eagerly.

@edolstra
Copy link
Member

edolstra commented Mar 15, 2021

The best way to keep a nix develop environment around is to use a profile, e.g.

# nix develop --profile ./foo # create profile
# nix develop ./foo # re-enter previously created profile

The latter command doesn't require any fetching/building.

@tpwrules
Copy link
Contributor Author

tpwrules commented Mar 23, 2021

I discovered this independently and meant to update this issue and this indeed solves the problem, almost.

The flake inputs themselves don't seem to be considered as part of the profile (e.g. the downloaded nixpkgs tarball), so if a GC cycle is run that file has to be fetched, though nothing else has to be built and it's a quick operation.

I've worked around this by including a text file with the input paths as a build input so the inputs are considered runtime dependencies and thus kept. Then the profile truly points to everything and I can garbage collect without fear. I wonder if this could/should be done automatically in Nix itself? It feels like an oversight to me.

@stale
Copy link

stale bot commented Sep 21, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Sep 21, 2021
@tpwrules
Copy link
Contributor Author

I am still interested in this being fixed. But I guess my solution was equivalent to the solution that was incompatible with lazy fetching.

@stale stale bot removed the stale label Sep 27, 2021
@mikepurvis
Copy link

I think I'm seeing this sometimes even without a GC having occurred. Literally just nix develop on a local, locked flake, and then a day later, nix develop again, and it's re-pulling the nixpkgs tarball.

Note though that this machine is running a Hydra instance, so possible Hydra is running GC on me?

@SuperSandro2000
Copy link
Member

I download nixpkgs at least every day because garbage collection always collects it. Any workaround for that?

@tpwrules
Copy link
Contributor Author

tpwrules commented Jun 4, 2022

The exact implementation depends on which type of flake output you want to keep around, but this is how I work around the problem for nix develop.

@SuperSandro2000
Copy link
Member

SuperSandro2000 commented Jun 5, 2022

I have also written this yesterday:
it creates gc-roots per directory per flake input.

gc_root_prefix="/nix/var/nix/gcroots/per-user/$USER/$(systemd-escape -p "$PWD")-flake-"
nix flake update "$@"
echo "Adding per-user gcroots..."
rm -f "$gc_root_prefix"*
nix flake archive --json 2>/dev/null | jq -r '.inputs | to_entries[] | "ln -fsT "+.value.path+" \"'"$gc_root_prefix"'"+.key+"\""' | while read -r line; do
  eval "$line"
done

@a-h
Copy link
Contributor

a-h commented Sep 20, 2023

I think it's impossible to do offline development at the moment due to #8953

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal flakes
Projects
None yet
Development

No branches or pull requests

5 participants