Add xdg settings, cache, cleanup script
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
{ user ? throw "user argument is required" }: { pkgs, ... }:
|
||||
{ user ? throw "user argument is required" }: { config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
hmConfig = config.home-manager.users."${user.name}";
|
||||
gpgPath = "${hmConfig.xdg.dataHome}/gnupg";
|
||||
in
|
||||
{
|
||||
home-manager.users."${user.name}" = {
|
||||
programs.gpg = {
|
||||
enable = true;
|
||||
homedir = gpgPath;
|
||||
};
|
||||
|
||||
services.gpg-agent = {
|
||||
enable = true;
|
||||
defaultCacheTtl = 31536000;
|
||||
@@ -11,22 +20,24 @@
|
||||
systemd.user = {
|
||||
services.gpg-agent-import = let
|
||||
init = pkgs.writeShellScriptBin "import-gpg-keys" ''
|
||||
export GNUPGHOME=${gpgPath}
|
||||
|
||||
for keyfile in "${user.home}"/.config/sops-nix/secrets/gpg-agent/*.key; do
|
||||
passfile="''${keyfile%.key}.pass"
|
||||
|
||||
if [ -f "$passfile" ]; then
|
||||
gpg --batch --yes --pinentry-mode loopback --passphrase-file "$passfile" --import "$keyfile"
|
||||
${pkgs.gnupg}/bin/gpg2 --batch --yes --pinentry-mode loopback --passphrase-file "$passfile" --import "$keyfile"
|
||||
else
|
||||
gpg --batch --yes --import "$keyfile"
|
||||
${pkgs.gnupg}/bin/gpg2 --batch --yes --import "$keyfile"
|
||||
fi
|
||||
|
||||
gpg --with-colons --import-options show-only --import "$keyfile" | grep '^fpr' | cut -d: -f10 | while read -r KEY_ID; do
|
||||
echo "$KEY_ID:6:" >> "${user.home}"/.gnupg/otrust.txt
|
||||
${pkgs.gnupg}/bin/gpg2 --with-colons --import-options show-only --import "$keyfile" | grep '^fpr' | cut -d: -f10 | while read -r KEY_ID; do
|
||||
echo "$KEY_ID:6:" >> "${gpgPath}"/otrust.txt
|
||||
done
|
||||
done
|
||||
|
||||
gpg --import-ownertrust "${user.home}"/.gnupg/otrust.txt
|
||||
rm "${user.home}"/.gnupg/otrust.txt
|
||||
${pkgs.gnupg}/bin/gpg2 --import-ownertrust "${gpgPath}"/otrust.txt
|
||||
rm "${gpgPath}"/otrust.txt
|
||||
'';
|
||||
in {
|
||||
Unit = {
|
||||
@@ -43,7 +54,12 @@
|
||||
Install = { WantedBy = [ "default.target" ]; };
|
||||
};
|
||||
|
||||
tmpfiles.rules = [ "d ${user.home}/.gnupg 0700 ${user.name} users -" ];
|
||||
tmpfiles.rules = [ "d ${hmConfig.xdg.dataHome}/gnupg 0700 ${user.name} users -" ];
|
||||
};
|
||||
|
||||
sops.secrets = {
|
||||
"gpg-agent/pgp.key" = { };
|
||||
"gpg-agent/pgp.pass" = { };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user