-
Notifications
You must be signed in to change notification settings - Fork 0
/
home-manager.nix
96 lines (87 loc) · 2.73 KB
/
home-manager.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{ config, lib, makeBinaryWrapper, rustPlatform, fetchFromGitHub, pkgs, cargo, pkg-config, openssl, libseccomp, sqlcipher, ... }:
with lib;
let
cfg = config.programs.sshield;
tomlFormat = pkgs.formats.toml { };
in {
options.programs.sshield = {
enable = mkEnableOption "sshield, secure SSH agent";
extraPackages = mkOption {
type = with types; listOf package;
default = [ ];
example = literalExpression "[ ]";
description = "Extra packages available to sshield.";
};
settings = mkOption {
type = tomlFormat.type;
default = { };
example = literalExpression ''
{
database = "/home/user/.ssh.db3";
prompt = 60;
keyring = true;
}
'';
description = ''
Configuration written to
{file}`$XDG_CONFIG_HOME/sshield/sshield.toml`.
'';
};
};
config = mkIf cfg.enable {
home.packages = [ (pkgs.callPackage ./default.nix { }) ];
home.sessionVariablesExtra = ''
if [[ -z "$SSH_AUTH_SOCK" ]]; then
export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/ssh-agent
fi
'';
systemd.user.services.sshield = {
Unit = {
Description = "Secure SSH agent written in Rust";
After = [ "graphical-session.target" ];
};
Install = {
WantedBy = [ "default.target" ];
};
Service = {
ExecStart = "${pkgs.writeShellScript "sshield-serve" ''
#!/usr/bin/env bash
sshield serve
''}";
ExecStop = "${pkgs.writeShellScript "sshield-stop" ''
#!/usr/bin/env bash
rm "$XDG_RUNTIME_DIR"/ssh-agent
''}";
Restart = "on-failure";
LockPersonality = true;
PrivateNetwork = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
ProtectSystem = "strict";
PrivateMounts = true;
PrivateTmp = true;
ProtectProc = "invisible";
ProtectClock = true;
ProtectControlGroups = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
RestrictAddressFamilies = [ "AF_UNIX" ];
SystemCallArchitectures = "native";
PrivateDevices = true;
SystemCallFilter = [ "@known" "~@clock" "~@cpu-emulation" "~@raw-io" "~@reboot" "~@mount" "~@obsolete" "~@swap" "~@debug" "~@keyring" "~@pkey" "~@chown" ];
};
};
xdg.configFile = let
settings = {
"sshield/sshield.toml" = mkIf (cfg.settings != { }) {
source = tomlFormat.generate "sshield-config" cfg.settings;
};
};
in settings;
};
}