1 { config, lib, pkgs, ... }:
4 cfg = config.services.dae;
6 genAssetsDrv = paths: pkgs.symlinkJoin {
12 meta.maintainers = with lib.maintainers; [ pokon548 oluceps ];
15 services.dae = with lib;{
16 enable = mkEnableOption "dae, a Linux high-performance transparent proxy solution based on eBPF";
18 package = mkPackageOption pkgs "dae" { };
22 type = with types;(listOf path);
23 default = with pkgs; [ v2ray-geoip v2ray-domain-list-community ];
24 defaultText = literalExpression "with pkgs; [ v2ray-geoip v2ray-domain-list-community ]";
26 Assets required to run dae.
30 assetsPath = mkOption {
32 default = "${genAssetsDrv assets}/share/v2ray";
33 defaultText = literalExpression ''
40 The path which contains geolocation database.
41 This option will override `assets`.
45 openFirewall = mkOption {
46 type = with types; submodule {
48 enable = mkEnableOption "opening {option}`port` in the firewall";
52 Port to be opened. Consist with field `tproxy_port` in config file.
61 defaultText = literalExpression ''
68 Open the firewall port.
72 configFile = mkOption {
73 type = with types; (nullOr path);
75 example = "/path/to/your/config.dae";
77 The path of dae config file, end with `.dae`.
82 type = with types; (nullOr str);
85 WARNING: This option will expose store your config unencrypted world-readable in the nix store.
88 See <https://github.com/daeuniverse/dae/blob/main/example.dae>.
92 disableTxChecksumIpGeneric =
93 mkEnableOption "" // { description = "See <https://github.com/daeuniverse/dae/issues/43>"; };
98 config = lib.mkIf cfg.enable
101 environment.systemPackages = [ cfg.package ];
102 systemd.packages = [ cfg.package ];
104 networking = lib.mkIf cfg.openFirewall.enable {
106 let portToOpen = cfg.openFirewall.port;
109 allowedTCPPorts = [ portToOpen ];
110 allowedUDPPorts = [ portToOpen ];
114 systemd.services.dae =
116 daeBin = lib.getExe cfg.package;
119 if cfg.configFile != null
120 then cfg.configFile else pkgs.writeText "config.dae" cfg.config;
122 TxChecksumIpGenericWorkaround = with lib;
123 (getExe pkgs.writeShellApplication {
124 name = "disable-tx-checksum-ip-generic";
126 iface=$(${iproute2}/bin/ip route | ${lib.getExe gawk} '/default/ {print $5}')
127 ${lib.getExe ethtool} -K "$iface" tx-checksum-ip-generic off
132 wantedBy = [ "multi-user.target" ];
134 LoadCredential = [ "config.dae:${configPath}" ];
135 ExecStartPre = [ "" "${daeBin} validate -c \${CREDENTIALS_DIRECTORY}/config.dae" ]
136 ++ (with lib; optional cfg.disableTxChecksumIpGeneric TxChecksumIpGenericWorkaround);
137 ExecStart = [ "" "${daeBin} run --disable-timestamp -c \${CREDENTIALS_DIRECTORY}/config.dae" ];
138 Environment = "DAE_LOCATION_ASSET=${cfg.assetsPath}";
144 assertion = lib.pathExists (toString (genAssetsDrv cfg.assets) + "/share/v2ray");
146 Packages in `assets` has no preset paths included.
147 Please set `assetsPath` instead.
152 assertion = !((config.services.dae.config != null)
153 && (config.services.dae.configFile != null));
155 Option `config` and `configFile` could not be set
161 assertion = !((config.services.dae.config == null)
162 && (config.services.dae.configFile == null));
164 Either `config` or `configFile` should be set.