You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I need to specify a github acess-token, if I want to include private repositories as flake inputs. I manage my /etc/nix/nix.conf declaratively on NixOS.
Describe the solution you'd like
I would like to keep the access token in a separate file using something like agenix or sops, to not have it end up in the nix store and in version control.
An option like acess-tokens-file = /run/secrets/access-tokens would be nice.
Ideally I'd be able to specify different access tokens in different files, e.g. acess-tokens-files = github.com=/run/secrets/github-acess-token gitlab.com=/run/secrets/gitlab-acess-token
Describe alternatives you've considered
Add access-token to ǹix.extraOptions`
the token ends up in the nix store (and version control)
Add access-token to ~/.config/nix/nix.conf
This works, if I don't manage user config using home-manager, but it has the downside, that I have a separate secret to keep track of. It would be more convenient to be able to keep the secrets with all other secrets in agenix and use an access-tokens-files option in /etc/nix/nix.conf
Reacted by Alex Martens, Roberto Abdelkader Martínez Pérez, Poscat, Cathal, Jason Pickens, oluceps, Ben Mellor, ryan4yin | 二花, wzy, Maximilian Bosch and 70 more
I guess that'd only work if the tokens can't start with an @, no idea whether that's possible or not. I'd rather go with access-token = @/run/secrets/github-acess-token @/run/secrets/gitlab-acess-token where each file contain the full key-value pair.
Any idea how hard this would be to implement? I'd like to be able to throw sops-nix at this since I'm hitting GH rate limits frequently lately.
After thinking about this today, it would be a bad idea to add a semantic to include file content directly into the configuration file value.
However, this would require more work but I think would play a lot nicer with automation and a clear syntax would be to use attributes sets, in which .file would expect a path to read the content and assign to the value. But I have no idea if this is easily doable, nix.conf syntax doesn't seem to allow this easily at first glance.
Notice the ! before the include. A missing file is an error without it. When you run nixos-rebuild switch, nix.conf is validated, but before sops-nix creates the secret file.
Also, notice that the user running the nix command needs read access to the secret file.
What is not possible with include is to have different tokens in different files, the last access-token declaration overwrites the previous ones.
Reacted by Naïm Camille Favier, Roberto Abdelkader Martínez Pérez, wrvsrx, Mohamed Laradji, Basti, Kasper Kondzielski, Damián Franco Álvarez, ryan4yin | 二花, Günter Zöchbauer, Sergei Zimmerman and 34 more
Reacted by basbebe, Adrian, Pavel Atanasov, ppenguin, ryan4yin | 二花, eihqnh, Luke Brendgen, Hannes and Zihad
I would argue that #6536 (comment) is enough and we don't need an extra feature for this.
I disagree, because of
Notice the ! before the include. A missing file is an error without it. When you run nixos-rebuild switch, nix.conf is validated, but before sops-nix creates the secret file.
One of the nice things in nix is having build-time failures instead of run-time ones when configuring your system: having an {,extra-}access-tokens-file option could allow relying on an include directive instead of an !include one, making the system less prone to runtime surprises.
To add another point: I just put in the raw token in the sops-nix secret file and that did not work, since it has to be a the config line access-tokens = github.com=github_pat_TOKEN. Since the secret file is read as part of the configuration file for nix, every nix command failed with an error that put the secret in plaintext in the terminal.
With this behavior, the secret can more easily leak.
I guess that'd only work if the tokens can't start with an @, no idea whether that's possible or not.
If they start with an "at" @, we could also just introduce escaping, i.e. @something where "something" is a path and \@something where "something" is a token literal.
To add another point: I just put in the raw token in the sops-nix secret file and that did not work, since it has to be a the config line access-tokens = github.com=github_pat_TOKEN.
Activity
thufschmitt commentedon May 16, 2022
Rather than a separate option, we could adopt the same syntax as
builders(builders = @/some/file). Maybe even make this a more generic thingSohalt commentedon May 16, 2022
That works, if the token never starts with an ´@´. But if that's the case, I'd like the more generic solution.
I guess another option would be to use
include /run/secrets/secret-config, although that way the file has to contain more than just the access token.colemickens commentedon Aug 10, 2022
I'd also very much like to be able to specify these as separate file references, I guess maybe something like this?
Any idea how hard this would be to implement? I'd like to be able to throw
sops-nixat this since I'm hitting GH rate limits frequently lately.thufschmitt commentedon Aug 11, 2022
I guess that'd only work if the tokens can't start with an
@, no idea whether that's possible or not. I'd rather go withaccess-token = @/run/secrets/github-acess-token @/run/secrets/gitlab-acess-tokenwhere each file contain the full key-value pair.rapenne-s commentedon Sep 22, 2022
After thinking about this today, it would be a bad idea to add a semantic to include file content directly into the configuration file value.
However, this would require more work but I think would play a lot nicer with automation and a clear syntax would be to use attributes sets, in which
.filewould expect a path to read the content and assign to the value. But I have no idea if this is easily doable, nix.conf syntax doesn't seem to allow this easily at first glance.jlesquembre commentedon Sep 22, 2022
It's possible to include other files in
nix.confwithinclude, an example using sops-nix (extracted from my dotfiles):Notice the
!before the include. A missing file is an error without it. When you runnixos-rebuild switch, nix.conf is validated, but before sops-nix creates the secret file.Also, notice that the user running the nix command needs read access to the secret file.
What is not possible with
includeis to have different tokens in different files, the lastaccess-tokendeclaration overwrites the previous ones.Kha commentedon Sep 22, 2022
That's what
extra-access-tokensis for, right?jlesquembre commentedon Sep 22, 2022
👍 Right, I missed the
extra-part in nix.conf docs. Problem solved, thanks!SuperSandro2000 commentedon Sep 22, 2022
New github tokens always start with
ghp_andgh*_for enterprise and old ones where alphadecimal IIRC.Noise, trying that out right now.
tomberek commentedon Dec 14, 2022
Somewhat related, would anyone be interested more specific url matching for the tokens?
Freed-Wu commentedon Jul 8, 2023
Why not get access-token from other files like
~/.git-credentialsor~/.netrc?~/.git-credentials~/.netrc15 remaining items
ci: nix-daemonにGitHubアクセストークンを設定してrate limitを回避
axodentally commentedon Apr 13, 2026
To add another point: I just put in the raw token in the sops-nix secret file and that did not work, since it has to be a the config line
access-tokens = github.com=github_pat_TOKEN. Since the secret file is read as part of the configuration file for nix, every nix command failed with an error that put the secret in plaintext in the terminal.With this behavior, the secret can more easily leak.
con-f-use commentedon Apr 13, 2026
If they start with an "at"
@, we could also just introduce escaping, i.e.@somethingwhere "something" is a path and\@somethingwhere "something" is a token literal.That, I believe, is what sops templating is for.
feat(sops): implement GitHub token authentication for all hosts
feat(sops): implement GitHub token authentication for all hosts
Add SecretSpec credential support
Add SecretSpec credential support
ci(workflows): secure nix auth config
ci(workflows): secure nix auth config
ci(workflows): fix security gaps (#226)
ci(workflows): fix security gaps (#226)
feat(sops): implement GitHub token authentication for all hosts
ci(workflows): fix security gaps (#226)
feat(sops): implement GitHub token authentication for all hosts
ci(workflows): fix security gaps (#226)