···
+
cfg = config.services.sshwifty;
+
format = pkgs.formats.json { };
+
settings = format.generate "sshwifty.json" cfg.settings;
+
options.services.sshwifty = {
+
enable = lib.mkEnableOption "Sshwifty";
+
package = lib.mkPackageOption pkgs "sshwifty" { };
+
settings = lib.mkOption {
+
Configuration for Sshwifty. See
+
[the Sshwifty documentation](https://github.com/nirui/sshwifty/tree/master?tab=readme-ov-file#configuration)
+
sharedKeyFile = lib.mkOption {
+
type = lib.types.nullOr lib.types.path;
+
description = "Path to a file containing the shared key.";
+
socks5PasswordFile = lib.mkOption {
+
type = lib.types.nullOr lib.types.path;
+
description = "Path to a file containing the SOCKS5 password.";
+
config = lib.mkIf cfg.enable {
+
systemd.services.sshwifty = {
+
description = "Sshwifty";
+
after = [ "network.target" ];
+
wantedBy = [ "multi-user.target" ];
+
${lib.optionalString (cfg.sharedKeyFile != null || cfg.socks5PasswordFile != null) (
+
lib.concatStringsSep " " [
+
(lib.optionalString (cfg.sharedKeyFile != null && cfg.socks5PasswordFile != null) "* .[2]")
+
cfg.sharedKeyFile != null
+
) "<(echo \"{\\\"SharedKey\\\":\\\"$(cat $CREDENTIALS_DIRECTORY/sharedkey)\\\"}\")")
+
cfg.socks5PasswordFile != null
+
) "<(echo \"{\\\"Socks5Password\\\":\\\"$(cat $CREDENTIALS_DIRECTORY/socks5pass)\\\"}\")")
+
"> /run/sshwifty/sshwifty.json"
+
cfg.sharedKeyFile != null || cfg.socks5PasswordFile != null
+
) "export SSHWIFTY_CONFIG=/run/sshwifty/sshwifty.json"}
+
cfg.sharedKeyFile == null && cfg.socks5PasswordFile == null
+
) "export SSHWIFTY_CONFIG=${settings}"}
+
exec ${lib.getExe cfg.package}
+
RuntimeDirectory = "sshwifty";
+
RuntimeDirectoryMode = "0750";
+
++ lib.optionals (cfg.sharedKeyFile != null) [ "sharedkey:${cfg.sharedKeyFile}" ]
+
++ lib.optionals (cfg.socks5PasswordFile != null) [ "socks5pass:${cfg.socks5PasswordFile}" ];
+
LockPersonality = true;
+
MemoryDenyWriteExecute = true;
+
NoNewPrivileges = true;
+
ProtectControlGroups = true;
+
ProtectHostname = true;
+
ProtectKernelLogs = true;
+
ProtectKernelModules = true;
+
ProtectKernelTunables = true;
+
RestrictRealtime = true;
+
RestrictSUIDSGID = true;
+
CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
+
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
+
PrivateTmp = "disconnected";
+
ProtectProc = "invisible";
+
ProtectSystem = "strict";
+
RestrictAddressFamilies = [
+
SystemCallArchitectures = "native";
+
meta.maintainers = [ lib.maintainers.ungeskriptet ];