2023-12-26 15:16:21 +05:00
|
|
|
{ self, ... }:
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.spoofdpi;
|
|
|
|
pkg = self.packages.${pkgs.system}.spoofdpi;
|
|
|
|
in {
|
|
|
|
options.services.spoofdpi = {
|
|
|
|
enable = mkEnableOption "Enables the SpoofDPI service";
|
|
|
|
|
|
|
|
address = mkOption rec {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
|
|
|
example = default;
|
|
|
|
description = "Listen address";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption rec {
|
2024-03-22 23:21:25 +05:00
|
|
|
type = types.port;
|
|
|
|
default = 8080;
|
2023-12-26 15:16:21 +05:00
|
|
|
example = default;
|
|
|
|
description = "Port";
|
|
|
|
};
|
|
|
|
|
2024-03-22 23:21:25 +05:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open services.spoofdpi.port";
|
|
|
|
};
|
|
|
|
|
2023-12-26 15:16:21 +05:00
|
|
|
dns = mkOption rec {
|
|
|
|
type = types.str;
|
|
|
|
default = "8.8.8.8";
|
|
|
|
example = default;
|
|
|
|
description = "DNS server";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.spoofdpi = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-03-22 23:21:25 +05:00
|
|
|
after = [ "network.target" ];
|
2023-12-26 15:16:21 +05:00
|
|
|
serviceConfig = {
|
|
|
|
Restart = "on-failure";
|
2024-03-22 23:21:25 +05:00
|
|
|
ExecStart = "${pkg}/bin/spoof-dpi -no-banner -addr ${cfg.address} -port ${toString cfg.port} -dns ${cfg.dns}";
|
2023-12-26 15:16:21 +05:00
|
|
|
DynamicUser = "yes";
|
|
|
|
};
|
|
|
|
};
|
2024-03-22 23:21:25 +05:00
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ cfg.port ];
|
|
|
|
};
|
2023-12-26 15:16:21 +05:00
|
|
|
};
|
|
|
|
}
|