From 5965922b5709253520851bee3ec4b7df66aeede1 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 1 Apr 2025 22:19:54 -0400 Subject: [PATCH] refactor: generalize flake input injection --- deploy/rpi5/default.nix | 8 +++++--- flake.nix | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/deploy/rpi5/default.nix b/deploy/rpi5/default.nix index 96b78fe..8a3cfbf 100644 --- a/deploy/rpi5/default.nix +++ b/deploy/rpi5/default.nix @@ -1,9 +1,11 @@ { config, lib, ... }: { options.aether.deploy.rpi5 = { - kernelPackages = lib.mkOption { + _internal.kernelPackages = lib.mkOption { type = lib.types.raw; - description = "Kernel package to use for Raspberry Pi 5 support"; + description = '' + Kernel package to use for Raspberry Pi 5 support. + ''; }; }; @@ -11,7 +13,7 @@ let cfg = config.aether.deploy.rpi5; in { nixpkgs.system = "aarch64-linux"; - boot.kernelPackages = cfg.kernelPackages; + boot.kernelPackages = cfg._internal.kernelPackages; boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = false; }; diff --git a/flake.nix b/flake.nix index 2c62bc9..bd59b40 100644 --- a/flake.nix +++ b/flake.nix @@ -19,23 +19,43 @@ outputs = inputs@{ self, nixpkgs, agenix, rpi5-kernel, ... }: let inherit (nixpkgs) lib; + # Extra config applied to each module + # (Mostly used for injecting flake inputs) + extraConfig = { + deploy-rpi5 = { + aether.deploy.rpi5._internal.kernelPackages = lib.mkDefault + rpi5-kernel.legacyPackages.aarch64-linux.linuxPackages_rpi5; + }; + }; + moduleNames = let sub = builtins.readDir ./modules; in builtins.filter (d: sub.${d} == "directory") (builtins.attrNames sub); - modules = lib.genAttrs moduleNames (name: ./modules/${name}); + deployNames = + let sub = builtins.readDir ./deploy; + in builtins.map (d: "deploy-${d}") + (builtins.filter + (d: sub.${d} == "directory") + (builtins.attrNames sub)); + + modules = lib.genAttrs moduleNames + (name: ./modules/${name}); + deployments = lib.genAttrs deployNames + (name: ./deploy/${lib.removePrefix "deploy-" name}); + + modulesWithCfg = builtins.mapAttrs (k: v: { + imports = [ v ]; + } // extraConfig.${k} or {}) modules; + deploymentsWithCfg = builtins.mapAttrs (k: v: { + imports = [ v ]; + } // extraConfig.${k} or {}) deployments; in { nixosModules = - modules - // { - all.imports = lib.attrValues modules; - deploy-rpi5 = { lib, ... }: { - imports = [ ./deploy/rpi5 ]; - aether.deploy.rpi5.kernelPackages = lib.mkDefault - rpi5-kernel.legacyPackages.aarch64-linux.linuxPackages_rpi5; - }; + modulesWithCfg // deploymentsWithCfg // { + all.imports = lib.attrValues modulesWithCfg; }; nixosConfigurations."toki-aether" =