mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 16:33:15 +00:00
nixos/dae: fix override existed config issue
This commit is contained in:
parent
ac4fd1a109
commit
bc07451d4f
@ -18,6 +18,7 @@ in
|
|||||||
|
|
||||||
package = mkPackageOptionMD pkgs "dae" { };
|
package = mkPackageOptionMD pkgs "dae" { };
|
||||||
|
|
||||||
|
|
||||||
assets = mkOption {
|
assets = mkOption {
|
||||||
type = with types;(listOf path);
|
type = with types;(listOf path);
|
||||||
default = with pkgs; [ v2ray-geoip v2ray-domain-list-community ];
|
default = with pkgs; [ v2ray-geoip v2ray-domain-list-community ];
|
||||||
@ -70,8 +71,8 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
configFile = mkOption {
|
configFile = mkOption {
|
||||||
type = types.path;
|
type = with types; (nullOr path);
|
||||||
default = "/etc/dae/config.dae";
|
default = null;
|
||||||
example = "/path/to/your/config.dae";
|
example = "/path/to/your/config.dae";
|
||||||
description = mdDoc ''
|
description = mdDoc ''
|
||||||
The path of dae config file, end with `.dae`.
|
The path of dae config file, end with `.dae`.
|
||||||
@ -79,12 +80,10 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = mkOption {
|
config = mkOption {
|
||||||
type = types.str;
|
type = with types; (nullOr str);
|
||||||
default = ''
|
default = null;
|
||||||
global{}
|
|
||||||
routing{}
|
|
||||||
'';
|
|
||||||
description = mdDoc ''
|
description = mdDoc ''
|
||||||
|
WARNING: This option will expose store your config unencrypted world-readable in the nix store.
|
||||||
Config text for dae.
|
Config text for dae.
|
||||||
|
|
||||||
See <https://github.com/daeuniverse/dae/blob/main/example.dae>.
|
See <https://github.com/daeuniverse/dae/blob/main/example.dae>.
|
||||||
@ -103,11 +102,6 @@ in
|
|||||||
environment.systemPackages = [ cfg.package ];
|
environment.systemPackages = [ cfg.package ];
|
||||||
systemd.packages = [ cfg.package ];
|
systemd.packages = [ cfg.package ];
|
||||||
|
|
||||||
environment.etc."dae/config.dae" = {
|
|
||||||
mode = "0400";
|
|
||||||
source = pkgs.writeText "config.dae" cfg.config;
|
|
||||||
};
|
|
||||||
|
|
||||||
networking = lib.mkIf cfg.openFirewall.enable {
|
networking = lib.mkIf cfg.openFirewall.enable {
|
||||||
firewall =
|
firewall =
|
||||||
let portToOpen = cfg.openFirewall.port;
|
let portToOpen = cfg.openFirewall.port;
|
||||||
@ -121,7 +115,13 @@ in
|
|||||||
systemd.services.dae =
|
systemd.services.dae =
|
||||||
let
|
let
|
||||||
daeBin = lib.getExe cfg.package;
|
daeBin = lib.getExe cfg.package;
|
||||||
TxChecksumIpGenericWorkaround = with lib;(getExe pkgs.writeShellApplication {
|
|
||||||
|
configPath =
|
||||||
|
if cfg.configFile != null
|
||||||
|
then cfg.configFile else pkgs.writeText "config.dae" cfg.config;
|
||||||
|
|
||||||
|
TxChecksumIpGenericWorkaround = with lib;
|
||||||
|
(getExe pkgs.writeShellApplication {
|
||||||
name = "disable-tx-checksum-ip-generic";
|
name = "disable-tx-checksum-ip-generic";
|
||||||
text = with pkgs; ''
|
text = with pkgs; ''
|
||||||
iface=$(${iproute2}/bin/ip route | ${lib.getExe gawk} '/default/ {print $5}')
|
iface=$(${iproute2}/bin/ip route | ${lib.getExe gawk} '/default/ {print $5}')
|
||||||
@ -132,9 +132,10 @@ in
|
|||||||
{
|
{
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStartPre = [ "" "${daeBin} validate -c ${cfg.configFile}" ]
|
LoadCredential = [ "config.dae:${configPath}" ];
|
||||||
|
ExecStartPre = [ "" "${daeBin} validate -c \${CREDENTIALS_DIRECTORY}/config.dae" ]
|
||||||
++ (with lib; optional cfg.disableTxChecksumIpGeneric TxChecksumIpGenericWorkaround);
|
++ (with lib; optional cfg.disableTxChecksumIpGeneric TxChecksumIpGenericWorkaround);
|
||||||
ExecStart = [ "" "${daeBin} run --disable-timestamp -c ${cfg.configFile}" ];
|
ExecStart = [ "" "${daeBin} run --disable-timestamp -c \${CREDENTIALS_DIRECTORY}/config.dae" ];
|
||||||
Environment = "DAE_LOCATION_ASSET=${cfg.assetsPath}";
|
Environment = "DAE_LOCATION_ASSET=${cfg.assetsPath}";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -149,13 +150,21 @@ in
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
assertion = !((config.services.dae.config != "global{}\nrouting{}\n")
|
assertion = !((config.services.dae.config != null)
|
||||||
&& (config.services.dae.configFile != "/etc/dae/config.dae"));
|
&& (config.services.dae.configFile != null));
|
||||||
message = ''
|
message = ''
|
||||||
Option `config` and `configFile` could not be set
|
Option `config` and `configFile` could not be set
|
||||||
at the same time.
|
at the same time.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
assertion = !((config.services.dae.config == null)
|
||||||
|
&& (config.services.dae.configFile == null));
|
||||||
|
message = ''
|
||||||
|
Either `config` or `configFile` should be set.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,10 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: {
|
|||||||
};
|
};
|
||||||
services.dae = {
|
services.dae = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
config = ''
|
||||||
|
global{}
|
||||||
|
routing{}
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user