flakelight/builtinModules/propagationModule.nix
Archit Gupta 4e9f53ff4e Enable all options to be auto-loaded from nixDir
This removes the manual configuration of which options are auto-loaded.
Now all options are eligible except for "nixDir" and "_module" as those
would cause inf recursions.

Additionally, instead of setting name aliases in the nixDir module, a
config option is added, enabling other modules to extend the aliases
lists.
2024-01-15 00:07:59 -08:00

39 lines
1.4 KiB
Nix

# 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
inherit (lib) mapAttrs mkOption optionalAttrs;
inherit (flakelight) selectAttr;
inherit (flakelight.types) module;
in
{
options.propagationModule = mkOption { type = module; internal = true; };
config.propagationModule =
{ lib, pkgs, options, ... }:
let inherit (pkgs.stdenv.hostPlatform) system; in {
config = (optionalAttrs (options ? nixpkgs.overlays) {
# Apply flakelight overlays to NixOS/home-manager configurations
nixpkgs.overlays = lib.mkOrder 10
(config.withOverlays ++ [ config.packageOverlay ]);
})
// (optionalAttrs (options ? home-manager.sharedModules) {
# Propagate module to home-manager when using its nixos module
home-manager.sharedModules = [ config.propagationModule ];
})
// {
# Give access to flakelight module args under `flake` arg.
# Also include inputs'/outputs' which depend on `pkgs`.
_module.args.flake = {
inputs' = mapAttrs (_: selectAttr system) inputs;
outputs' = selectAttr system outputs;
} // moduleArgs;
};
};
}