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.
This commit is contained in:
Archit Gupta 2024-01-15 00:07:59 -08:00
parent 11e65b623d
commit 4e9f53ff4e
4 changed files with 50 additions and 85 deletions

View File

@ -38,12 +38,15 @@ in
default = { }; default = { };
}; };
config.outputs = mkIf (config.homeConfigurations != { }) { config = {
homeConfigurations = configs; outputs = mkIf (config.homeConfigurations != { }) {
checks = foldl recursiveUpdate { } (mapAttrsToList homeConfigurations = configs;
(n: v: { checks = foldl recursiveUpdate { } (mapAttrsToList
${v.config.nixpkgs.system}."home-${n}" = v.activationPackage; (n: v: {
}) ${v.config.nixpkgs.system}."home-${n}" = v.activationPackage;
configs); })
configs);
};
nixDirAliases.homeConfigurations = [ "home" ];
}; };
} }

View File

@ -2,76 +2,35 @@
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com> # Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
{ config, src, lib, flakelight, moduleArgs, ... }: { config, options, src, lib, flakelight, ... }:
let let
inherit (lib) mkOption mkIf mkMerge; inherit (builtins) attrNames;
inherit (flakelight) autoImport autoImportArgs; inherit (lib) genAttrs mkIf mkOption subtractLists;
inherit (lib.types) attrsOf listOf str;
inherit (flakelight) autoImport;
inherit (flakelight.types) path; inherit (flakelight.types) path;
autoImport' = autoImport config.nixDir;
autoImportArgs' = autoImportArgs config.nixDir moduleArgs;
in in
{ {
options.nixDir = mkOption { options = {
type = path; nixDir = mkOption {
default = src + /nix; type = path;
default = src + /nix;
};
nixDirAliases = mkOption {
type = attrsOf (listOf str);
default = { };
};
}; };
config = config = genAttrs (subtractLists [ "_module" "nixDir" ] (attrNames options))
let (name:
outputs = autoImport' "outputs"; let
perSystem = autoImport' "perSystem"; internal = options.${name}.internal or false;
withOverlays = autoImport' "withOverlays"; val = autoImport config.nixDir
package = autoImport' "package"; (if name == "nixDirAliases" then name else
packages = autoImport' "packages"; ([ name ] ++ config.nixDirAliases.${name} or [ ]));
overlays = autoImport' "overlays"; cond = !internal && (val != null);
devShell = autoImport' "devShell"; in
devShells = autoImport' "devShells"; mkIf cond (if cond then val else { }));
app = autoImport' "app";
apps = autoImport' "apps";
checks = autoImport' "checks";
template = autoImport' "template";
templates = autoImport' "templates";
formatters = autoImport' "formatters";
bundler = autoImport' "bundler";
bundlers = autoImport' "bundlers";
nixosModule = autoImport' "nixosModule";
nixosModules = autoImport' "nixosModules";
nixosConfigurations = autoImport' [ "nixosConfigurations" "nixos" ];
homeModule = autoImport' "homeModule";
homeModules = autoImport' "homeModules";
homeConfigurations = autoImport' [ "homeConfigurations" "home" ];
flakelightModule = autoImport' "flakelightModule";
flakelightModules = autoImport' "flakelightModules";
lib = autoImport' "lib";
functor = autoImport' "functor";
in
mkMerge [
(mkIf (outputs != null) { inherit outputs; })
(mkIf (perSystem != null) { inherit perSystem; })
(mkIf (withOverlays != null) { inherit withOverlays; })
(mkIf (package != null) { inherit package; })
(mkIf (packages != null) { inherit packages; })
(mkIf (overlays != null) { inherit overlays; })
(mkIf (devShell != null) { inherit devShell; })
(mkIf (devShells != null) { inherit devShells; })
(mkIf (app != null) { inherit app; })
(mkIf (apps != null) { inherit apps; })
(mkIf (checks != null) { inherit checks; })
(mkIf (template != null) { inherit template; })
(mkIf (templates != null) { inherit templates; })
(mkIf (formatters != null) { inherit formatters; })
(mkIf (bundler != null) { inherit bundler; })
(mkIf (bundlers != null) { inherit bundlers; })
(mkIf (nixosModule != null) { inherit nixosModule; })
(mkIf (nixosModules != null) { inherit nixosModules; })
(mkIf (nixosConfigurations != null) { inherit nixosConfigurations; })
(mkIf (homeModule != null) { inherit homeModule; })
(mkIf (homeModules != null) { inherit homeModules; })
(mkIf (homeConfigurations != null) { inherit homeConfigurations; })
(mkIf (flakelightModule != null) { inherit flakelightModule; })
(mkIf (flakelightModules != null) { inherit flakelightModules; })
(mkIf (lib != null) { inherit lib; })
(mkIf (functor != null) { inherit functor; })
];
} }

View File

@ -32,16 +32,19 @@ in
default = { }; default = { };
}; };
config.outputs = mkIf (config.nixosConfigurations != { }) { config = {
nixosConfigurations = configs; outputs = mkIf (config.nixosConfigurations != { }) {
checks = foldl recursiveUpdate { } (mapAttrsToList nixosConfigurations = configs;
(n: v: { checks = foldl recursiveUpdate { } (mapAttrsToList
# Wrapping the drv is needed as computing its name is expensive (n: v: {
# If not wrapped, it slows down `nix flake show` significantly # Wrapping the drv is needed as computing its name is expensive
${v.config.nixpkgs.system}."nixos-${n}" = v.pkgs.runCommand # If not wrapped, it slows down `nix flake show` significantly
"check-nixos-${n}" ${v.config.nixpkgs.system}."nixos-${n}" = v.pkgs.runCommand
{ } "echo ${v.config.system.build.toplevel} > $out"; "check-nixos-${n}"
}) { } "echo ${v.config.system.build.toplevel} > $out";
configs); })
configs);
};
nixDirAliases.nixosConfigurations = [ "nixos" ];
}; };
} }

View File

@ -12,7 +12,7 @@ let
inherit (flakelight.types) module; inherit (flakelight.types) module;
in in
{ {
options.propagationModule = mkOption { type = module; }; options.propagationModule = mkOption { type = module; internal = true; };
config.propagationModule = config.propagationModule =
{ lib, pkgs, options, ... }: { lib, pkgs, options, ... }: