style(nix): apply style fixes

This commit was merged in pull request #53.
This commit is contained in:
2026-09-16 00:16:08 -04:00
parent d24f58a4c9
commit e15ce7f16b
42 changed files with 389 additions and 289 deletions

View File

@@ -10,19 +10,21 @@ in
{
fix = {
type = "app";
program = lib.getExe (pkgs.writeShellApplication {
name = "fix";
runtimeInputs = [
formatter.config.build.wrapper
pkgs.statix
pkgs.deadnix
];
text = ''
treefmt
statix fix .
deadnix --edit --exclude configs/nixos/hosts/*/hardware-configuration.nix -- .
treefmt
'';
});
program = lib.getExe (
pkgs.writeShellApplication {
name = "fix";
runtimeInputs = [
formatter.config.build.wrapper
pkgs.statix
pkgs.deadnix
];
text = ''
treefmt
statix fix .
deadnix --edit --exclude configs/nixos/hosts/*/hardware-configuration.nix -- .
treefmt
'';
}
);
};
}

View File

@@ -17,16 +17,13 @@ let
directoryMounts = lib.filterAttrs (_: mount: mount.directory != null) cfg.mounts;
directoryScript = lib.concatStringsSep "\n" (
lib.mapAttrsToList (
_: mount:
''
${config.system.path}/bin/install -d \
${lib.optionalString (mount.owner != null) "-o ${lib.escapeShellArg (toString mount.owner)}"} \
${lib.optionalString (mount.group != null) "-g ${lib.escapeShellArg mount.group}"} \
${lib.optionalString (mount.mode != null) "-m ${lib.escapeShellArg mount.mode}"} \
${lib.escapeShellArg mount.directory}
''
) directoryMounts
lib.mapAttrsToList (_: mount: ''
${config.system.path}/bin/install -d \
${lib.optionalString (mount.owner != null) "-o ${lib.escapeShellArg (toString mount.owner)}"} \
${lib.optionalString (mount.group != null) "-g ${lib.escapeShellArg mount.group}"} \
${lib.optionalString (mount.mode != null) "-m ${lib.escapeShellArg mount.mode}"} \
${lib.escapeShellArg mount.directory}
'') directoryMounts
);
in
{
@@ -171,14 +168,20 @@ let
assertions =
let
hasDirectorySettings = mount: mount.owner != null || mount.group != null || mount.mode != null;
hasCompleteDirectorySettings = mount: mount.owner != null && mount.group != null && mount.mode != null;
hasCompleteDirectorySettings =
mount: mount.owner != null && mount.group != null && mount.mode != null;
hasOneSource = mount: (mount.directory != null) != (mount.file != null);
mountsWithInvalidSource = lib.attrNames (lib.filterAttrs (_: mount: !hasOneSource mount) cfg.mounts);
mountsWithInvalidSource = lib.attrNames (
lib.filterAttrs (_: mount: !hasOneSource mount) cfg.mounts
);
fileMountsWithHostSettings = lib.attrNames (
lib.filterAttrs (_: mount: mount.file != null && hasDirectorySettings mount) cfg.mounts
);
directoryMountsWithPartialHostSettings = lib.attrNames (
lib.filterAttrs (_: mount: mount.directory != null && hasDirectorySettings mount && !hasCompleteDirectorySettings mount) cfg.mounts
lib.filterAttrs (
_: mount:
mount.directory != null && hasDirectorySettings mount && !hasCompleteDirectorySettings mount
) cfg.mounts
);
in
[
@@ -203,20 +206,23 @@ let
{
assertion = lib.elem cfg.vlan config.modules.network.vlans.ids;
message = ''
guests.${name}.vlan = ${toString cfg.vlan} is not among its host's modules.network.vlans.ids (${lib.concatMapStringsSep ", " toString config.modules.network.vlans.ids}). Declare the VLAN on the host or correct the guest's placement.
guests.${name}.vlan = ${toString cfg.vlan} is not among its host's modules.network.vlans.ids (${
lib.concatMapStringsSep ", " toString config.modules.network.vlans.ids
}). Declare the VLAN on the host or correct the guest's placement.
'';
}
];
registry.address.${config.networking.hostName}.${name} =
lib.mkIf (cfg.address != null) cfg.address;
registry.address.${config.networking.hostName}.${name} = lib.mkIf (cfg.address != null) cfg.address;
registry.route.${config.networking.hostName}.${name} =
lib.mkIf cfg.reverseProxy.enable cfg.reverseProxy.route;
systemd.services."container@${name}" =
let
bridgeDevice = "sys-subsystem-net-devices-${lib.replaceStrings [ "-" ] [ "\\x2d" ] (util.bridgeName cfg.vlan)}.device";
bridgeDevice = "sys-subsystem-net-devices-${
lib.replaceStrings [ "-" ] [ "\\x2d" ] (util.bridgeName cfg.vlan)
}.device";
in
{
after = [ bridgeDevice ];
@@ -268,10 +274,11 @@ let
};
};
};
in
let
files = util.collectNixFiles root;
guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) (builtins.readDir root);
guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) (
builtins.readDir root
);
names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles);
in
{

View File

@@ -26,7 +26,8 @@ let
guestModules
# TODO: refactor
registryModule (root + "/${name}")
registryModule
(root + "/${name}")
{
networking.hostName = name;
@@ -34,12 +35,8 @@ let
}
];
};
in
let
directories = lib.filterAttrs (_name: type: type == "directory") (builtins.readDir root);
names = lib.attrNames directories;
in
lib.genAttrs names (
name:
mkHost { inherit root name; }
)
lib.genAttrs names (name: mkHost { inherit root name; })

View File

@@ -1,4 +1,8 @@
{ hosts, lib, root }:
{
hosts,
lib,
root,
}:
let
checkType = lib.types.submodule {
options = {
@@ -19,7 +23,8 @@ let
};
predicates = {
uniqueValue = value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries;
uniqueValue =
value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries;
};
registryLib = lib // {
@@ -57,15 +62,18 @@ let
registryName = fileName: lib.removeSuffix ".nix" fileName;
registryOption = registry: lib.mkOption {
type = lib.types.attrsOf (lib.types.attrsOf registry.type);
default = { };
description = ''
Lazily collected fleet-visible registry entries, nested by host and entry name.
'';
};
registryOption =
registry:
lib.mkOption {
type = lib.types.attrsOf (lib.types.attrsOf registry.type);
default = { };
description = ''
Lazily collected fleet-visible registry entries, nested by host and entry name.
'';
};
mkRegistry = path:
mkRegistry =
path:
let
evaluated = lib.evalModules {
specialArgs.lib = registryLib;
@@ -79,15 +87,21 @@ let
inherit (evaluated.config) type replicate checks;
};
definitions = lib.mapAttrs' (
name: type:
let
path = root + "/${name}";
in
lib.nameValuePair (registryName name) (mkRegistry path)
) (lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root));
definitions =
lib.mapAttrs'
(
name: _type:
let
path = root + "/${name}";
in
lib.nameValuePair (registryName name) (mkRegistry path)
)
(
lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root)
);
flattenRegistryEntries = registryName: data:
flattenRegistryEntries =
registryName: data:
lib.concatLists (
lib.mapAttrsToList (
host: entries:
@@ -98,10 +112,12 @@ let
) data
);
rawDeclarations = registryName: hosts:
rawDeclarations =
registryName: hosts:
lib.mapAttrs (_hostName: host: host.config.registry.${registryName} or { }) hosts;
replicatedEntries = registryName: raw:
replicatedEntries =
registryName: raw:
let
entries = lib.concatLists (
lib.concatLists (
@@ -126,18 +142,21 @@ let
else
throw "conflicting replicated registry entry ${entry.path} does not match ${acc.${entry.entryName}.path}"
else
acc // {
acc
// {
${entry.entryName} = entry;
}
) { } entries;
replicatedData = registryName: hosts: raw:
replicatedData =
registryName: hosts: raw:
let
entries = lib.mapAttrs (_entryName: entry: entry.value) (replicatedEntries registryName raw);
in
lib.mapAttrs (_hostName: _host: entries) hosts;
validationAssertions = data:
validationAssertions =
data:
lib.concatLists (
lib.mapAttrsToList (
registryName: registry:
@@ -151,7 +170,8 @@ let
) definitions
);
assertValid = data:
assertValid =
data:
let
assertions = validationAssertions data;
failures = lib.filter (assertion: !assertion.assertion) assertions;
@@ -161,9 +181,12 @@ let
);
data;
join = registry: host: entry:
join =
registry: host: entry:
lib.filterAttrs (_name: value: value != null) (
lib.mapAttrs (registryName: _registry: (registry.${registryName}.${host} or { }).${entry} or null) definitions
lib.mapAttrs (
registryName: _registry: (registry.${registryName}.${host} or { }).${entry} or null
) definitions
);
collectData =
@@ -180,7 +203,8 @@ let
in
assertValid data;
withOperations = registry:
withOperations =
registry:
registry
// {
join = host: entry: join registry host entry;
@@ -190,8 +214,10 @@ in
types = lib.mapAttrs (_name: definition: definition.type) definitions;
module = {
options.registry = lib.mapAttrs (_name: registry: registryOption registry) definitions;
options.registry = lib.mapAttrs (_name: registryOption) definitions;
};
collected = withOperations (collectData { inherit hosts; });
collected = withOperations (collectData {
inherit hosts;
});
}

View File

@@ -28,5 +28,14 @@ in
hash = builtins.hashString "sha256" name;
octet = i: builtins.substring (i * 2) 2 hash;
in
lib.concatStringsSep ":" ([ "02" ] ++ map octet [ 0 1 2 3 4 ]);
lib.concatStringsSep ":" (
[ "02" ]
++ map octet [
0
1
2
3
4
]
);
}