Skip to content

Commit

Permalink
modules: init shadowsocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ocfox committed Sep 29, 2024
1 parent f61181d commit 9c0bd3e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{ ... }:
{
imports = [
(import ./shadowsocks.nix)
];
};
}
33 changes: 33 additions & 0 deletions modules/shadowsocks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.shadowsocks-rust;
settingsFormat = pkgs.formats.json { };
configfile = settingsFormat.generate "config.json" cfg.settings;
in
{
options = {
services.shadowsocks-rust = {
enable = lib.mkEnableOption "shadowsocks-rust";
settings = lib.mkOption {
type = lib.types.submodule { freeformType = settingsFormat.type; };
default = { };
};
};
};

config = lib.mkIf cfg.enable {
environment.etc."shadowsocks-rust/config.json".source = configfile;

systemd.services.shadowsocks-rust = {
CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
wantedBy = [ "multi-user.target" ];
ExecStart = "${lib.getExe pkgs.shadowsocks-rust} -c /etc/shadowsocks-rust/config.json";
};
};
}

0 comments on commit 9c0bd3e

Please sign in to comment.