nixos/xray: init service
This commit is contained in:
parent
0264a93087
commit
96f7444bc8
|
@ -198,6 +198,15 @@
|
||||||
<link xlink:href="options.html#opt-virtualisation.appvm.enable">virtualisation.appvm</link>.
|
<link xlink:href="options.html#opt-virtualisation.appvm.enable">virtualisation.appvm</link>.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
[xray] (https://github.com/XTLS/Xray-core), a fully compatible
|
||||||
|
v2ray-core replacement. Features XTLS, which when enabled on
|
||||||
|
server and client, brings UDP FullCone NAT to proxy setups.
|
||||||
|
Available as
|
||||||
|
<link xlink:href="options.html#opt-services.xray.enable">services.xray</link>.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<link xlink:href="https://github.com/mozilla-services/syncstorage-rs">syncstorage-rs</link>,
|
<link xlink:href="https://github.com/mozilla-services/syncstorage-rs">syncstorage-rs</link>,
|
||||||
|
|
|
@ -79,6 +79,9 @@ In addition to numerous new and upgraded packages, this release has the followin
|
||||||
## New Services {#sec-release-22.11-new-services}
|
## New Services {#sec-release-22.11-new-services}
|
||||||
|
|
||||||
- [appvm](https://github.com/jollheef/appvm), Nix based app VMs. Available as [virtualisation.appvm](options.html#opt-virtualisation.appvm.enable).
|
- [appvm](https://github.com/jollheef/appvm), Nix based app VMs. Available as [virtualisation.appvm](options.html#opt-virtualisation.appvm.enable).
|
||||||
|
|
||||||
|
- [xray] (https://github.com/XTLS/Xray-core), a fully compatible v2ray-core replacement. Features XTLS, which when enabled on server and client, brings UDP FullCone NAT to proxy setups. Available as [services.xray](options.html#opt-services.xray.enable).
|
||||||
|
|
||||||
- [syncstorage-rs](https://github.com/mozilla-services/syncstorage-rs), a self-hostable sync server for Firefox. Available as [services.firefox-syncserver](options.html#opt-services.firefox-syncserver.enable).
|
- [syncstorage-rs](https://github.com/mozilla-services/syncstorage-rs), a self-hostable sync server for Firefox. Available as [services.firefox-syncserver](options.html#opt-services.firefox-syncserver.enable).
|
||||||
|
|
||||||
- [dragonflydb](https://dragonflydb.io/), a modern replacement for Redis and Memcached. Available as [services.dragonflydb](#opt-services.dragonflydb.enable).
|
- [dragonflydb](https://dragonflydb.io/), a modern replacement for Redis and Memcached. Available as [services.dragonflydb](#opt-services.dragonflydb.enable).
|
||||||
|
|
|
@ -989,6 +989,7 @@
|
||||||
./services/networking/xinetd.nix
|
./services/networking/xinetd.nix
|
||||||
./services/networking/xl2tpd.nix
|
./services/networking/xl2tpd.nix
|
||||||
./services/networking/x2goserver.nix
|
./services/networking/x2goserver.nix
|
||||||
|
./services/networking/xray.nix
|
||||||
./services/networking/xrdp.nix
|
./services/networking/xrdp.nix
|
||||||
./services/networking/yggdrasil.nix
|
./services/networking/yggdrasil.nix
|
||||||
./services/networking/zerobin.nix
|
./services/networking/zerobin.nix
|
||||||
|
|
96
nixos/modules/services/networking/xray.nix
Normal file
96
nixos/modules/services/networking/xray.nix
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
|
||||||
|
services.xray = {
|
||||||
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
Whether to run xray server.
|
||||||
|
|
||||||
|
Either `settingsFile` or `settings` must be specified.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
default = pkgs.xray;
|
||||||
|
defaultText = literalExpression "pkgs.xray";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
Which xray package to use.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
settingsFile = mkOption {
|
||||||
|
type = types.nullOr types.path;
|
||||||
|
default = null;
|
||||||
|
example = "/etc/xray/config.json";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The absolute path to the configuration file.
|
||||||
|
|
||||||
|
Either `settingsFile` or `settings` must be specified.
|
||||||
|
|
||||||
|
See <https://www.v2fly.org/en_US/config/overview.html>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
settings = mkOption {
|
||||||
|
type = types.nullOr (types.attrsOf types.unspecified);
|
||||||
|
default = null;
|
||||||
|
example = {
|
||||||
|
inbounds = [{
|
||||||
|
port = 1080;
|
||||||
|
listen = "127.0.0.1";
|
||||||
|
protocol = "http";
|
||||||
|
}];
|
||||||
|
outbounds = [{
|
||||||
|
protocol = "freedom";
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The configuration object.
|
||||||
|
|
||||||
|
Either `settingsFile` or `settings` must be specified.
|
||||||
|
|
||||||
|
See <https://www.v2fly.org/en_US/config/overview.html>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
config = let
|
||||||
|
cfg = config.services.xray;
|
||||||
|
settingsFile = if cfg.settingsFile != null
|
||||||
|
then cfg.settingsFile
|
||||||
|
else pkgs.writeTextFile {
|
||||||
|
name = "xray.json";
|
||||||
|
text = builtins.toJSON cfg.settings;
|
||||||
|
checkPhase = ''
|
||||||
|
${cfg.package}/bin/xray -test -config $out
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
in mkIf cfg.enable {
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = (cfg.settingsFile == null) != (cfg.settings == null);
|
||||||
|
message = "Either but not both `settingsFile` and `settings` should be specified for xray.";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
systemd.services.xray = {
|
||||||
|
description = "xray Daemon";
|
||||||
|
after = [ "network.target" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
DynamicUser = true;
|
||||||
|
ExecStart = "${cfg.package}/bin/xray -config ${settingsFile}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue