9 cfg = config.services.sing-box;
10 settingsFormat = pkgs.formats.json { };
15 maintainers = with lib.maintainers; [ nickcao ];
20 enable = lib.mkEnableOption "sing-box universal proxy platform";
22 package = lib.mkPackageOption pkgs "sing-box" { };
24 settings = lib.mkOption {
25 type = lib.types.submodule {
26 freeformType = settingsFormat.type;
29 geoip.path = lib.mkOption {
30 type = lib.types.path;
31 default = "${pkgs.sing-geoip}/share/sing-box/geoip.db";
32 defaultText = lib.literalExpression "\${pkgs.sing-geoip}/share/sing-box/geoip.db";
34 The path to the sing-geoip database.
37 geosite.path = lib.mkOption {
38 type = lib.types.path;
39 default = "${pkgs.sing-geosite}/share/sing-box/geosite.db";
40 defaultText = lib.literalExpression "\${pkgs.sing-geosite}/share/sing-box/geosite.db";
42 The path to the sing-geosite database.
50 The sing-box configuration, see https://sing-box.sagernet.org/configuration/ for documentation.
52 Options containing secret data should be set to an attribute set
53 containing the attribute `_secret` - a string pointing to a file
54 containing the value the option should be set to.
60 config = lib.mkIf cfg.enable {
61 systemd.packages = [ cfg.package ];
63 systemd.services.sing-box = {
64 preStart = utils.genJqSecretsReplacementSnippet cfg.settings "/run/sing-box/config.json";
66 StateDirectory = "sing-box";
67 StateDirectoryMode = "0700";
68 RuntimeDirectory = "sing-box";
69 RuntimeDirectoryMode = "0700";
72 "${lib.getExe cfg.package} -D \${STATE_DIRECTORY} -C \${RUNTIME_DIRECTORY} run"
75 wantedBy = [ "multi-user.target" ];