home/gpg: create key refresh timer and add keyservers

This commit is contained in:
Oystein Kristoffer Tveit 2024-08-02 17:24:25 +02:00
parent 773cfc9dab
commit 227c710265
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
3 changed files with 75 additions and 7 deletions

View File

@ -15,7 +15,7 @@ in {
./programs/gdb.nix ./programs/gdb.nix
./programs/gh.nix ./programs/gh.nix
./programs/git ./programs/git
./programs/gpg.nix ./programs/gpg
./programs/less.nix ./programs/less.nix
./programs/neovim.nix ./programs/neovim.nix
./programs/tmux.nix ./programs/tmux.nix

View File

@ -0,0 +1,61 @@
{ config, pkgs, lib, ... }:
let
cfg = config.programs.gpg;
in
{
options = {
programs.gpg.auto-refresh-keys = {
enable = lib.mkEnableOption "a timer that automatically refreshes your gpg keys";
frequency = lib.mkOption {
default = "daily";
type = lib.types.str;
description = ''
How often to refresh keys.
:::{.note}
This value is passed to the systemd
timer configuration as the onCalendar option. See
{manpage}`systemd.time(7)`
for more information about the format.
:::
'';
};
};
};
config = {
systemd.user.services.gpg-refresh-keys = lib.mkIf cfg.auto-refresh-keys.enable {
Unit = {
Description = "Refresh gpg keys";
Documentation = [ "man:gpg(1)" ];
};
Service = {
Type = "oneshot";
CPUSchedulingPolicy = "idle";
IOSchedulingClass = "idle";
ExecStart = "${lib.getExe cfg.package} --refresh-keys";
Environment = [
"GNUPGHOME=${cfg.homedir}"
];
};
};
systemd.user.timers.gpg-refresh-keys = lib.mkIf cfg.auto-refresh-keys.enable {
Unit = {
Description = "Refresh gpg keys";
Documentation = [ "man:gpg(1)" ];
};
Timer = {
Unit = "gpg-refresh-keys.service";
OnCalendar = cfg.auto-refresh-keys.frequency;
Persistent = true;
};
Install = {
WantedBy = [ "timers.target" ];
};
};
};
}

View File

@ -1,15 +1,22 @@
{ pkgs, config, ... }: { pkgs, config, ... }:
{ {
imports = [
./auto-refresh-keys.nix
];
programs.gpg = { programs.gpg = {
enable = true; enable = true;
homedir = "${config.xdg.configHome}/gnupg"; homedir = "${config.xdg.configHome}/gnupg";
# TODO: declare public keys and trust declaratively
# mutableKeys = false;
# mutableTrust = false;
# publicKeys = [];
# settings = {
# }; auto-refresh-keys.enable = true;
settings = {
keyserver = [
"hkps://keys.openpgp.org"
"hkps://keyserver.ubuntu.com"
"hkps://pgp.mit.edu"
];
};
}; };
services.gpg-agent = { services.gpg-agent = {