1
1
mirror of https://github.com/divnix/digga.git synced 2024-12-23 08:02:21 +03:00

feat: add function to filter hosts from an attrset by system

This commit is contained in:
Chris Montgomery 2022-04-10 19:27:40 -04:00
parent 4438b0f111
commit 698551e084
No known key found for this signature in database
GPG Key ID: A6BA9BA2FDA7C997
3 changed files with 27 additions and 13 deletions

View File

@ -127,6 +127,7 @@
inherit (generators) mkDeployNodes mkHomeConfigurations ;
inherit (collectors)
collectHosts
collectHostsOnSystem
;
# DEPRECATED - will be removed soon

View File

@ -1,19 +1,34 @@
{ lib }:
let
collectHosts = nixosHosts: darwinHosts:
collectHosts = nixosConfigurations: darwinConfigurations:
/**
Synopsis: hostsOnSystem _hostOutputs_ _system_
Synopsis: collectHosts _nixosConfigurations_ _darwinConfigurations_
Collect all hosts across NixOS and Darwin configurations, validating for
unique hostnames to prevent collisions.
**/
(nixosHosts // lib.mapAttrs (name: value:
if builtins.hasAttr name nixosHosts
then throw ''
Hostnames must be unique across all platforms! Found a duplicate host config for '${name}'.
''
(nixosConfigurations // lib.mapAttrs
(name: value:
if builtins.hasAttr name nixosConfigurations
then
throw ''
Hostnames must be unique across all platforms! Found a duplicate host config for '${name}'.
''
else value
)
darwinHosts);
darwinConfigurations);
in
{
inherit collectHosts;
collectHostsOnSystem = hostConfigurations: system:
/**
Synopsis: collectHostsOnSystem _hostConfigurations_ _system_
Filter a set of host configurations to those matching a given system.
**/
let
systemSieve = _: host: host.config.nixpkgs.system == system;
in
lib.filterAttrs systemSieve hostConfigurations;
}

View File

@ -1,5 +1,5 @@
# constructor dependencies
{ lib, self, inputs, deploy, devshell, home-manager, flake-utils-plus, tests, ... }:
{ lib, self, inputs, collectors, deploy, devshell, home-manager, flake-utils-plus, tests, ... }:
config: channels:
let
@ -109,8 +109,7 @@ in
(self.nixosConfigurations != { })
) then
let
systemSieve = _: host: host.config.nixpkgs.system == system;
hostConfigsOnThisSystem = lib.filterAttrs systemSieve self.nixosConfigurations;
hostConfigsOnThisSystem = collectors.collectHostsOnSystem self.nixosConfigurations system;
createCustomTestOp = n: host: test:
lib.warnIf (!(test ? name)) ''
@ -145,8 +144,7 @@ in
(self.darwinConfigurations != { })
) then
let
systemSieve = _: host: host.config.nixpkgs.system == system;
hostConfigsOnThisSystem = lib.filterAttrs systemSieve self.darwinConfigurations;
hostConfigsOnThisSystem = collectors.collectHostsOnSystem self.darwinConfigurations system;
createCustomTestOp = n: host: test:
lib.warnIf (!(test ? name)) ''