From 3acd35c7b2450e1688daea780b32cc3d298a4e1c Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Mon, 13 Oct 2025 14:12:18 +0200 Subject: [PATCH] Add more custom libs --- flake-parts/hosts.nix | 20 ++++---------------- flake-parts/modules.nix | 9 ++++----- lib/default.nix | 8 ++++++++ modules/system/services/syncthing.nix | 3 ++- modules/system/services/wlan.nix | 9 ++++----- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/flake-parts/hosts.nix b/flake-parts/hosts.nix index 5280e86..357e0c8 100644 --- a/flake-parts/hosts.nix +++ b/flake-parts/hosts.nix @@ -1,8 +1,4 @@ -{ - inputs, - self, - ... -}: +{ inputs, self, ... }: let lib = inputs.nixpkgs.lib.extend (_: _: { custom = import "${self}/lib" inputs.nixpkgs.lib; }); @@ -29,18 +25,10 @@ let in { flake = { - nixosConfigurations = - "${self}/hosts" - |> builtins.readDir - |> lib.filterAttrs (_: type: type == "directory") - |> lib.mapAttrs (name: _: mkHost name); + nixosConfigurations = "${self}/hosts" |> lib.custom.listDirectories |> lib.custom.genAttrs mkHost; - deploy.nodes = - "${self}/hosts" - |> builtins.readDir - |> lib.filterAttrs (_: type: type == "directory") - |> lib.mapAttrs (name: _: mkDeployNode name); + deploy.nodes = "${self}/hosts" |> lib.custom.listDirectories |> lib.custom.genAttrs mkDeployNode; - checks = lib.mapAttrs (_: deployLib: deployLib.deployChecks self.deploy) inputs.deploy-rs.lib; + checks = inputs.deploy-rs.lib |> lib.mapAttrs (_: deployLib: deployLib.deployChecks self.deploy); }; } diff --git a/flake-parts/modules.nix b/flake-parts/modules.nix index eab3356..39a3932 100644 --- a/flake-parts/modules.nix +++ b/flake-parts/modules.nix @@ -1,11 +1,10 @@ -{ self, lib, ... }: +{ self, inputs, ... }: let - listNixFilesRecursive = - dir: dir |> lib.filesystem.listFilesRecursive |> lib.filter (lib.hasSuffix ".nix"); + lib = inputs.nixpkgs.lib.extend (_: _: { custom = import "${self}/lib" inputs.nixpkgs.lib; }); in { flake = { - nixosModules.default.imports = listNixFilesRecursive "${self}/modules/system"; - homeManagerModules.default.imports = listNixFilesRecursive "${self}/modules/home"; + nixosModules.default.imports = lib.custom.listNixFilesRecursive "${self}/modules/system"; + homeManagerModules.default.imports = lib.custom.listNixFilesRecursive "${self}/modules/home"; }; } diff --git a/lib/default.nix b/lib/default.nix index 83404b7..e8fb8c3 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -4,4 +4,12 @@ lib: { subdomainOf = domain: domain |> lib.splitString "." |> lib.head; rootDomainOf = domain: domain |> lib.splitString "." |> lib.tail |> lib.concatStringsSep "."; + + listNixFilesRecursive = + dir: dir |> lib.filesystem.listFilesRecursive |> lib.filter (lib.hasSuffix ".nix"); + + listDirectories = + path: path |> builtins.readDir |> lib.filterAttrs (_: type: type == "directory") |> lib.attrNames; + + genAttrs = f: names: lib.genAttrs names f; } diff --git a/modules/system/services/syncthing.nix b/modules/system/services/syncthing.nix index ee9f8ca..6949973 100644 --- a/modules/system/services/syncthing.nix +++ b/modules/system/services/syncthing.nix @@ -107,7 +107,8 @@ in let genFolders = folders: - lib.genAttrs folders (name: { + folders + |> lib.custom.genAttrs (name: { path = "${dataDir}/${name}"; ignorePerms = false; devices = config.services.syncthing.settings.devices |> lib.attrNames; diff --git a/modules/system/services/wlan.nix b/modules/system/services/wlan.nix index ee2efd7..0b28a3f 100644 --- a/modules/system/services/wlan.nix +++ b/modules/system/services/wlan.nix @@ -29,11 +29,10 @@ in sops.secrets = cfg.networks - |> lib.map (name: { - name = "iwd/${name}"; - value.restartUnits = [ "iwd.service" ]; - }) - |> lib.listToAttrs; + |> lib.map (name: "iwd/${name}") + |> lib.custom.genAttrs (_: { + restartUnits = [ "iwd.service" ]; + }); systemd.services.iwd.preStart = '' rm --force /var/lib/iwd/*.{psk,8021x}