tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
nixos/dae: fix override existed config issue
oluceps
2 years ago
bc07451d
ac4fd1a1
+36
-23
2 changed files
expand all
collapse all
unified
split
nixos
modules
services
networking
dae.nix
tests
dae.nix
+32
-23
nixos/modules/services/networking/dae.nix
···
18
18
19
19
package = mkPackageOptionMD pkgs "dae" { };
20
20
21
21
+
21
22
assets = mkOption {
22
23
type = with types;(listOf path);
23
24
default = with pkgs; [ v2ray-geoip v2ray-domain-list-community ];
···
70
71
};
71
72
72
73
configFile = mkOption {
73
73
-
type = types.path;
74
74
-
default = "/etc/dae/config.dae";
74
74
+
type = with types; (nullOr path);
75
75
+
default = null;
75
76
example = "/path/to/your/config.dae";
76
77
description = mdDoc ''
77
78
The path of dae config file, end with `.dae`.
···
79
80
};
80
81
81
82
config = mkOption {
82
82
-
type = types.str;
83
83
-
default = ''
84
84
-
global{}
85
85
-
routing{}
86
86
-
'';
83
83
+
type = with types; (nullOr str);
84
84
+
default = null;
87
85
description = mdDoc ''
86
86
+
WARNING: This option will expose store your config unencrypted world-readable in the nix store.
88
87
Config text for dae.
89
88
90
89
See <https://github.com/daeuniverse/dae/blob/main/example.dae>.
···
103
102
environment.systemPackages = [ cfg.package ];
104
103
systemd.packages = [ cfg.package ];
105
104
106
106
-
environment.etc."dae/config.dae" = {
107
107
-
mode = "0400";
108
108
-
source = pkgs.writeText "config.dae" cfg.config;
109
109
-
};
110
110
-
111
105
networking = lib.mkIf cfg.openFirewall.enable {
112
106
firewall =
113
107
let portToOpen = cfg.openFirewall.port;
···
121
115
systemd.services.dae =
122
116
let
123
117
daeBin = lib.getExe cfg.package;
124
124
-
TxChecksumIpGenericWorkaround = with lib;(getExe pkgs.writeShellApplication {
125
125
-
name = "disable-tx-checksum-ip-generic";
126
126
-
text = with pkgs; ''
127
127
-
iface=$(${iproute2}/bin/ip route | ${lib.getExe gawk} '/default/ {print $5}')
128
128
-
${lib.getExe ethtool} -K "$iface" tx-checksum-ip-generic off
129
129
-
'';
130
130
-
});
118
118
+
119
119
+
configPath =
120
120
+
if cfg.configFile != null
121
121
+
then cfg.configFile else pkgs.writeText "config.dae" cfg.config;
122
122
+
123
123
+
TxChecksumIpGenericWorkaround = with lib;
124
124
+
(getExe pkgs.writeShellApplication {
125
125
+
name = "disable-tx-checksum-ip-generic";
126
126
+
text = with pkgs; ''
127
127
+
iface=$(${iproute2}/bin/ip route | ${lib.getExe gawk} '/default/ {print $5}')
128
128
+
${lib.getExe ethtool} -K "$iface" tx-checksum-ip-generic off
129
129
+
'';
130
130
+
});
131
131
in
132
132
{
133
133
wantedBy = [ "multi-user.target" ];
134
134
serviceConfig = {
135
135
-
ExecStartPre = [ "" "${daeBin} validate -c ${cfg.configFile}" ]
135
135
+
LoadCredential = [ "config.dae:${configPath}" ];
136
136
+
ExecStartPre = [ "" "${daeBin} validate -c \${CREDENTIALS_DIRECTORY}/config.dae" ]
136
137
++ (with lib; optional cfg.disableTxChecksumIpGeneric TxChecksumIpGenericWorkaround);
137
137
-
ExecStart = [ "" "${daeBin} run --disable-timestamp -c ${cfg.configFile}" ];
138
138
+
ExecStart = [ "" "${daeBin} run --disable-timestamp -c \${CREDENTIALS_DIRECTORY}/config.dae" ];
138
139
Environment = "DAE_LOCATION_ASSET=${cfg.assetsPath}";
139
140
};
140
141
};
···
149
150
}
150
151
151
152
{
152
152
-
assertion = !((config.services.dae.config != "global{}\nrouting{}\n")
153
153
-
&& (config.services.dae.configFile != "/etc/dae/config.dae"));
153
153
+
assertion = !((config.services.dae.config != null)
154
154
+
&& (config.services.dae.configFile != null));
154
155
message = ''
155
156
Option `config` and `configFile` could not be set
156
157
at the same time.
158
158
+
'';
159
159
+
}
160
160
+
161
161
+
{
162
162
+
assertion = !((config.services.dae.config == null)
163
163
+
&& (config.services.dae.configFile == null));
164
164
+
message = ''
165
165
+
Either `config` or `configFile` should be set.
157
166
'';
158
167
}
159
168
];
+4
nixos/tests/dae.nix
···
14
14
};
15
15
services.dae = {
16
16
enable = true;
17
17
+
config = ''
18
18
+
global{}
19
19
+
routing{}
20
20
+
'';
17
21
};
18
22
};
19
23