refactor: remove duplication

This commit is contained in:
FUFSoB committed 2026-09-18 21:39:18 +05:00
1 parent f7036f6075
commit 8a4ba2db6a
109 files changed
+2206 -3078

No files matched your search

+57
View File
@@ -13,6 +13,63 @@ rec {
);
forward = forwardWith lib.id;
# The unit and package forwarding NixOS and system-manager do identically.
systemdForward = internal: {
systemd.services = forward internal.services;
systemd.timers = forward internal.timers;
systemd.paths = forward internal.paths;
systemd.tmpfiles.rules = forward internal.tmpfiles;
environment.systemPackages = lib.mkMerge [
(forwardWith lib.mkBefore internal.earlyPackages)
(forward internal.packages)
];
};
# One system user per daemon, each in a group of its own, plus the userControl group.
systemUsersAndGroups = cfg: {
users.users = lib.genAttrs cfg.internal.systemUsers (name: {
isSystemUser = true;
group = name;
description = "proxy-suite daemons";
});
users.groups = lib.genAttrs (cfg.internal.systemUsers ++ cfg.internal.groups) (_: { });
};
firewallPortForward = internal: {
networking.firewall = {
allowedTCPPorts = forward internal.firewall.allowedTCPPorts;
allowedUDPPorts = forward internal.firewall.allowedUDPPorts;
};
};
# The rootless adapters (home-manager, nix-on-droid) render the same unit set for a user
# manager: system and user services together, timers and paths, each filtered to enabled.
userUnitsFor =
{
lib,
pkgs,
host,
internal,
hostPath ? null,
}:
let
units = import ./user-units.nix (
{
inherit lib pkgs;
inherit (host) runtimeDir;
stateDir = builtins.dirOf host.stateDir;
}
// lib.optionalAttrs (hostPath != null) { inherit hostPath; }
);
enabled = lib.filterAttrs (_: unit: unit.enable);
in
{
services = lib.mapAttrs units.toService (enabled (internal.services // internal.userServices));
timers = lib.mapAttrs units.toTimer (enabled internal.timers);
paths = lib.mapAttrs units.toPath (enabled internal.paths);
};
# Scripts share one store name per block, and journald names a unit's output
# after its ExecStart basename; tag each unit with its own name instead.
unitsWithOwnSyslogIdentifier = lib.mkOption {