2023-08-27 07:48:57 +02:00
|
|
|
# flakelight -- Framework for simplifying flake setup
|
2023-08-25 06:14:55 +02:00
|
|
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2023-08-27 22:57:16 +02:00
|
|
|
{ config, lib, inputs, flakelight, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
2023-08-27 22:57:16 +02:00
|
|
|
inherit (builtins) parseDrvName;
|
|
|
|
inherit (lib) filterAttrs mapAttrs mapAttrs' mkIf mkMerge mkOption
|
|
|
|
nameValuePair optionalAttrs;
|
|
|
|
inherit (lib.types) lazyAttrsOf nullOr uniq;
|
2023-08-27 07:48:57 +02:00
|
|
|
inherit (flakelight) supportedSystem;
|
2023-08-27 22:57:16 +02:00
|
|
|
inherit (flakelight.types) overlay packageDef;
|
2023-08-25 06:14:55 +02:00
|
|
|
|
2023-08-27 22:57:16 +02:00
|
|
|
genPkg = pkgs: pkg: pkgs.callPackage pkg { };
|
|
|
|
genPkgs = pkgs: mapAttrs (_: genPkg pkgs) config.packages;
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
package = mkOption {
|
|
|
|
type = nullOr packageDef;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
packages = mkOption {
|
|
|
|
type = lazyAttrsOf packageDef;
|
|
|
|
default = { };
|
|
|
|
};
|
2023-08-27 22:57:16 +02:00
|
|
|
|
|
|
|
packageOverlay = mkOption {
|
|
|
|
internal = true;
|
|
|
|
type = uniq overlay;
|
|
|
|
default = _: _: { };
|
|
|
|
};
|
2023-08-25 06:14:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
(mkIf (config.package != null) {
|
|
|
|
packages.default = config.package;
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (config.packages != { }) {
|
2023-08-27 22:57:16 +02:00
|
|
|
packageOverlay = final: prev:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
2023-08-27 22:57:16 +02:00
|
|
|
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;
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
(optionalAttrs (config.packages ? default) {
|
2023-08-27 22:57:16 +02:00
|
|
|
${defaultPkgName} = genPkg final config.packages.default;
|
|
|
|
}) // genPkgs final;
|
2023-08-25 06:14:55 +02:00
|
|
|
|
2023-08-27 22:57:16 +02:00
|
|
|
overlay = final: prev: removeAttrs
|
|
|
|
(config.packageOverlay (final.appendOverlays config.withOverlays) prev)
|
|
|
|
[ "default" ];
|
2023-08-25 06:14:55 +02:00
|
|
|
|
|
|
|
perSystem = pkgs: rec {
|
2023-08-27 22:57:16 +02:00
|
|
|
packages = filterAttrs (_: supportedSystem pkgs) (genPkgs pkgs);
|
2023-08-25 06:14:55 +02:00
|
|
|
|
|
|
|
checks = mapAttrs' (n: nameValuePair ("packages-" + n)) packages;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|