From c08289419cd498980156d989e84763f721acc255 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Wed, 28 Feb 2024 18:44:27 +0800 Subject: [PATCH] lib/nixos: update to include config --- lib/nixos.nix | 12 +++++++++++- modules/nixos/_private/extra-arguments.nix | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/nixos.nix b/lib/nixos.nix index 52b2eeea..b58a6b34 100644 --- a/lib/nixos.nix +++ b/lib/nixos.nix @@ -1,5 +1,5 @@ # All of the functions suitable only for NixOS. -{ pkgs, lib }: +{ pkgs, config, lib }: rec { # This is only used for home-manager users without a NixOS user counterpart. @@ -30,4 +30,14 @@ rec { settings ]; }); + + # Checks if the NixOS configuration is part of the nixos-generator build. + # Typically, we just check if there's a certain attribute that is imported + # from it. + hasNixosFormat = + pkgs.lib.hasAttrByPath [ "formatAttr" ] config; + + # Checks if the NixOS config is being built for a particular format. + isFormat = format: + hasNixosFormat && config.formatAttr == format; } diff --git a/modules/nixos/_private/extra-arguments.nix b/modules/nixos/_private/extra-arguments.nix index b9f4e072..62230e36 100644 --- a/modules/nixos/_private/extra-arguments.nix +++ b/modules/nixos/_private/extra-arguments.nix @@ -1,6 +1,6 @@ # All of the extra module arguments to be passed as part of the holistic NixOS # system. -{ options, lib, pkgs, ... }: +{ config, options, lib, pkgs, ... }: let foodogsquaredLib = import ../../../lib { inherit pkgs; }; @@ -8,7 +8,7 @@ in { _module.args.foodogsquaredLib = foodogsquaredLib.extend (final: prev: - import ../../../lib/nixos.nix { inherit pkgs; lib = prev; } + import ../../../lib/nixos.nix { inherit pkgs config; lib = prev; } // lib.optionalAttrs (options?sops) { sops-nix = import ../../../lib/sops.nix { inherit pkgs; lib = prev; }; });