From 78c85b15906a3f0ace17797e07329e41f52a16ac Mon Sep 17 00:00:00 2001 From: Joshua Yuen Date: Sun, 21 Jun 2026 12:51:31 -0400 Subject: [PATCH] Add your signing key as the GPG default and trusted key list --- flake.nix | 4 ++++ homes/josh/home.nix | 5 +++-- modules/core/user.nix | 2 +- modules/homes/gpg.nix | 5 +++++ modules/options/gpg.nix | 4 ++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 8d1c2ba..1b1a4c2 100644 --- a/flake.nix +++ b/flake.nix @@ -115,6 +115,7 @@ homeConfigurations.josh = let profile = "desktop"; username = "josh"; + gpgSigningKey = null; in home-manager.lib.homeManagerConfiguration { extraSpecialArgs = { inherit inputs; @@ -123,6 +124,9 @@ }; pkgs = pkgs; modules = [ + { + modules.gpg.signingKey = gpgSigningKey; + } ./homes/josh/home.nix stylix.homeModules.stylix ]; diff --git a/homes/josh/home.nix b/homes/josh/home.nix index 9f1bd1e..89b41cb 100644 --- a/homes/josh/home.nix +++ b/homes/josh/home.nix @@ -1,12 +1,13 @@ { config, - gpgSigningKey, lib, pkgs, profile, ... }: with lib; +let gpgCfg = config.modules.gpg; +in { imports = [ ../../modules/homes @@ -34,7 +35,7 @@ with lib; name = "Joshua Yuen"; email = "joshuayuen99@gmail.com"; # We need to do this to pass through the (optional) signing key from the hosts/* file - signingkey = if gpgSigningKey != "" then gpgSigningKey else config.modules.gpg.signingKey; + signingkey = mkIf (gpgCfg.signingKey != null) gpgCfg.signingKey; }; commit.gpgsign = true; init.defaultBranch = "main"; diff --git a/modules/core/user.nix b/modules/core/user.nix index 9b2f932..2feed34 100644 --- a/modules/core/user.nix +++ b/modules/core/user.nix @@ -24,10 +24,10 @@ in profile username ; - gpgSigningKey = config.modules.gpg.signingKey; }; users.${username} = { imports = [ ../../homes/${username}/home.nix ]; + modules.gpg.signingKey = config.modules.gpg.signingKey; }; }; diff --git a/modules/homes/gpg.nix b/modules/homes/gpg.nix index 827d898..36147b2 100644 --- a/modules/homes/gpg.nix +++ b/modules/homes/gpg.nix @@ -25,6 +25,11 @@ in programs = { gpg = { enable = true; + + settings = { + default-key = mkIf (cfg.signingKey != null) cfg.signingKey; + trusted-key = mkIf (cfg.signingKey != null) cfg.signingKey; + }; }; }; }; diff --git a/modules/options/gpg.nix b/modules/options/gpg.nix index 85414bb..8b0e6fd 100644 --- a/modules/options/gpg.nix +++ b/modules/options/gpg.nix @@ -11,8 +11,8 @@ with lib; }; signingKey = mkOption { - type = types.str; - default = ""; + type = types.nullOr types.str; + default = null; description = "The key ID to sign with for git"; }; };