flake/darwin/modules/services/mihomo.nix

52 lines
1.3 KiB
Nix
Raw Normal View History

2024-01-03 15:30:30 +00:00
{
lib,
config,
pkgs,
...
}: let
2024-07-08 10:10:35 +00:00
cfg = config.services.mihomo;
2024-01-03 15:30:30 +00:00
in {
2024-07-08 10:10:35 +00:00
options.services.mihomo = {
enable = lib.mkEnableOption "Whether to enable Mihomo, A rule-based proxy in Go.";
package = lib.mkPackageOption pkgs "mihomo" {};
2024-01-03 15:30:30 +00:00
webui = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.path;
description = ''
Local web interface to use.
- metacubexd:
- http://d.metacubex.one
- https://metacubex.github.io/metacubexd
- https://metacubexd.pages.dev
- yacd:
- https://yacd.haishan.me
2024-07-08 10:10:35 +00:00
- clash-dashboard:
2024-01-03 15:30:30 +00:00
- https://clash.razord.top
'';
};
extraOpts = lib.mkOption {
default = null;
type = lib.types.nullOr lib.types.str;
2024-01-03 15:30:30 +00:00
description = "Extra command line options to use.";
};
};
config = lib.mkIf cfg.enable {
### launchd service
# TODO: not run as root user
2024-07-08 10:10:35 +00:00
launchd.daemons."mihomo" = {
2024-07-21 10:09:21 +00:00
command = lib.concatStringsSep " " [
2024-01-03 15:30:30 +00:00
(lib.getExe cfg.package)
2024-07-08 10:10:35 +00:00
"-d /etc/mihomo"
2024-01-03 15:30:30 +00:00
(lib.optionalString (cfg.webui != null) "-ext-ui ${cfg.webui}")
(lib.optionalString (cfg.extraOpts != null) cfg.extraOpts)
];
serviceConfig = {
RunAtLoad = true;
KeepAlive.NetworkState = true;
};
};
};
}