2024-01-14 03:04:31 +01:00
|
|
|
# flakelight -- Framework for simplifying flake setup
|
|
|
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
# This provides a module that can be added to module systems nested inside of
|
|
|
|
# flakelight, for example NixOS or home-manager configurations.
|
|
|
|
|
|
|
|
{ lib, config, flakelight, moduleArgs, inputs, outputs, ... }:
|
|
|
|
let
|
2024-04-07 02:47:55 +02:00
|
|
|
inherit (lib) mapAttrs mkOption optional optionalAttrs;
|
2024-01-14 21:59:39 +01:00
|
|
|
inherit (flakelight) selectAttr;
|
2024-01-14 03:04:31 +01:00
|
|
|
inherit (flakelight.types) module;
|
2024-04-07 02:47:55 +02:00
|
|
|
flakeConfig = config;
|
2024-01-14 03:04:31 +01:00
|
|
|
in
|
|
|
|
{
|
2024-01-15 09:07:59 +01:00
|
|
|
options.propagationModule = mkOption { type = module; internal = true; };
|
2024-01-14 03:04:31 +01:00
|
|
|
|
|
|
|
config.propagationModule =
|
2024-04-07 02:47:55 +02:00
|
|
|
{ lib, pkgs, options, config, ... }:
|
2024-01-14 21:59:39 +01:00
|
|
|
let inherit (pkgs.stdenv.hostPlatform) system; in {
|
2024-04-07 02:53:50 +02:00
|
|
|
config = (optionalAttrs (options ? nixpkgs) {
|
|
|
|
nixpkgs = (optionalAttrs (options ? nixpkgs.overlays) {
|
|
|
|
# Forward overlays to NixOS/home-manager configurations
|
|
|
|
overlays = lib.mkOrder 10
|
|
|
|
(flakeConfig.withOverlays ++ [ flakeConfig.packageOverlay ]);
|
|
|
|
})
|
|
|
|
// (optionalAttrs (options ? nixpkgs.config) {
|
|
|
|
# Forward nixpkgs.config to NixOS/home-manager configurations
|
|
|
|
inherit (flakeConfig.nixpkgs) config;
|
|
|
|
});
|
2024-01-14 03:04:31 +01:00
|
|
|
})
|
|
|
|
// (optionalAttrs (options ? home-manager.sharedModules) {
|
|
|
|
# Propagate module to home-manager when using its nixos module
|
2024-04-07 02:47:55 +02:00
|
|
|
home-manager.sharedModules =
|
|
|
|
optional (! config.home-manager.useGlobalPkgs)
|
|
|
|
[ flakeConfig.propagationModule ];
|
2024-01-14 03:04:31 +01:00
|
|
|
})
|
|
|
|
// {
|
|
|
|
# Give access to flakelight module args under `flake` arg.
|
|
|
|
# Also include inputs'/outputs' which depend on `pkgs`.
|
|
|
|
_module.args.flake = {
|
2024-01-14 21:59:39 +01:00
|
|
|
inputs' = mapAttrs (_: selectAttr system) inputs;
|
|
|
|
outputs' = selectAttr system outputs;
|
2024-01-14 03:04:31 +01:00
|
|
|
} // moduleArgs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|