Merge pull request #252978 from oluceps/dae-upup
dae,nixos/dae: 0.2.4 -> 0.3.0
This commit is contained in:
commit
cfb61436d7
|
@ -1,41 +1,161 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.dae;
|
cfg = config.services.dae;
|
||||||
|
assets = cfg.assets;
|
||||||
|
genAssetsDrv = paths: pkgs.symlinkJoin {
|
||||||
|
name = "dae-assets";
|
||||||
|
inherit paths;
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
meta.maintainers = with lib.maintainers; [ pokon548 ];
|
meta.maintainers = with lib.maintainers; [ pokon548 oluceps ];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
services.dae = {
|
services.dae = with lib;{
|
||||||
enable = lib.options.mkEnableOption (lib.mdDoc "the dae service");
|
enable = mkEnableOption
|
||||||
package = lib.mkPackageOptionMD pkgs "dae" { };
|
(mdDoc "A Linux high-performance transparent proxy solution based on eBPF");
|
||||||
|
|
||||||
|
package = mkPackageOptionMD pkgs "dae" { };
|
||||||
|
|
||||||
|
assets = mkOption {
|
||||||
|
type = with types;(listOf path);
|
||||||
|
default = with pkgs; [ v2ray-geoip v2ray-domain-list-community ];
|
||||||
|
defaultText = literalExpression "with pkgs; [ v2ray-geoip v2ray-domain-list-community ]";
|
||||||
|
description = mdDoc ''
|
||||||
|
Assets required to run dae.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
assetsPath = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "${genAssetsDrv assets}/share/v2ray";
|
||||||
|
defaultText = literalExpression ''
|
||||||
|
(symlinkJoin {
|
||||||
|
name = "dae-assets";
|
||||||
|
paths = assets;
|
||||||
|
})/share/v2ray
|
||||||
|
'';
|
||||||
|
description = mdDoc ''
|
||||||
|
The path which contains geolocation database.
|
||||||
|
This option will override `assets`.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
openFirewall = mkOption {
|
||||||
|
type = with types; submodule {
|
||||||
|
options = {
|
||||||
|
enable = mkEnableOption "enable";
|
||||||
|
port = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
description = ''
|
||||||
|
Port to be opened. Consist with field `tproxy_port` in config file.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
default = {
|
||||||
|
enable = true;
|
||||||
|
port = 12345;
|
||||||
|
};
|
||||||
|
defaultText = literalExpression ''
|
||||||
|
{
|
||||||
|
enable = true;
|
||||||
|
port = 12345;
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = mdDoc ''
|
||||||
|
Open the firewall port.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
configFile = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
default = "/etc/dae/config.dae";
|
||||||
|
example = "/path/to/your/config.dae";
|
||||||
|
description = mdDoc ''
|
||||||
|
The path of dae config file, end with `.dae`.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = ''
|
||||||
|
global{}
|
||||||
|
routing{}
|
||||||
|
'';
|
||||||
|
description = mdDoc ''
|
||||||
|
Config text for dae.
|
||||||
|
|
||||||
|
See <https://github.com/daeuniverse/dae/blob/main/example.dae>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
disableTxChecksumIpGeneric =
|
||||||
|
mkEnableOption (mdDoc "See <https://github.com/daeuniverse/dae/issues/43>");
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf config.services.dae.enable {
|
config = lib.mkIf cfg.enable
|
||||||
networking.firewall.allowedTCPPorts = [ 12345 ];
|
|
||||||
networking.firewall.allowedUDPPorts = [ 12345 ];
|
|
||||||
|
|
||||||
systemd.services.dae = {
|
{
|
||||||
unitConfig = {
|
environment.systemPackages = [ cfg.package ];
|
||||||
Description = "dae Service";
|
systemd.packages = [ cfg.package ];
|
||||||
Documentation = "https://github.com/daeuniverse/dae";
|
|
||||||
After = [ "network-online.target" "systemd-sysctl.service" ];
|
environment.etc."dae/config.dae" = {
|
||||||
Wants = [ "network-online.target" ];
|
mode = "0400";
|
||||||
|
source = pkgs.writeText "config.dae" cfg.config;
|
||||||
};
|
};
|
||||||
|
|
||||||
serviceConfig = {
|
networking = lib.mkIf cfg.openFirewall.enable {
|
||||||
User = "root";
|
firewall =
|
||||||
ExecStartPre = "${lib.getExe cfg.package} validate -c /etc/dae/config.dae";
|
let portToOpen = cfg.openFirewall.port;
|
||||||
ExecStart = "${lib.getExe cfg.package} run --disable-timestamp -c /etc/dae/config.dae";
|
in
|
||||||
ExecReload = "${lib.getExe cfg.package} reload $MAINPID";
|
{
|
||||||
LimitNPROC = 512;
|
allowedTCPPorts = [ portToOpen ];
|
||||||
LimitNOFILE = 1048576;
|
allowedUDPPorts = [ portToOpen ];
|
||||||
Restart = "on-abnormal";
|
};
|
||||||
Type = "notify";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.services.dae =
|
||||||
|
let
|
||||||
|
daeBin = lib.getExe cfg.package;
|
||||||
|
TxChecksumIpGenericWorkaround = with lib;(getExe pkgs.writeShellApplication {
|
||||||
|
name = "disable-tx-checksum-ip-generic";
|
||||||
|
text = with pkgs; ''
|
||||||
|
iface=$(${iproute2}/bin/ip route | ${lib.getExe gawk} '/default/ {print $5}')
|
||||||
|
${lib.getExe ethtool} -K "$iface" tx-checksum-ip-generic off
|
||||||
|
'';
|
||||||
|
});
|
||||||
|
in
|
||||||
|
{
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStartPre = [ "" "${daeBin} validate -c ${cfg.configFile}" ]
|
||||||
|
++ (with lib; optional cfg.disableTxChecksumIpGeneric TxChecksumIpGenericWorkaround);
|
||||||
|
ExecStart = [ "" "${daeBin} run --disable-timestamp -c ${cfg.configFile}" ];
|
||||||
|
Environment = "DAE_LOCATION_ASSET=${cfg.assetsPath}";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = lib.pathExists (toString (genAssetsDrv cfg.assets) + "/share/v2ray");
|
||||||
|
message = ''
|
||||||
|
Packages in `assets` has no preset paths included.
|
||||||
|
Please set `assetsPath` instead.
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
assertion = !((config.services.dae.config != "global{}\nrouting{}\n")
|
||||||
|
&& (config.services.dae.configFile != "/etc/dae/config.dae"));
|
||||||
|
message = ''
|
||||||
|
Option `config` and `configFile` could not be set
|
||||||
|
at the same time.
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,6 +211,7 @@ in {
|
||||||
custom-ca = handleTest ./custom-ca.nix {};
|
custom-ca = handleTest ./custom-ca.nix {};
|
||||||
croc = handleTest ./croc.nix {};
|
croc = handleTest ./croc.nix {};
|
||||||
darling = handleTest ./darling.nix {};
|
darling = handleTest ./darling.nix {};
|
||||||
|
dae = handleTest ./dae.nix {};
|
||||||
dconf = handleTest ./dconf.nix {};
|
dconf = handleTest ./dconf.nix {};
|
||||||
deepin = handleTest ./deepin.nix {};
|
deepin = handleTest ./deepin.nix {};
|
||||||
deluge = handleTest ./deluge.nix {};
|
deluge = handleTest ./deluge.nix {};
|
||||||
|
|
29
nixos/tests/dae.nix
Normal file
29
nixos/tests/dae.nix
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import ./make-test-python.nix ({ lib, pkgs, ... }: {
|
||||||
|
|
||||||
|
name = "dae";
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
maintainers = with lib.maintainers; [ oluceps ];
|
||||||
|
};
|
||||||
|
|
||||||
|
nodes.machine = { pkgs, ... }: {
|
||||||
|
environment.systemPackages = [ pkgs.curl ];
|
||||||
|
services.nginx = {
|
||||||
|
enable = true;
|
||||||
|
statusPage = true;
|
||||||
|
};
|
||||||
|
services.dae = {
|
||||||
|
enable = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = ''
|
||||||
|
machine.wait_for_unit("nginx.service")
|
||||||
|
machine.wait_for_unit("dae.service")
|
||||||
|
|
||||||
|
machine.wait_for_open_port(80)
|
||||||
|
|
||||||
|
machine.succeed("curl --fail --max-time 10 http://localhost")
|
||||||
|
'';
|
||||||
|
|
||||||
|
})
|
|
@ -1,29 +1,25 @@
|
||||||
{ lib
|
{ lib
|
||||||
, clang
|
, clang
|
||||||
, fetchFromGitHub
|
, fetchFromGitHub
|
||||||
, symlinkJoin
|
|
||||||
, buildGoModule
|
, buildGoModule
|
||||||
, makeWrapper
|
|
||||||
, v2ray-geoip
|
|
||||||
, v2ray-domain-list-community
|
|
||||||
}:
|
}:
|
||||||
buildGoModule rec {
|
buildGoModule rec {
|
||||||
pname = "dae";
|
pname = "dae";
|
||||||
version = "0.2.4";
|
version = "0.3.0";
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
owner = "daeuniverse";
|
owner = "daeuniverse";
|
||||||
repo = "dae";
|
repo = "dae";
|
||||||
rev = "v${version}";
|
rev = "v${version}";
|
||||||
hash = "sha256-MVmx37q5nbgaUehPJ2C2UjVyx48/U/vA3NeBx6Zcmg8=";
|
hash = "sha256-WiJqhXYehuUCLEuVbsQkmTntuH1srtePtZgYBSTbxiw=";
|
||||||
fetchSubmodules = true;
|
fetchSubmodules = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
vendorHash = "sha256-oeMAekLWRJzmkmge4LmrVSFRzHZ/dStX+CvLtuYOsog=";
|
vendorHash = "sha256-fb4PEMhV8+5zaRJyl+nYi2BHcOUDUVAwxce2xaRt5JA=";
|
||||||
|
|
||||||
proxyVendor = true;
|
proxyVendor = true;
|
||||||
|
|
||||||
nativeBuildInputs = [ clang makeWrapper ];
|
nativeBuildInputs = [ clang ];
|
||||||
|
|
||||||
ldflags = [
|
ldflags = [
|
||||||
"-s"
|
"-s"
|
||||||
|
@ -33,7 +29,7 @@ buildGoModule rec {
|
||||||
];
|
];
|
||||||
|
|
||||||
preBuild = ''
|
preBuild = ''
|
||||||
make CFLAGS="-D__REMOVE_BPF_PRINTK -fno-stack-protector" \
|
make CFLAGS="-D__REMOVE_BPF_PRINTK -fno-stack-protector -Wno-unused-command-line-argument" \
|
||||||
NOSTRIP=y \
|
NOSTRIP=y \
|
||||||
ebpf
|
ebpf
|
||||||
'';
|
'';
|
||||||
|
@ -41,15 +37,8 @@ buildGoModule rec {
|
||||||
# network required
|
# network required
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
|
|
||||||
assetsDrv = symlinkJoin {
|
|
||||||
name = "dae-assets";
|
|
||||||
paths = [ v2ray-geoip v2ray-domain-list-community ];
|
|
||||||
};
|
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
install -Dm444 install/dae.service $out/lib/systemd/system/dae.service
|
install -Dm444 install/dae.service $out/lib/systemd/system/dae.service
|
||||||
wrapProgram $out/bin/dae \
|
|
||||||
--suffix DAE_LOCATION_ASSET : $assetsDrv/share/v2ray
|
|
||||||
substituteInPlace $out/lib/systemd/system/dae.service \
|
substituteInPlace $out/lib/systemd/system/dae.service \
|
||||||
--replace /usr/bin/dae $out/bin/dae
|
--replace /usr/bin/dae $out/bin/dae
|
||||||
'';
|
'';
|
||||||
|
|
Loading…
Reference in a new issue