gnupg: Support declarative GPG keysfiles#810
Conversation
rycee
left a comment
There was a problem hiding this comment.
Thanks for the contribution! I've added a few comments.
642e750 to
1413ee2
Compare
veehaitch
left a comment
There was a problem hiding this comment.
I'd like to revive this PR :) happy to lend a hand.
| importGgpKeys = dag.entryAfter ["linkGeneration"] ( | ||
| let | ||
| importKey = keyfile: '' | ||
| ${pkgs.gnupg}/bin/gpg --import ${lib.escapeShellArg (builtins.toString (pkgs.copyPathToStore keyfile))} |
There was a problem hiding this comment.
Instead of adding the given keys to any preexisting state of GnuPG, we could also create the file pubring.kbx in its entirety and symlink it similar to .gnupg/gpg.conf.
There was a problem hiding this comment.
I really like this idea, but I'm unsure how to implement it
There was a problem hiding this comment.
How does this work though, does this then prevent me from ever importing gpg keys without adding them to my h-m configuration first? I'd prefer to just have them imported on top, like I think is happening now.
There was a problem hiding this comment.
@colemickens That's correct. I think, however, that such an approach is well aligned with the goal of achieving a declarative, reproducible configuration. Moreover, home-manager works like this in other places as well, for example programs.git.
@MilesBreslin We could create a derivation which sets export GNUPGHOME=$TMPDIR, imports all configured keys and then produces pubring.kbx as an output.
There was a problem hiding this comment.
Hm. To me, Git's configuration is completely static, whereas I regularly have to import gpg keys on the fly to work with sops or just do general things; so I view them differently (however, I am of course a fan of having everything managed, so I get this desire).
If GPG had a way to read from multiple pubrings, I'd be a lot more excited about pre-forming and symlinking the primary one.
Can we support both, maybe?
| ''; | ||
| }; | ||
|
|
||
| keyfiles = mkOption { |
There was a problem hiding this comment.
It would be great to have an option to also give the ownertrust of a key. This information is stored in the file .gnupg/trustdb.gpg. Unfortuantely, it is regularly written to by GnuPG even on operations which one would regard as read-only. Therefore, symlinking into the Nix store (as I'd suggest for the public keys, see below) would likely cause unexpected issues. It could be a middle ground to copy the trustdb.gpg file instead of symlinking it.
cd5b8dd to
b7a1ece
Compare
MilesBreslin
left a comment
There was a problem hiding this comment.
I've added mutable and immutable support for both key files and trust. Since the trustdb needs to be writable, it gets copied on each activation.
|
|
||
| # Copy immutable trust | ||
| (optionalString (trust != null && !cfg.mutableTrust) '' | ||
| install -m 0700 ${keyringFiles}/trustdb.gpg "$HOME/.gnupg/trustdb.gpg" |
There was a problem hiding this comment.
Is there a better way to do this?
|
Thank you for your contribution! I marked this pull request as stale due to inactivity. If this remains inactive for another 7 days, I will close this PR. Please read the relevant sections below before commenting. If you are the original author of the PR
If you are not the original author of the issue
|
|
:( I'd still like to see this. |
|
Is there something I can do to push this along? I've been running with my own version of this for a while now, but I'd still like to get it upstream. |
|
I finally had a bit of time to look at this more carefully. Rebased and made a few cleanups and such. The most noticeable one is renaming Please have a look at the last few commits and see if I made any mistakes. |
|
These changes look good at a glance. It's been a while since I've looked at this, but it looks like everything is there and should be functional. I'll give it a go this weekend. Thanks for helping organize this. This looks better! |
|
Tested on my configuration. It seems to be working with no issues now. I use |
Looks like this needs to be more forceful. |
|
Looking into this further, this is just a migration issue on my end. This is working as intended. |
|
@MilesBreslin Nice, so this is OK to merge? If so, then I can squash and merge as soon as possible. |
|
@rycee Yes, this should be good to merge. |
|
Great, merged to master now. Good job! |
|
Thank you for making this possible. This works great. |
PR nix-community#810 (cherry picked from commit ea1794a)
PR nix-community#810 (cherry picked from commit ea1794a)
Adds a new option
programs.gpg.keyfilesto be an array of paths to gpg key exports.Is implemented as an activation script that runs
gpg --import $keyfor each key.