From fd2dd2b56577805cbc426fda11bf453b220cbe0c Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 23 Aug 2024 18:02:21 +0200 Subject: [PATCH] BuildClan: autoimport facter.json --- flake.lock | 301 +++++++++++++++++++++++++++++++++++++- flake.nix | 12 ++ lib/build-clan/module.nix | 18 ++- 3 files changed, 327 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index e8b68d70b..59b3f3093 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,78 @@ { "nodes": { + "blueprint": { + "inputs": { + "nixpkgs": [ + "nixos-facter", + "nixpkgs" + ], + "systems": [ + "nixos-facter", + "systems" + ] + }, + "locked": { + "lastModified": 1722503414, + "narHash": "sha256-JFMBd4cERlKd2lH1FuWgiwf2Q9PzPRPsdD4HV8Fs2IQ=", + "owner": "numtide", + "repo": "blueprint", + "rev": "214500b4802d1e0149a51aa19340d6f1aefb33e8", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "blueprint", + "type": "github" + } + }, + "blueprint_2": { + "inputs": { + "nixpkgs": [ + "nixos-facter", + "hwinfo", + "nixpkgs" + ], + "systems": "systems" + }, + "locked": { + "lastModified": 1724053269, + "narHash": "sha256-DinmPyxmUSLjBUYMe3eK0GKykwe33vWbVTmp7++P4Ng=", + "owner": "numtide", + "repo": "blueprint", + "rev": "766302be9063650ca6578e5ba09cc4260b0da29c", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "blueprint", + "type": "github" + } + }, + "blueprint_3": { + "inputs": { + "nixpkgs": [ + "nixos-facter-modules", + "nixpkgs" + ], + "systems": [ + "nixos-facter-modules", + "systems" + ] + }, + "locked": { + "lastModified": 1722503414, + "narHash": "sha256-JFMBd4cERlKd2lH1FuWgiwf2Q9PzPRPsdD4HV8Fs2IQ=", + "owner": "numtide", + "repo": "blueprint", + "rev": "214500b4802d1e0149a51aa19340d6f1aefb33e8", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "blueprint", + "type": "github" + } + }, "disko": { "inputs": { "nixpkgs": [ @@ -20,6 +93,24 @@ "type": "github" } }, + "disko_2": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1723996216, + "narHash": "sha256-QNykxbGaHF3ANP369TT+VEBHlHufwY0SQk1SvUz5RcE=", + "owner": "nix-community", + "repo": "disko", + "rev": "fd43891af43916918eabdd498eeb24788d666079", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -40,6 +131,121 @@ "type": "github" } }, + "flake-utils": { + "inputs": { + "systems": [ + "nixos-facter", + "systems" + ] + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gomod2nix": { + "inputs": { + "flake-utils": [ + "nixos-facter", + "flake-utils" + ], + "nixpkgs": [ + "nixos-facter", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722589758, + "narHash": "sha256-sbbA8b6Q2vB/t/r1znHawoXLysCyD4L/6n6/RykiSnA=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "4e08ca09253ef996bd4c03afa383b23e35fe28a1", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "hwinfo": { + "inputs": { + "blueprint": "blueprint_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1724271981, + "narHash": "sha256-JqGUgN2ronkVrekLJ3t2Oa3Zt/W1JhU5oA/GD5f1nhI=", + "owner": "numtide", + "repo": "hwinfo", + "rev": "db1f44bde5b633cc68a46317773d33a80f7f28e7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "hwinfo", + "type": "github" + } + }, + "nixos-facter": { + "inputs": { + "blueprint": "blueprint", + "disko": "disko_2", + "flake-utils": "flake-utils", + "gomod2nix": "gomod2nix", + "hwinfo": "hwinfo", + "nixpkgs": [ + "nixpkgs" + ], + "systems": "systems_2", + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1724408140, + "narHash": "sha256-NKB/72C5udfGlnoQt1BRNkfZJ0BLd9Fud/2eWnPX5UU=", + "owner": "numtide", + "repo": "nixos-facter", + "rev": "8e7131acedc57af4a17bb51d66596fbb172b71df", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nixos-facter", + "type": "github" + } + }, + "nixos-facter-modules": { + "inputs": { + "blueprint": "blueprint_3", + "nixpkgs": [ + "nixpkgs" + ], + "systems": "systems_3", + "treefmt-nix": "treefmt-nix_2" + }, + "locked": { + "lastModified": 1724320449, + "narHash": "sha256-0hB5P75tIwPS9lNI3nYxEorpcFtuQUJGmGHGIEgWksY=", + "owner": "numtide", + "repo": "nixos-facter-modules", + "rev": "e00d789870e72baabb79d19afcc645428c3c6980", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nixos-facter-modules", + "type": "github" + } + }, "nixos-images": { "inputs": { "nixos-stable": [], @@ -81,11 +287,13 @@ "inputs": { "disko": "disko", "flake-parts": "flake-parts", + "nixos-facter": "nixos-facter", + "nixos-facter-modules": "nixos-facter-modules", "nixos-images": "nixos-images", - "nixpkgs": "nixpkgs", + "nixpkgs": "nixpkgs_3", "sops-nix": "sops-nix", - "systems": "systems", - "treefmt-nix": "treefmt-nix" + "systems": "systems_4", + "treefmt-nix": "treefmt-nix_3" } }, "sops-nix": { @@ -124,7 +332,94 @@ "type": "github" } }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixos-facter", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1723808491, + "narHash": "sha256-rhis3qNuGmJmYC/okT7Dkc4M8CeUuRCSvW6kC2f3hBc=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "1d07739554fdc4f8481068f1b11d6ab4c1a4167a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, + "treefmt-nix_2": { + "inputs": { + "nixpkgs": [ + "nixos-facter-modules", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1723656612, + "narHash": "sha256-6Sx+/VhRPLR+kRf6rnNUFMQ66DUz1DMYajixYUe+CUU=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "4a6d7dccf80a1aa2d04cfaa88d9e5511542a2486", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, + "treefmt-nix_3": { "inputs": { "nixpkgs": [ "nixpkgs" diff --git a/flake.nix b/flake.nix index c582ed3c2..e240d7ef2 100644 --- a/flake.nix +++ b/flake.nix @@ -17,6 +17,11 @@ systems.url = "github:nix-systems/default"; treefmt-nix.url = "github:numtide/treefmt-nix"; treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; + nixos-facter-modules.url = "github:numtide/nixos-facter-modules"; + nixos-facter-modules.inputs.nixpkgs.follows = "nixpkgs"; + + nixos-facter.url = "github:numtide/nixos-facter"; + nixos-facter.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = @@ -49,6 +54,13 @@ ./nixosModules/clanCore/vars/flake-module.nix ./pkgs/flake-module.nix ./templates/flake-module.nix + + # Inherit the nixos-facter package so its build is chached in clans binary cache + { + perSystem = {system, inputs', ...}: { + packages.nixos-facter = inputs'.nixos-facter.packages.default; + }; + } ]; } ); diff --git a/lib/build-clan/module.nix b/lib/build-clan/module.nix index 390625248..97739c09f 100644 --- a/lib/build-clan/module.nix +++ b/lib/build-clan/module.nix @@ -64,14 +64,30 @@ let modules = let settings = machineSettings name; + facterJson = "${directory}/machines/${name}/facter.json"; + hwConfig = "${directory}/machines/${name}/hardware-configuration.nix"; + + facterModules = lib.optionals (builtins.pathExists facterJson) [ + clan-core.inputs.nixos-facter-modules.nixosModules.facter + { config.facter.reportPath = facterJson; } + ]; in (machineImports settings) + ++ facterModules ++ [ { # Autoinclude configuration.nix and hardware-configuration.nix imports = builtins.filter builtins.pathExists [ "${directory}/machines/${name}/configuration.nix" - "${directory}/machines/${name}/hardware-configuration.nix" + hwConfig + ]; + config.warnings = lib.optionals (builtins.all builtins.pathExists [hwConfig facterJson]) [ + '' + Duplicate hardware facts: '${hwConfig}' and '${facterJson}' exist. + Using both is not recommended. + + It is recommended to use the hardware facts from '${facterJson}', please remove '${hwConfig}'. + '' ]; } settings