Premise
Currently it’s really really easy to accidentally put your secret keys in to the nix-store, there’s plenty of bad advise around, especially for resource acquisition, nix is great until you can’t use a fetcher, and then there’s a billion ways to mess up manually acquiring resources, It’s also just a pain in the ass (coughheavilymoddedfactorioserver), nix can fetch resources, and it has access to every application that one might use to download, the issue is that you cannot cleanly, nicely use them inside the sandbox.
If you want to see a package that does everything wrong, see the Factorio Downloader that writes secrets in to the nix-store while trying avoid transient issues.
The entire point of nix to me is that I can type nix build
and it builds an entire workable package, or full system, I should not need to wrangle all sorts of weird things, that otherwise could be just a prompt.
A solution should not leak secrets to arbitrary users via nix-build, it should not need raised privileged, and it should not need me to do non-nix things, or manage a reverse-proxy, or accidentally write your secrets to bash history.
Current solutions include:
-
NIX_PATH
- probably leaks to nix-store
-
netrc
- only works with basic http authentication. (RIP circa 2004)
- probably not safe on a multi-user system due to it being available to all builders.
-
impureEvars
- only supported on single user installs, doesn’t actually work on NixOS!
-
ad-hoc scripting to load the files in to store manually
- Not compatible with nixpkgs.
- undermines the point of using nix.
-
Setup a http proxy injecting headers or full custom backend
- requires a running, error-prone, system already setup (not newbie friendly)
- only works with http style payloads (steamcmd no workie)
-
providing secrets over http/udp/tcp
- technically works, but http/udp/tcp is not secure
-
extra-sandbox-paths
- my favorite
- careful use of setfacl so nix-bld can access the path.
- potentially unsafe on a multi-user system.
- requires the user to be in the trusted-user list.
- e.x. GitHub - YellowOnion/factorio-mods-nix: Factorio mods for Nix
Actual solution
Nix really needs a way so that with minimal setup nix build
can work, providing a prompt to the user if possible, and then passing these secrets from the front end, to the builders safely and securely.
It seems like a MVP could be constructed using pre-build-hook
and post-build-hook
, and some per-derivation sandbox paths, Still not exactly sure how to authenticate which derivation gets which secrets. but it seems trivial to implement.
But this would need to be added to nix
itself, so that nixpkgs could start accepting fetchers of this sort, I assume any packages that use these fetchers would be no different to the requireFile, except you could wrap your package in a “secret provider” override for nixos-config, it could be easily documented in nixpkgs, the fetchers that use this functionality can be audited by nixpkg maintainers in one location instead of the many different ad-hoc solutions inside nixpkgs or outside it.