From 937c6bd39adfcbe7231f34bf218bfe9993a9ebc8 Mon Sep 17 00:00:00 2001 From: Guanran Wang Date: Sat, 23 Dec 2023 16:47:14 +0800 Subject: [PATCH] nixos/clash: minor adjustments --- nixos/modules/services/clash.nix | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/nixos/modules/services/clash.nix b/nixos/modules/services/clash.nix index 2cc12d4..799c419 100644 --- a/nixos/modules/services/clash.nix +++ b/nixos/modules/services/clash.nix @@ -7,7 +7,7 @@ cfg = config.services.clash; in { options.services.clash = { - enable = lib.mkEnableOption "Whether to enable Clash."; + enable = lib.mkEnableOption "Whether to enable Clash, A rule-based proxy in Go"; package = lib.mkPackageOption pkgs "clash" {}; }; @@ -20,27 +20,27 @@ in { }; ### systemd service + # https://en.clash.wiki/introduction/service.html#systemd + # https://wiki.metacubex.one/startup/service/#systemd systemd.services."clash" = { - description = "Clash Daemon"; + description = "Clash daemon, A rule-based proxy in Go."; after = ["network-online.target"]; wantedBy = ["multi-user.target"]; serviceConfig = { - Type = "simple"; - WorkingDirectory = "/etc/clash"; + # TODO: DynamicUser + # DynamicUser = true; + # LoadCredential = "credentials:${config.sops.secrets."clash-config".path}"; + + # https://man.archlinux.org/man/systemd.exec.5 + ConfigurationDirectory = "clash"; User = [config.users.users."clash".name]; Group = [config.users.groups."clash".name]; ExecStart = "${lib.getExe cfg.package} -d /etc/clash"; - Restart = "on-failure"; - CapabilityBoundingSet = [ - "CAP_NET_ADMIN" - "CAP_NET_BIND_SERVICE" - "CAP_NET_RAW" - ]; - AmbientCapabilities = [ - "CAP_NET_ADMIN" - "CAP_NET_BIND_SERVICE" - "CAP_NET_RAW" - ]; + + # Capability, inherited from Clash wiki + # https://man.archlinux.org/man/core/man-pages/capabilities.7.en + CapabilityBoundingSet = ["CAP_NET_ADMIN" "CAP_NET_BIND_SERVICE" "CAP_NET_RAW"]; + AmbientCapabilities = ["CAP_NET_ADMIN" "CAP_NET_BIND_SERVICE" "CAP_NET_RAW"]; }; }; };