Skip to content

Commit

Permalink
feat(nix): add git and gnupg
Browse files Browse the repository at this point in the history
  • Loading branch information
sbulav committed Jan 31, 2024
1 parent aadf046 commit ce47b59
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 24 deletions.
2 changes: 1 addition & 1 deletion fish/config.fish
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ set -gx PATH $PATH $HOME/.krew/bin
set -gx FISH_KUBECTL_COMPLETION_COMPLETE_CRDS 0

# Load ssh keys into ssh-agent
load_keys
#load_keys

# Load env credentials
if begin; test -f ~/.ssh/env-credentials;end
Expand Down
14 changes: 7 additions & 7 deletions fish/functions/load_keys.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function load_keys --description 'Load keys from .ssh folder starting with id_'
if status --is-login
for key in (ls $HOME/.ssh/id_* | grep -v pub)
ssh-add -q $key
end
end
end
#function load_keys --description 'Load keys from .ssh folder starting with id_'
# if status --is-login
# for key in (ls $HOME/.ssh/id_* | grep -v pub)
# ssh-add -q $key
# end
# end
#end
19 changes: 11 additions & 8 deletions nix/modules/nixos/suites/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ in {
};

config = mkIf cfg.enable {
system.nix.enable = true;
system.security.doas.enable = false;
system = {
nix.enable = true;

fonts.enable = true;
locale.enable = true;
time.enable = true;
xkb.enable = true;

security.doas.enable = false;
security.gpg.enable = true;
};

hardware.audio.enable = true;
hardware.networking.enable = true;
Expand All @@ -26,12 +35,6 @@ in {
# add sys custom build package
environment.systemPackages = [pkgs.custom.sys];

system = {
fonts.enable = true;
locale.enable = true;
time.enable = true;
xkb.enable = true;
};
custom.tools = {
git.enable = true;
};
Expand Down
70 changes: 70 additions & 0 deletions nix/modules/nixos/system/security/gpg/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
options,
config,
pkgs,
lib,
inputs,
...
}:
with lib;
with lib.custom; let
cfg = config.system.security.gpg;

gpgConf = ''
use-agent
pinentry-mode loopback
'';

gpgAgentConf = ''
enable-ssh-support
default-cache-ttl 28800
max-cache-ttl 28800
allow-loopback-pinentry
'';
in {
options.system.security.gpg = with types; {
enable = mkBoolOpt false "Whether or not to enable GPG.";
agentTimeout = mkOpt int 5 "The amount of time to wait before continuing with shell init.";
};

config = mkIf cfg.enable {
# NOTE: This should already have been added by programs.gpg, but
# keeping it here for now just in case.
environment.shellInit = ''
export GPG_TTY="$(tty)"
export SSH_AUTH_SOCK=$(${pkgs.gnupg}/bin/gpgconf --list-dirs agent-ssh-socket)
${pkgs.coreutils}/bin/timeout ${builtins.toString cfg.agentTimeout} ${pkgs.gnupg}/bin/gpgconf --launch gpg-agent
gpg_agent_timeout_status=$?
if [ "$gpg_agent_timeout_status" = 124 ]; then
# Command timed out...
echo "GPG Agent timed out..."
echo 'Run "gpgconf --launch gpg-agent" to try and launch it again.'
fi
'';

environment.systemPackages = with pkgs; [
gnupg
pinentry-curses
pinentry-qt
];

programs = {
ssh.startAgent = false;

gnupg.agent = {
enable = true;
enableSSHSupport = true;
enableExtraSocket = true;
};
};

home.file = {
".gnupg/.keep".text = "";

".gnupg/gpg.conf".text = gpgConf;
".gnupg/gpg-agent.conf".text = gpgAgentConf;
};
};
}
22 changes: 22 additions & 0 deletions nix/modules/nixos/system/security/keyring/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
options,
config,
lib,
pkgs,
...
}:
with lib;
with lib.custom; let
cfg = config.custom.security.keyring;
in {
options.custom.security.keyring = with types; {
enable = mkBoolOpt false "Whether to enable gnome keyring.";
};

config = mkIf cfg.enable {
environment.systemPackages = with pkgs; [
gnome.gnome-keyring
gnome.libgnome-keyring
];
};
}
35 changes: 27 additions & 8 deletions nix/modules/nixos/tools/git/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
with lib;
with lib.custom; let
cfg = config.custom.tools.git;
# gpg = config.custom.security.gpg;
gpg = config.system.security.gpg;
user = config.custom.user;
in {
options.custom.tools.git = with types; {
enable = mkBoolOpt false "Whether or not to install and configure git.";
userName = mkOpt types.str user.fullName "The name to configure git with.";
userEmail = mkOpt types.str user.email "The email to configure git with.";
signingKey =
mkOpt types.str "9762169A1B35EA68" "The key ID to sign commits with.";
mkOpt types.str "7C43420F61CEC7FB" "The key ID to sign commits with.";
};

config = mkIf cfg.enable {
Expand All @@ -27,18 +27,37 @@ in {
enable = true;
inherit (cfg) userName userEmail;
lfs = enabled;
# signing = {
# key = cfg.signingKey;
# signByDefault = mkIf gpg.enable true;
# };
signing = {
key = cfg.signingKey;
signByDefault = mkIf gpg.enable true;
};
extraConfig = {
init = {defaultBranch = "main";};
init = {
defaultBranch = "master";
templatedir = "~/.git_template";
whitespace = "trailing-space,space-before-tab";
};
core = {
pager = "bat";
};
pull = {rebase = true;};
push = {autoSetupRemote = true;};
core = {whitespace = "trailing-space,space-before-tab";};
safe = {
directory = "${config.users.users.${user.name}.home}/work/config";
};
merge = {
tool = "nvimdiff";
conflictstyle = "diff3";
};
diff = {
tool = "nvimdiff";
};
difftool = {
prompt = false;
};
mergetool = {
prompt = false;
};
};
};
};
Expand Down

0 comments on commit ce47b59

Please sign in to comment.