Hello lovely Nix community
I wonder how can I change setting (like firewall settings or configs from applications) in my configuration.nix without internet? If I do it without the internet it errors out because it can’t fetch some nix urls. So how to use nixos fully when I am offline?
Thanks in advance!
This discussion has helped me in the past:
Specifically, you probably want:
nixos-rebuild switch --option substitute false
Depending on exactly what your config is, this may only work if you haven’t had any garbage collection since, and of course only if none of your config requires new things from the internet. For changes to the firewall this is likely ok.
In addition, watch out for using fetchurl
without a hash, this will make nix redownload the path whenever its cache expires, which is either every 15 minutes or two hours by default, I forget which.
With the answer to your direct question out of the way, here’s my answer to the potential underlying problem:
If you’re asking specifically because you often want to unblock ports while offline, give nixos-firewall-tool a go - or use nftables and learn how to modify the chain by hand if you need more control. Generally, if you find yourself updating your configuration to make changes at runtime, it’s probably best to find a way to allow yourself to make those changes non-declaratively (while setting some declarative default). NixOS generally has good support for this if you’re looking out for it.
A similar answer to the thread @badcold linked would e.g. be to use networkmanager.ensureProfiles
.