nixos/clash: utilize command line opts

This commit is contained in:
Guanran Wang 2023-12-25 10:58:41 +08:00
parent 82eafc1aba
commit e27bfc9672
Signed by: nyancat
SSH key fingerprint: SHA256:8oWGKciPALWut/6WA27oFKofX+6Wtc0gQnsefXLQx/8
2 changed files with 23 additions and 3 deletions

View file

@ -9,6 +9,20 @@ in {
options.services.clash = {
enable = lib.mkEnableOption "Whether to enable Clash, A rule-based proxy in Go";
package = lib.mkPackageOption pkgs "clash" {};
# TODO
webui = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.path;
};
configFile = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.path;
};
extraOpts = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.string;
};
};
config = lib.mkIf cfg.enable {
@ -35,7 +49,13 @@ in {
ConfigurationDirectory = "clash";
User = [config.users.users."clash".name];
Group = [config.users.groups."clash".name];
ExecStart = "${lib.getExe cfg.package} -d /etc/clash";
ExecStart = builtins.replaceStrings ["\n"] [" "] ''
${lib.getExe cfg.package}
-d /etc/clash
${lib.optionalString (cfg.webui != null) "-ext-ui ${cfg.webui}"}
${lib.optionalString (cfg.configFile != null) "-f ${cfg.configFile}"}
${lib.optionalString (cfg.extraOpts != null) cfg.extraOpts}
'';
# Capability, inherited from Clash wiki
# https://man.archlinux.org/man/core/man-pages/capabilities.7.en

View file

@ -7,6 +7,8 @@
services.clash = {
enable = true;
package = pkgs.clash-meta;
configFile = config.sops.secrets."clash-config".path;
webui = inputs.self.packages.${pkgs.system}.metacubexd;
};
### sops-nix
@ -14,7 +16,6 @@
owner = config.users.users."clash".name;
group = config.users.groups."clash".name;
restartUnits = ["clash.service"];
path = "/etc/clash/config.yaml";
};
### System proxy settings
@ -30,5 +31,4 @@
# - https://yacd.haishan.me
# - clash-dashboard (buggy):
# - https://clash.razord.top
environment.etc."clash/metacubexd".source = inputs.self.packages.${pkgs.system}.metacubexd;
}