1
1
forked from extern/flakelight

Apply optional parameters to non-per-system attrs

This allows attrs that previously did not take args to receive args
including the flakelite lib attrs and module parameters.

`withOverlay` and `withPackage` are excluded as it would be ambiguous
since those are already functions. They are also short forms; if args
are needed, the regular plural attr can be used.

These args are also added to the flakelite pkgs attr for per-system
attrs to take advantage of.
This commit is contained in:
Archit Gupta 2023-04-14 20:16:50 -07:00
parent cd655770d6
commit b1fe8e8e17

View File

@ -11,10 +11,12 @@ let
optionalAttrs optionalString parseDrvName pathExists pipe recursiveUpdate
removeSuffix zipAttrsWith;
exports = { inherit mkFlake loadNixDir systems; };
baseModule = src: inputs: root: {
withOverlay = final: prev: {
flakelite = exports // {
inherit inputs;
withOverlays = params: [
(final: prev: {
flakelite = params // {
inputs' = mapAttrs
(_: mapAttrs
(_: v: v.${prev.system} or { }))
@ -30,7 +32,8 @@ let
else final.lib.licenses.${root.license};
};
};
};
})
];
checks = { pkgs, lib, ... }:
(optionalAttrs (pathExists (src + /.editorconfig)) {
editorconfig = "${lib.getExe pkgs.editorconfig-checker}"
@ -51,6 +54,11 @@ let
(mapAttrsToList (_: v: v.flakeliteModule))
];
mkFunc = v: if isFunction v then v else _: v;
params = exports // { inherit src inputs root'; };
applyParams = v: mkFunc v params;
defaultModule = {
withOverlays = [ ];
packages = { };
@ -65,31 +73,40 @@ let
formatters = _: { };
};
mergeListFns = f1: f2: args: (f1 args) ++ (f2 args);
mergeAttrFns = f1: f2: args: (f1 args) // (f2 args);
mkFunc = v: if isFunction v then v else _: v;
normalizeModule = module:
let
module' = defaultModule // module;
in
module' // {
withOverlays = module'.withOverlays
withOverlays = (applyParams module'.withOverlays)
++ optional (module' ? withOverlay) module'.withOverlay;
packages = module'.packages // optionalAttrs (module' ? package) {
packages = (applyParams module'.packages)
// optionalAttrs (module' ? package) {
default = module'.package;
};
devTools = mkFunc module'.devTools;
env = mkFunc module'.env;
overlays = module'.overlays // optionalAttrs (module' ? overlay) {
overlays = (applyParams module'.overlays)
// optionalAttrs (module' ? overlay) {
default = module'.overlay;
};
apps = mkFunc module'.apps;
checks = mkFunc module'.checks;
nixosModules = applyParams module'.nixosModules;
nixosConfigurations = applyParams module'.nixosConfigurations;
templates = applyParams module'.templates;
formatters = mkFunc module'.formatters;
};
root' = normalizeModule root // {
systems = applyParams root.systems or systems.linuxDefault;
perSystem = mkFunc root.perSystem or (_: { });
outputs = applyParams root.outputs or { };
};
mergeListFns = f1: f2: args: (f1 args) ++ (f2 args);
mergeAttrFns = f1: f2: args: (f1 args) // (f2 args);
mergeModules = m1: m2: {
withOverlays = m1.withOverlays ++ m2.withOverlays;
packages = m1.packages // m2.packages;
@ -105,12 +122,6 @@ let
formatters = mergeAttrFns m1.formatters m2.formatters;
};
root' = normalizeModule root // {
systems = root.systems or systems.linuxDefault;
perSystem = mkFunc root.perSystem or (_: { });
outputs = root.outputs or { };
};
merged = foldl mergeModules defaultModule
((map (m: normalizeModule (m src inputs root'))
([ baseModule ] ++ modules)) ++ [ root' ]);
@ -276,7 +287,5 @@ let
"i686-linux"
];
};
exports = { inherit mkFlake loadNixDir systems; };
in
exports