2023-08-27 07:48:57 +02:00
|
|
|
# flakelight -- Framework for simplifying flake setup
|
2023-08-25 06:14:55 +02:00
|
|
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2024-01-14 10:29:16 +01:00
|
|
|
{ config, lib, inputs, flakelight, moduleArgs, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
2024-01-14 21:59:39 +01:00
|
|
|
inherit (builtins) head mapAttrs match;
|
|
|
|
inherit (lib) foldl mapAttrsToList mkOption mkIf recursiveUpdate;
|
2024-01-14 10:29:16 +01:00
|
|
|
inherit (lib.types) attrs lazyAttrsOf;
|
2024-01-14 21:59:39 +01:00
|
|
|
inherit (flakelight) selectAttr;
|
2024-01-15 04:05:39 +01:00
|
|
|
inherit (flakelight.types) optCallWith;
|
2023-08-25 06:14:55 +02:00
|
|
|
|
2024-01-14 10:29:16 +01:00
|
|
|
isHome = x: x ? activationPackage;
|
|
|
|
|
2024-01-14 21:59:39 +01:00
|
|
|
mkHome = name: cfg: inputs.home-manager.lib.homeManagerConfiguration (
|
|
|
|
(removeAttrs cfg [ "system" ]) // {
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit inputs;
|
|
|
|
inputs' = mapAttrs (_: selectAttr cfg.system) inputs;
|
|
|
|
} // cfg.extraSpecialArgs or { };
|
|
|
|
modules = [
|
|
|
|
({ lib, ... }: {
|
|
|
|
home.username = lib.mkDefault (head (match "([^@]*)(@.*)?" name));
|
|
|
|
})
|
|
|
|
config.propagationModule
|
|
|
|
] ++ cfg.modules or [ ];
|
|
|
|
pkgs = inputs.nixpkgs.legacyPackages.${cfg.system};
|
|
|
|
}
|
|
|
|
);
|
2023-12-05 09:12:04 +01:00
|
|
|
|
2024-01-14 10:29:16 +01:00
|
|
|
configs = mapAttrs
|
2024-01-15 04:05:39 +01:00
|
|
|
(name: cfg: if isHome cfg then cfg else mkHome name cfg)
|
2024-01-14 10:29:16 +01:00
|
|
|
config.homeConfigurations;
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.homeConfigurations = mkOption {
|
2024-01-15 04:05:39 +01:00
|
|
|
type = lazyAttrsOf (optCallWith moduleArgs attrs);
|
2023-08-25 06:14:55 +02:00
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
config.outputs = mkIf (config.homeConfigurations != { }) {
|
2023-12-05 09:12:04 +01:00
|
|
|
homeConfigurations = configs;
|
2023-08-25 06:14:55 +02:00
|
|
|
checks = foldl recursiveUpdate { } (mapAttrsToList
|
|
|
|
(n: v: {
|
|
|
|
${v.config.nixpkgs.system}."home-${n}" = v.activationPackage;
|
|
|
|
})
|
2023-12-05 09:12:04 +01:00
|
|
|
configs);
|
2023-08-25 06:14:55 +02:00
|
|
|
};
|
|
|
|
}
|