chore: nf-fmt-nix

This commit is contained in:
arcnmx 2024-06-23 11:48:55 -07:00
parent e4bbddb004
commit 32ff0a8e0c
7 changed files with 152 additions and 138 deletions

11
lib.nix
View file

@ -19,16 +19,21 @@
nibble0 = Str.index part 0;
in
nibble0 + UInt.toHexLower nibble1;
in trimAddress6 "${part0 (part 0)}${part 1}:${part 2}ff:fe${part 3}:${part 4}${part 5}";
in
trimAddress6 "${part0 (part 0)}${part 1}:${part 2}ff:fe${part 3}:${part 4}${part 5}";
trimAddress6 = let
matcher = match ''(^|.*:)(0+)([0-9a-fA-F].*)'';
in addr: let
in
addr: let
matched = matcher addr;
prefix = elemAt matched 0;
postfix = elemAt matched 2;
addrReplaced = prefix + postfix;
in if matched == null then addr else trimAddress6 addrReplaced;
in
if matched == null
then addr
else trimAddress6 addrReplaced;
parseUrl = url: let
parts' = Regex.match ''^([^:]+)://(\[[0-9a-fA-F:]+]|[^/:\[]+)(|:[0-9]+)(|/.*)$'' url;

View file

@ -62,7 +62,7 @@ let
in {
enable = mkDefault true;
port = mkDefault 9091;
extraFlags = [ "--collector.disable-defaults" ];
extraFlags = ["--collector.disable-defaults"];
enabledCollectors = mkIf cfg.defaultCollectors (mkMerge [
[
"systemd"

View file

@ -1,9 +1,15 @@
let
deviceModule = {config, lib, ...}: let
deviceModule = {
config,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption;
in {
options = with lib.types; {
enable = mkEnableOption "adb device" // {
enable =
mkEnableOption "adb device"
// {
default = true;
};
uphold = mkOption {
@ -15,14 +21,15 @@ let
};
};
};
in {
in
{
config,
gensokyo-zone,
utils,
pkgs,
lib,
...
}: let
}: let
inherit (lib.options) mkOption mkPackageOption mkEnableOption;
inherit (lib.modules) mkIf mkMerge mkDefault mkOptionDefault;
inherit (lib.attrsets) filterAttrs mapAttrsToList;
@ -31,7 +38,7 @@ in {
inherit (gensokyo-zone.lib) mapOptionDefaults;
cfg = config.services.adb;
enabledDevices = filterAttrs (_: device: device.enable) cfg.devices;
in {
in {
options.services.adb = with lib.types; {
enable = mkEnableOption "adb server";
package = mkPackageOption pkgs "android-tools" {};
@ -49,7 +56,7 @@ in {
default = [];
};
settings = mkOption {
type = attrsOf (oneOf [ str int (nullOr bool) ]);
type = attrsOf (oneOf [str int (nullOr bool)]);
};
devices = mkOption {
type = attrsOf (submoduleWith {
@ -69,19 +76,20 @@ in {
P = cfg.port;
};
};
conf.services.udev.packages = [ cfg.rulesPackage ];
conf.environment.systemPackages = [ cfg.package ];
conf.services.udev.packages = [cfg.rulesPackage];
conf.environment.systemPackages = [cfg.package];
conf.users.groups.adbusers = {};
conf.systemd.services.adb = {
upholds = let
upheldDevices = filterAttrs (_: device: device.uphold) enabledDevices;
in mapAttrsToList (_: device: "adb-device@${escapeSystemdPath device.serial}.service") upheldDevices;
in
mapAttrsToList (_: device: "adb-device@${escapeSystemdPath device.serial}.service") upheldDevices;
after = ["network.target"];
wantedBy = ["multi-user.target"];
serviceConfig = {
Type = mkOptionDefault "forking";
ExecStart = let
args = toGNUCommandLine { } cfg.settings ++ cfg.extraArguments;
args = toGNUCommandLine {} cfg.settings ++ cfg.extraArguments;
in [
"${cfg.package}/bin/adb start-server ${escapeSystemdExecArgs args}"
];
@ -95,7 +103,7 @@ in {
};
};
conf.systemd.services."adb-device@" = rec {
requisite = [ "adb.service" ];
requisite = ["adb.service"];
partOf = requisite;
after = requisite;
environment = mapOptionDefaults {
@ -134,4 +142,4 @@ in {
confService
(mkIf cfg.enable conf)
];
}
}

View file

@ -15,7 +15,7 @@ in {
services.prometheus.exporters = {
node = {
port = 9091;
extraFlags = [ "--collector.disable-defaults" ];
extraFlags = ["--collector.disable-defaults"];
enabledCollectors = mkMerge [
(mkIf config.boot.supportedFilesystems.xfs or false [
"xfs"

View file

@ -295,14 +295,12 @@ in {
hasService = system: system.exports.services.${service}.enable;
notFound = throw "no system found serving ${service}";
multiple = throw "multiple systems found serving ${service}";
in
(findSingle hasService notFound multiple (attrValues systems));
in (findSingle hasService notFound multiple (attrValues systems));
systemForServiceId = serviceId: let
hasService = system: findSingle (service: service.id == serviceId && service.enable) null multiple (attrValues system.exports.services) != null;
notFound = throw "no system found serving ${serviceId}";
multiple = throw "multiple systems found serving ${serviceId}";
in
(findSingle hasService notFound multiple (attrValues systems));
in (findSingle hasService notFound multiple (attrValues systems));
};
};
}

View file

@ -18,10 +18,12 @@ in {
settings.fail_timeout = mkDefault timeout;
addr = mkDefault "10.1.1.67";
port = mkDefault nfandroidtv.ports.default.port;
/*accessService = {
/*
accessService = {
system = "bedroomtv";
name = "nfandroidtv";
};*/
};
*/
};
fallback = let
virtualHost = nginx.virtualHosts.nfandroidtv'fallback;
@ -70,7 +72,8 @@ in {
config.networking.firewall.interfaces.lan = let
virtualHost = nginx.virtualHosts.nfandroidtv'local;
listen = virtualHost.listen'.nfandroidtv;
in mkIf (virtualHost.enable && listen.enable) {
allowedTCPPorts = [ listen.port ];
in
mkIf (virtualHost.enable && listen.enable) {
allowedTCPPorts = [listen.port];
};
}

View file

@ -17,10 +17,10 @@ in {
};
systemd.services = mkIf cfg.enable {
adb = {
environment.ADB_TRACE = mkDefault (toString [ "adb" ]);
environment.ADB_TRACE = mkDefault (toString ["adb"]);
};
};
networking.firewall.interfaces.lan = mkIf (cfg.enable && cfg.settings.a or false == true) {
allowedTCPPorts = [ cfg.port ];
allowedTCPPorts = [cfg.port];
};
}