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 10:29:16 +01:00
|
|
|
inherit (builtins) concatLists head mapAttrs match;
|
|
|
|
inherit (lib) foldl last mapAttrsToList mkOption mkIf recursiveUpdate
|
|
|
|
zipAttrsWith;
|
|
|
|
inherit (lib.types) attrs lazyAttrsOf;
|
2023-10-24 05:21:36 +02:00
|
|
|
inherit (flakelight.types) optFunctionTo;
|
2023-08-25 06:14:55 +02:00
|
|
|
|
2024-01-14 10:29:16 +01:00
|
|
|
isHome = x: x ? activationPackage;
|
|
|
|
|
|
|
|
mergeCfg = zipAttrsWith (n: vs:
|
|
|
|
if n == "extraSpecialArgs" then
|
|
|
|
foldl (a: b: a // b) { } vs
|
|
|
|
else if n == "modules" then
|
|
|
|
concatLists vs
|
|
|
|
else last vs);
|
|
|
|
|
|
|
|
mkHome = name: cfg:
|
|
|
|
let
|
|
|
|
inherit (cfg) system;
|
|
|
|
in
|
|
|
|
inputs.home-manager.lib.homeManagerConfiguration (mergeCfg [
|
|
|
|
{
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit inputs;
|
|
|
|
inputs' = mapAttrs (_: mapAttrs (_: v: v.${system} or { })) inputs;
|
|
|
|
};
|
|
|
|
modules = [
|
|
|
|
({ lib, ... }: {
|
|
|
|
home.username = lib.mkDefault (head (match "([^@]*)(@.*)?" name));
|
|
|
|
})
|
|
|
|
config.propagationModule
|
|
|
|
];
|
|
|
|
pkgs = inputs.nixpkgs.legacyPackages.${system};
|
|
|
|
}
|
|
|
|
(removeAttrs cfg [ "system" ])
|
|
|
|
]);
|
2023-12-05 09:12:04 +01:00
|
|
|
|
2024-01-14 10:29:16 +01:00
|
|
|
configs = mapAttrs
|
|
|
|
(name: f:
|
|
|
|
let val = f moduleArgs; in
|
|
|
|
if isHome val then val else mkHome name val)
|
|
|
|
config.homeConfigurations;
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.homeConfigurations = mkOption {
|
2024-01-14 10:29:16 +01:00
|
|
|
type = lazyAttrsOf (optFunctionTo 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
|
|
|
};
|
|
|
|
}
|