From 12b804340ff0f365cdb94506aea86646e002a6a3 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Sun, 6 Jul 2025 04:55:10 +0800 Subject: [PATCH] feat(nixos): pass inputs and hostName as specialArgs to nixosSystem --- modules/configurations/nixos.nix | 13 ++++++++----- modules/flake-parts/modules.nix | 4 ++++ modules/hostSpec.nix | 14 +++++++++++++- modules/modules/nixos/networking.nix | 7 +++++++ 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 modules/flake-parts/modules.nix create mode 100644 modules/modules/nixos/networking.nix diff --git a/modules/configurations/nixos.nix b/modules/configurations/nixos.nix index 03f5539..b3f0743 100644 --- a/modules/configurations/nixos.nix +++ b/modules/configurations/nixos.nix @@ -1,4 +1,9 @@ -{ config, lib, ... }: +{ + config, + lib, + inputs, + ... +}: let inherit (lib.trivial) pipe; inherit (lib.attrsets) filterAttrs mapAttrs'; @@ -13,10 +18,8 @@ let { name = hostName; value = lib.nixosSystem { - modules = [ - value - { networking = { inherit hostName; }; } - ]; + specialArgs = { inherit inputs hostName; }; + modules = [ value ]; }; }; in diff --git a/modules/flake-parts/modules.nix b/modules/flake-parts/modules.nix new file mode 100644 index 0000000..1c75663 --- /dev/null +++ b/modules/flake-parts/modules.nix @@ -0,0 +1,4 @@ +{ inputs, ... }: +{ + imports = [ inputs.flake-parts.flakeModules.modules ]; +} diff --git a/modules/hostSpec.nix b/modules/hostSpec.nix index 1b914f3..3059518 100644 --- a/modules/hostSpec.nix +++ b/modules/hostSpec.nix @@ -1,3 +1,15 @@ +{ config, ... }: { - flake.hostSpec.hosts = { }; + flake.hostSpec.hosts = { + "nixos/test".imports = with config.flake.modules.nixos; [ networking ]; + "nixos/test".config = { + boot.loader.systemd-boot.enable = true; + fileSystems."/" = { + device = "/dev/sda1"; + fsType = "ext4"; + }; + nixpkgs.hostPlatform = "x86_64-linux"; + system.stateVersion = "25.05"; + }; + }; } diff --git a/modules/modules/nixos/networking.nix b/modules/modules/nixos/networking.nix new file mode 100644 index 0000000..1dc3fc6 --- /dev/null +++ b/modules/modules/nixos/networking.nix @@ -0,0 +1,7 @@ +{ + flake.modules.nixos.networking = + { hostName, ... }: + { + networking = { inherit hostName; }; + }; +}