From 0204773d277037b9d318ee97995aaaf7b86b9e41 Mon Sep 17 00:00:00 2001 From: clerie Date: Sat, 28 Jun 2025 16:43:03 +0200 Subject: [PATCH] lib/nixosSystem.nix: Wrap nixpkgs.lib.nixosSystem and include nixfiles modules and overlays by default --- flake/nixosConfigurations.nix | 18 +-------------- lib/default.nix | 1 + lib/nixosSystem.nix | 41 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 lib/nixosSystem.nix diff --git a/flake/nixosConfigurations.nix b/flake/nixosConfigurations.nix index 5f4c874..8f5f80d 100644 --- a/flake/nixosConfigurations.nix +++ b/flake/nixosConfigurations.nix @@ -10,29 +10,13 @@ let group ? null, modules ? [], }: let - localNixpkgs = import ./nixpkgs.nix inputs; - in nixpkgs.lib.nixosSystem { + in self.lib.nixosSystem { system = system; - pkgs = localNixpkgs.${system}; modules = modules ++ [ - self.nixosModules.nixfilesInputs - self.nixosModules.clerie - self.nixosModules.profiles - ({ config, lib, ... }: { # Set hostname networking.hostName = lib.mkDefault name; - /* - 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 = { - inputs = inputs; - _nixfiles = self; - }; - # Expose host group to monitoring clerie.monitoring = nixpkgs.lib.attrsets.optionalAttrs (group != null) { serviceLevel = group; }; diff --git a/lib/default.nix b/lib/default.nix index 0d1d47a..388a1df 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -8,6 +8,7 @@ let lib = { clerie-monitoring-ids = callLibs ./clerie-monitoring-ids.nix; + nixosSystem = callLibs ./nixosSystem.nix; }; in diff --git a/lib/nixosSystem.nix b/lib/nixosSystem.nix new file mode 100644 index 0000000..bac3eec --- /dev/null +++ b/lib/nixosSystem.nix @@ -0,0 +1,41 @@ +{ + inputs, + self, + ... +}: + +/* + + nixfiles.lib.nixosSystem, like nixpkgs.lib.nixosSystem but + with nixfiles overlays and modules already populated + +*/ +{ + system ? null, + pkgs ? null, + modules ? [], + ... +}@args: + +let + localNixpkgs = import ../flake/nixpkgs.nix inputs; +in inputs.nixpkgs.lib.nixosSystem ({ + system = system; + pkgs = if pkgs != null then pkgs else localNixpkgs.${system}; + modules = [ + self.nixosModules.nixfilesInputs + self.nixosModules.clerie + self.nixosModules.profiles + ({ config, lib, ... }: { + /* + 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 = { + inputs = inputs; + _nixfiles = self; + }; + }) + ] ++ modules; +} // builtins.removeAttrs args [ "system" "pkgs" "modules" ] )