From 9ee85857168f3165d5dda214107101e17d30e73a Mon Sep 17 00:00:00 2001 From: clerie Date: Mon, 6 Feb 2023 12:20:59 +0100 Subject: [PATCH] Replace lib/hosts.nix with an injected special argument containing the nix flake --- flake.nix | 8 ++++++++ hosts/monitoring-3/prometheus.nix | 4 ++-- lib/hosts.nix | 26 -------------------------- 3 files changed, 10 insertions(+), 28 deletions(-) delete mode 100644 lib/hosts.nix diff --git a/flake.nix b/flake.nix index 6ee58f4..dd9e7d3 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,14 @@ generateNixosSystem = name: nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ + ({ ... }: { + /* + Make the contents of the flake availiable to modules. + Useful for having the monitoring server scraping the + target config from all other servers automatically. + */ + _module.args._nixfiles = self; + }) ./configuration/common ({ ... }: { nixpkgs.overlays = [ diff --git a/hosts/monitoring-3/prometheus.nix b/hosts/monitoring-3/prometheus.nix index cf83db8..15a1f1a 100644 --- a/hosts/monitoring-3/prometheus.nix +++ b/hosts/monitoring-3/prometheus.nix @@ -1,9 +1,9 @@ -{ config, pkgs, lib, ... }: +{ config, pkgs, lib, _nixfiles, ... }: with lib; let - hosts = (import ../../lib/hosts.nix { inherit pkgs; }).hosts; + hosts = _nixfiles.nixosConfigurations; monitoringHosts = filterAttrs (name: host: attrByPath ["clerie" "monitoring" "enable"] false host.config) diff --git a/lib/hosts.nix b/lib/hosts.nix deleted file mode 100644 index b0e26d3..0000000 --- a/lib/hosts.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ pkgs ? import ../pkgs {} }: - -with pkgs.lib; - -rec { - hostsDir = ../hosts; - - hostNames = attrNames ( - filterAttrs ( - name: type: type == "directory" - ) ( - builtins.readDir hostsDir - ) - ); - - hosts = listToAttrs ( - map ( - hostName: nameValuePair hostName ( - import (pkgs.path + "/nixos") { - configuration = import (hostsDir + "/${hostName}/configuration.nix"); - system = "x86_64-linux"; - } - ) - ) hostNames - ); -}