Rebuild is caching the flake

I have infected a host via ssh and now have a bare NixOS server. I then apply my flake like this:

nixos-rebuild switch --flake git+ssh://

and get the system I want. :tada:

But when I make a change to the repo and re-run the same command nothing happens.
I seems like the content for that repo is cached. Why is that? Is there a way around that?

In the long run it’s probably better to look into NixOps (or something) but I thought I start to learn the land like this first.

That’s the tarball-ttl nix setting, which can be set in /etc/nix/nix.conf, ~/.config/nix/nix.conf, or on the cmdline with --tarball-ttl. From man nix.conf:

The number of seconds a downloaded tarball is considered fresh. If the cached tarball is stale, Nix will check whether it is still up to date using the ETag header. Nix will download a new version if the ETag header is unsupported, or the cached ETag doesn’t match.

Setting the TTL to 0 forces Nix to always check if the tarball is up to date.

Nix caches tarballs in $XDG_CACHE_HOME/nix/tarballs.

Files fetched via NIX_PATH, fetchGit, fetchMercurial, fetchTarball, and fetchurl respect this TTL.

Default: 3600

1 Like

I knew there must be a way. Thanks!

Unfortunately at least nixos-rebuild switch does not seem to have a --tarball-ttl command line parameter. I guess I could set the ttl in my flake though.

Oh, yea, anything that can be set in nix.conf can also be set on the CLI like --option tarball-ttl 0. The --tarball-ttl argument is actually just shorthand for --option tarball-ttl, and not all of the CLI tools support this shorthand for every option.

1 Like

Hm. Are you sure?
Because I cannot find anything in the man page.
And trying various variations neither did work.

nixos-rebuild --option "tarball-ttl=0" switch --flake git+ssh://
nixos-rebuild switch --flake git+ssh:// --option "tarball-ttl 0"

yea, I’m fairly sure. And it would be --option tarball-ttl 0, not --option tarball-ttl=0. I’m not sure why that wouldn’t be working. Unless maybe --flake doesn’t respect tarball-ttl? But I’m fairly sure it does. So I’m surprised it isn’t working for you.

Ah, Nix likes to cache things. I’ve solved this in the past by asking Nix to fetch the latest source for a flake uri:

nix flake prefetch github:my/repo

Then you can run whatever commands you need to that rely on that flake.

1 Like

Hm. I tried both versions (“tarball-ttl=0” and “tarball-ttl 0”) without success.
Also not sure which position to add the “–option” at - or whether that matters.

@tcurdt I ran into the same problem while developing my flake on one machine and continually doing nixos-rebuild switch on another. It seems there is an (undocumented, or at least not present in the man-page) option called --refresh, which seems to ensure the flake is refreshed from Github, even if the cache is still considered fresh. Hope it helps.

1 Like

--option tarball-ttl 0 (without the quotes) should work

1 Like