forked from extern/flakelight
82f9fe67c3
Using `perSystem` to implement per-system attributes ties all the per-system attributes together; all the `perSystem` functions must run to determine output attrs. By generating them separately, the generation can be done lazily.
70 lines
1.9 KiB
Nix
70 lines
1.9 KiB
Nix
# flakelight -- Framework for simplifying flake setup
|
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
{ config, lib, inputs, flakelight, genSystems, ... }:
|
|
let
|
|
inherit (builtins) parseDrvName;
|
|
inherit (lib) filterAttrs mapAttrs mapAttrs' mkIf mkMerge mkOption
|
|
nameValuePair optionalAttrs;
|
|
inherit (lib.types) lazyAttrsOf nullOr uniq;
|
|
inherit (flakelight) supportedSystem;
|
|
inherit (flakelight.types) overlay packageDef;
|
|
|
|
genPkg = pkgs: pkg: pkgs.callPackage pkg { };
|
|
genPkgs = pkgs: mapAttrs (_: genPkg pkgs) config.packages;
|
|
in
|
|
{
|
|
options = {
|
|
package = mkOption {
|
|
type = nullOr packageDef;
|
|
default = null;
|
|
};
|
|
|
|
packages = mkOption {
|
|
type = lazyAttrsOf packageDef;
|
|
default = { };
|
|
};
|
|
|
|
packageOverlay = mkOption {
|
|
internal = true;
|
|
type = uniq overlay;
|
|
default = _: _: { };
|
|
};
|
|
};
|
|
|
|
config = mkMerge [
|
|
(mkIf (config.package != null) {
|
|
packages.default = config.package;
|
|
})
|
|
|
|
(mkIf (config.packages != { }) {
|
|
packageOverlay = final: prev:
|
|
let
|
|
getName = pkg: pkg.pname or (parseDrvName pkg.name).name;
|
|
defaultPkgName = getName (import inputs.nixpkgs {
|
|
inherit (prev.stdenv.hostPlatform) system;
|
|
inherit (config.nixpkgs) config;
|
|
overlays = config.withOverlays ++ [ (final: _: genPkgs final) ];
|
|
}).default;
|
|
in
|
|
(optionalAttrs (config.packages ? default) {
|
|
${defaultPkgName} = genPkg final config.packages.default;
|
|
}) // genPkgs final;
|
|
|
|
overlay = final: prev: removeAttrs
|
|
(config.packageOverlay (final.appendOverlays config.withOverlays) prev)
|
|
[ "default" ];
|
|
|
|
outputs = rec {
|
|
packages = genSystems (pkgs:
|
|
filterAttrs (_: supportedSystem pkgs) (genPkgs pkgs));
|
|
|
|
checks = mapAttrs
|
|
(_: mapAttrs' (n: nameValuePair ("packages-" + n)))
|
|
packages;
|
|
};
|
|
})
|
|
];
|
|
}
|