Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions modules/programs/rbw.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ let

configDir =
if pkgs.stdenv.hostPlatform.isDarwin then "Library/Application Support" else config.xdg.configHome;
socketPath = "$XDG_RUNTIME_DIR/rbw/ssh-agent-socket";
in
{
meta.maintainers = with lib.maintainers; [ ambroisie ];
Expand Down Expand Up @@ -93,13 +94,63 @@ in
managed by Home Manager.
'';
};
sshAgent = lib.mkOption {
Comment thread
minionflo marked this conversation as resolved.
type = lib.types.bool;
description = "rbw as an SSH Agent";
default = false;
};

systemd = {
enable = lib.mkOption {
type = lib.types.bool;
description = "run the rbw agent in systemd";
default = true;
};
targets = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "targets for the rbw systemd service";
default = [ "default.target" ];
};
};
};

config = lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "programs.rbw.sshAgent" pkgs lib.platforms.linux)
];

home.packages = [ cfg.package ];

home.file."${configDir}/rbw/config.json" = lib.mkIf (cfg.settings != null) {
source = jsonFormat.generate "rbw-config.json" (lib.filterAttrs (_: v: v != null) cfg.settings);
};

systemd.user.services.rbw-agent = lib.mkIf cfg.systemd.enable {
Service = {
ExecStart = "${cfg.package}/bin/rbw-agent --no-daemonize";
PIDFile = "rbw/pidfile";
};
Install = {
WantedBy = cfg.systemd.targets;
};
Unit = {
After = [ "network.target" ];
Description = "rbw Agent";
Documentation = "man:rbw-agent(1)";
};
};

sshAuthSock = lib.mkIf cfg.sshAgent {
Comment thread
minionflo marked this conversation as resolved.
enable = true;
systemd = {
socketProviderUnit = lib.mkIf cfg.systemd.enable "rbw-agent.service";
};
initialization = {
bash = "export SSH_AUTH_SOCK=${socketPath}";
fish = "set -x SSH_AUTH_SOCK ${socketPath}";
zsh = "export SSH_AUTH_SOCK=${socketPath}";
nushell = "$env.SSH_AUTH_SOCK = ${socketPath}";
};
};
};
}
Loading