formatting
This commit is contained in:
21 files changed
+843
-582
No files matched your search
@@ -3,21 +3,29 @@
|
||||
rec {
|
||||
mkAssertion = assertion: message: { inherit assertion message; };
|
||||
|
||||
requireEnabled = featureEnabled: dependencyEnabled: message:
|
||||
requireEnabled =
|
||||
featureEnabled: dependencyEnabled: message:
|
||||
mkAssertion (!featureEnabled || dependencyEnabled) message;
|
||||
|
||||
requireAvailable = featureUsed: dependencyEnabled: message:
|
||||
requireAvailable =
|
||||
featureUsed: dependencyEnabled: message:
|
||||
mkAssertion (!featureUsed || dependencyEnabled) message;
|
||||
|
||||
uniqueValues = condition: values: message:
|
||||
uniqueValues =
|
||||
condition: values: message:
|
||||
mkAssertion (!condition || builtins.length values == builtins.length (lib.unique values)) message;
|
||||
|
||||
notEqualWhen = condition: left: right: message:
|
||||
notEqualWhen =
|
||||
condition: left: right: message:
|
||||
mkAssertion (!(condition && left == right)) message;
|
||||
|
||||
forbiddenValues = condition: value: disallowed: message:
|
||||
forbiddenValues =
|
||||
condition: value: disallowed: message:
|
||||
mkAssertion (!(condition && builtins.elem value disallowed)) message;
|
||||
|
||||
exactlyOneOf = condition: values: message:
|
||||
mkAssertion (!condition || builtins.length (builtins.filter (value: value != null) values) == 1) message;
|
||||
exactlyOneOf =
|
||||
condition: values: message:
|
||||
mkAssertion (
|
||||
!condition || builtins.length (builtins.filter (value: value != null) values) == 1
|
||||
) message;
|
||||
}
|
||||
@@ -15,7 +15,14 @@ let
|
||||
preStart ? null,
|
||||
}:
|
||||
{
|
||||
inherit description after wantedBy wants requires conflicts;
|
||||
inherit
|
||||
description
|
||||
after
|
||||
wantedBy
|
||||
wants
|
||||
requires
|
||||
conflicts
|
||||
;
|
||||
}
|
||||
// lib.optionalAttrs (preStart != null) { inherit preStart; };
|
||||
in
|
||||
@@ -23,7 +30,9 @@ rec {
|
||||
mkNamedUnits =
|
||||
entries:
|
||||
lib.listToAttrs (
|
||||
map (entry: lib.nameValuePair entry.name entry.value) (builtins.filter (entry: entry.enable) entries)
|
||||
map (entry: lib.nameValuePair entry.name entry.value) (
|
||||
builtins.filter (entry: entry.enable) entries
|
||||
)
|
||||
);
|
||||
|
||||
mkRestartingService =
|
||||
@@ -54,17 +63,16 @@ rec {
|
||||
;
|
||||
})
|
||||
// {
|
||||
serviceConfig =
|
||||
{
|
||||
ExecStart = execStart;
|
||||
Restart = "on-failure";
|
||||
RestartSec = 5;
|
||||
RuntimeDirectory = runtimeDirectory;
|
||||
}
|
||||
// lib.optionalAttrs (stateDirectory != null) { StateDirectory = stateDirectory; }
|
||||
// lib.optionalAttrs (execStartPost != null) { ExecStartPost = execStartPost; }
|
||||
// lib.optionalAttrs (execStopPost != null) { ExecStopPost = execStopPost; }
|
||||
// extraServiceConfig;
|
||||
serviceConfig = {
|
||||
ExecStart = execStart;
|
||||
Restart = "on-failure";
|
||||
RestartSec = 5;
|
||||
RuntimeDirectory = runtimeDirectory;
|
||||
}
|
||||
// lib.optionalAttrs (stateDirectory != null) { StateDirectory = stateDirectory; }
|
||||
// lib.optionalAttrs (execStartPost != null) { ExecStartPost = execStartPost; }
|
||||
// lib.optionalAttrs (execStopPost != null) { ExecStopPost = execStopPost; }
|
||||
// extraServiceConfig;
|
||||
};
|
||||
|
||||
mkOneshotService =
|
||||
@@ -97,19 +105,18 @@ rec {
|
||||
;
|
||||
})
|
||||
// {
|
||||
serviceConfig =
|
||||
{
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
ExecStart = execStart;
|
||||
}
|
||||
// lib.optionalAttrs (execStop != null) { ExecStop = execStop; }
|
||||
// lib.optionalAttrs (execStartPre != null) { ExecStartPre = execStartPre; }
|
||||
// lib.optionalAttrs (execStartPost != null) { ExecStartPost = execStartPost; }
|
||||
// lib.optionalAttrs (execStopPost != null) { ExecStopPost = execStopPost; }
|
||||
// lib.optionalAttrs (runtimeDirectory != null) { RuntimeDirectory = runtimeDirectory; }
|
||||
// lib.optionalAttrs (stateDirectory != null) { StateDirectory = stateDirectory; }
|
||||
// extraServiceConfig;
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
ExecStart = execStart;
|
||||
}
|
||||
// lib.optionalAttrs (execStop != null) { ExecStop = execStop; }
|
||||
// lib.optionalAttrs (execStartPre != null) { ExecStartPre = execStartPre; }
|
||||
// lib.optionalAttrs (execStartPost != null) { ExecStartPost = execStartPost; }
|
||||
// lib.optionalAttrs (execStopPost != null) { ExecStopPost = execStopPost; }
|
||||
// lib.optionalAttrs (runtimeDirectory != null) { RuntimeDirectory = runtimeDirectory; }
|
||||
// lib.optionalAttrs (stateDirectory != null) { StateDirectory = stateDirectory; }
|
||||
// extraServiceConfig;
|
||||
};
|
||||
|
||||
mkUserRuleService =
|
||||
|
||||
@@ -55,17 +55,47 @@ let
|
||||
};
|
||||
|
||||
scripts = import ./scripts.nix {
|
||||
inherit lib pkgs singBoxCfg perAppRoutingTun selectionMode collapseNamedOutbounds hasSubscriptions;
|
||||
inherit jq python3 singBox parserScriptsPythonPath buildOutboundPy fetchSubscriptionPy;
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
singBoxCfg
|
||||
perAppRoutingTun
|
||||
selectionMode
|
||||
collapseNamedOutbounds
|
||||
hasSubscriptions
|
||||
;
|
||||
inherit
|
||||
jq
|
||||
python3
|
||||
singBox
|
||||
parserScriptsPythonPath
|
||||
buildOutboundPy
|
||||
fetchSubscriptionPy
|
||||
;
|
||||
inherit tproxyFile tunFile perAppTunFile;
|
||||
};
|
||||
|
||||
perAppRouting = import ./per-app-routing.nix {
|
||||
inherit lib pkgs cfg singBoxCfg perAppRoutingCfg perAppRoutingTun perAppRoutingTproxy;
|
||||
inherit
|
||||
lib
|
||||
pkgs
|
||||
cfg
|
||||
singBoxCfg
|
||||
perAppRoutingCfg
|
||||
perAppRoutingTun
|
||||
perAppRoutingTproxy
|
||||
;
|
||||
perAppZapretCfg = perAppZapretCfg;
|
||||
inherit perAppTunChainFile perAppTproxyRulesFile perAppZapretRulesFile;
|
||||
inherit ip nft;
|
||||
inherit awk grepBin findBin headBin seqBin sleepBin;
|
||||
inherit
|
||||
awk
|
||||
grepBin
|
||||
findBin
|
||||
headBin
|
||||
seqBin
|
||||
sleepBin
|
||||
;
|
||||
};
|
||||
|
||||
control = import ./control.nix {
|
||||
|
||||
@@ -217,20 +217,17 @@ let
|
||||
{
|
||||
enable = perAppRoutingTun.enable;
|
||||
name = "${serviceNames.perAppTun}-anchor";
|
||||
value =
|
||||
mkAnchorService perAppRouting.perAppTunSliceName "Anchor service for proxy-suite app TUN slice";
|
||||
value = mkAnchorService perAppRouting.perAppTunSliceName "Anchor service for proxy-suite app TUN slice";
|
||||
}
|
||||
{
|
||||
enable = perAppRoutingTproxy.enable;
|
||||
name = "${serviceNames.perAppTproxy}-anchor";
|
||||
value =
|
||||
mkAnchorService perAppRouting.perAppTproxySliceName "Anchor service for proxy-suite app TProxy slice";
|
||||
value = mkAnchorService perAppRouting.perAppTproxySliceName "Anchor service for proxy-suite app TProxy slice";
|
||||
}
|
||||
{
|
||||
enable = perAppZapretEnabled;
|
||||
name = "${serviceNames.perAppZapret}-anchor";
|
||||
value =
|
||||
mkAnchorService perAppRouting.perAppZapretSliceName "Anchor service for proxy-suite app zapret slice";
|
||||
value = mkAnchorService perAppRouting.perAppZapretSliceName "Anchor service for proxy-suite app zapret slice";
|
||||
}
|
||||
];
|
||||
|
||||
@@ -262,29 +259,36 @@ in
|
||||
};
|
||||
|
||||
security.polkit.enable = lib.mkIf (cfg.enable && userControlEnabled) true;
|
||||
security.polkit.extraConfig = lib.mkIf (cfg.enable && userControlEnabled) (lib.mkAfter ''
|
||||
polkit.addRule(function(action, subject) {
|
||||
if (!subject.isInGroup("${userControlCfg.group}")) {
|
||||
security.polkit.extraConfig = lib.mkIf (cfg.enable && userControlEnabled) (
|
||||
lib.mkAfter ''
|
||||
polkit.addRule(function(action, subject) {
|
||||
if (!subject.isInGroup("${userControlCfg.group}")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (action.id !== "org.freedesktop.systemd1.manage-units") {
|
||||
return null;
|
||||
}
|
||||
|
||||
var unit = action.lookup("unit");
|
||||
${polkit.userControlPolkitRules}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (action.id !== "org.freedesktop.systemd1.manage-units") {
|
||||
return null;
|
||||
}
|
||||
|
||||
var unit = action.lookup("unit");
|
||||
${polkit.userControlPolkitRules}
|
||||
|
||||
return null;
|
||||
});
|
||||
'');
|
||||
});
|
||||
''
|
||||
);
|
||||
|
||||
systemd.user.services = mkNamedUnits userServiceEntries;
|
||||
|
||||
assertions = import ../service-assertions.nix {
|
||||
inherit lib cfg derived;
|
||||
tgWsProxyCfg = cfg.tgWsProxy;
|
||||
inherit builtinTags outboundTags subscriptionTags invalidRoutingTargets;
|
||||
inherit
|
||||
builtinTags
|
||||
outboundTags
|
||||
subscriptionTags
|
||||
invalidRoutingTargets
|
||||
;
|
||||
inherit (perAppRouting)
|
||||
effectivePerAppRoutingProfileNames
|
||||
hasProxychainsProfiles
|
||||
|
||||
@@ -58,7 +58,9 @@ let
|
||||
);
|
||||
effectivePerAppRoutingProfiles =
|
||||
perAppRoutingCfg.profiles
|
||||
++ builtins.filter (profile: !(builtins.elem profile.name perAppRoutingProfileNames)) defaultPerAppRoutingProfiles;
|
||||
++ builtins.filter (
|
||||
profile: !(builtins.elem profile.name perAppRoutingProfileNames)
|
||||
) defaultPerAppRoutingProfiles;
|
||||
effectivePerAppRoutingProfileNames = map (profile: profile.name) effectivePerAppRoutingProfiles;
|
||||
|
||||
perAppRoutingProfilesFile = pkgs.writeText "proxy-suite-per-app-routing-profiles.json" (
|
||||
@@ -77,10 +79,16 @@ let
|
||||
'';
|
||||
proxychainsQuietArg = lib.optionalString perAppRoutingCfg.proxychains.quiet "-q ";
|
||||
|
||||
hasProxychainsProfiles = builtins.any (profile: profile.route == "proxychains") effectivePerAppRoutingProfiles;
|
||||
hasProxychainsProfiles = builtins.any (
|
||||
profile: profile.route == "proxychains"
|
||||
) effectivePerAppRoutingProfiles;
|
||||
hasTunProfiles = builtins.any (profile: profile.route == "tun") effectivePerAppRoutingProfiles;
|
||||
hasTproxyProfiles = builtins.any (profile: profile.route == "tproxy") effectivePerAppRoutingProfiles;
|
||||
hasZapretProfiles = builtins.any (profile: profile.route == "zapret") effectivePerAppRoutingProfiles;
|
||||
hasTproxyProfiles = builtins.any (
|
||||
profile: profile.route == "tproxy"
|
||||
) effectivePerAppRoutingProfiles;
|
||||
hasZapretProfiles = builtins.any (
|
||||
profile: profile.route == "zapret"
|
||||
) effectivePerAppRoutingProfiles;
|
||||
|
||||
perAppTunWaitForInterface = pkgs.writeShellScript "proxy-suite-per-app-tun-wait-for-interface" ''
|
||||
set -euo pipefail
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# Polkit rules granting proxy-suite group members passwordless control over services.
|
||||
{ lib, cfg, userControlCfg }:
|
||||
{
|
||||
lib,
|
||||
cfg,
|
||||
userControlCfg,
|
||||
}:
|
||||
|
||||
let
|
||||
userControlEnabled = userControlCfg.global.enable || userControlCfg.perApp.enable;
|
||||
@@ -18,4 +22,6 @@ let
|
||||
}
|
||||
'';
|
||||
in
|
||||
{ inherit userControlEnabled userControlPolkitRules; }
|
||||
{
|
||||
inherit userControlEnabled userControlPolkitRules;
|
||||
}
|
||||
@@ -100,9 +100,11 @@ let
|
||||
fi
|
||||
if [ -f "$CACHE_FILE" ]; then
|
||||
SUB_JSON=$(cat "$CACHE_FILE")
|
||||
${lib.optionalString (routingMark != null) ''
|
||||
SUB_JSON=$(${jq} --argjson m ${toString routingMark} 'map(. + {routing_mark: $m})' <<< "$SUB_JSON")
|
||||
''}OUTBOUNDS_JSON=$(${jq} --argjson sub "$SUB_JSON" '. + $sub' <<< "$OUTBOUNDS_JSON")
|
||||
${
|
||||
lib.optionalString (routingMark != null) ''
|
||||
SUB_JSON=$(${jq} --argjson m ${toString routingMark} 'map(. + {routing_mark: $m})' <<< "$SUB_JSON")
|
||||
''
|
||||
}OUTBOUNDS_JSON=$(${jq} --argjson sub "$SUB_JSON" '. + $sub' <<< "$OUTBOUNDS_JSON")
|
||||
fi
|
||||
'';
|
||||
|
||||
@@ -117,8 +119,9 @@ let
|
||||
else
|
||||
lib.concatMapStrings (ob: mkOutboundBlock ob routingMark ob.tag) singBoxCfg.outbounds;
|
||||
|
||||
subscriptionBlocks =
|
||||
lib.concatMapStrings (sub: mkSubscriptionBlock sub routingMark) singBoxCfg.subscriptions;
|
||||
subscriptionBlocks = lib.concatMapStrings (
|
||||
sub: mkSubscriptionBlock sub routingMark
|
||||
) singBoxCfg.subscriptions;
|
||||
|
||||
wrapperBlock =
|
||||
if collapseNamedOutbounds then
|
||||
|
||||
Reference in new issue
Block a user