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
|
|
|
|
|
2024-01-15 04:17:50 +01:00
|
|
|
{ config, lib, inputs, flakelight, genSystems, moduleArgs, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
2024-01-12 02:27:34 +01:00
|
|
|
inherit (builtins) parseDrvName tryEval;
|
2024-01-12 08:21:49 +01:00
|
|
|
inherit (lib) filterAttrs findFirst mapAttrs mapAttrs' mkIf mkMerge mkOption
|
|
|
|
nameValuePair optionalAttrs;
|
2024-01-12 02:27:34 +01:00
|
|
|
inherit (lib.types) lazyAttrsOf nullOr str uniq;
|
2023-08-27 07:48:57 +02:00
|
|
|
inherit (flakelight) supportedSystem;
|
2024-01-15 04:17:50 +01:00
|
|
|
inherit (flakelight.types) optCallWith 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 {
|
2024-01-15 04:17:50 +01:00
|
|
|
type = optCallWith moduleArgs (lazyAttrsOf packageDef);
|
2023-08-25 06:14:55 +02:00
|
|
|
default = { };
|
|
|
|
};
|
2023-08-27 22:57:16 +02:00
|
|
|
|
2024-01-12 02:27:34 +01:00
|
|
|
pname = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
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;
|
2024-01-12 02:27:34 +01:00
|
|
|
inherit (prev.stdenv.hostPlatform) system;
|
|
|
|
baseNixpkgs = inputs.nixpkgs.legacyPackages.${system};
|
2024-01-12 08:21:49 +01:00
|
|
|
mockPkgs = import ../misc/nameMockedPkgs.nix prev;
|
2024-01-12 02:27:34 +01:00
|
|
|
|
|
|
|
defaultPkgName = findFirst (x: (tryEval x).success)
|
|
|
|
(throw ("Could not determine the name of the default package; " +
|
|
|
|
"please set the `pname` flakelight option to the intended name."))
|
|
|
|
[
|
|
|
|
(assert config.pname != null; config.pname)
|
2024-01-12 08:21:49 +01:00
|
|
|
(getName (mockPkgs.callPackage config.packages.default { }))
|
2024-01-12 02:27:34 +01:00
|
|
|
(getName (baseNixpkgs.callPackage config.packages.default { }))
|
|
|
|
(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
|
|
|
|
2024-01-10 10:16:24 +01:00
|
|
|
outputs = rec {
|
|
|
|
packages = genSystems (pkgs:
|
2024-01-12 09:45:22 +01:00
|
|
|
filterAttrs (_: supportedSystem pkgs)
|
|
|
|
(mapAttrs (k: _: pkgs.${k}) config.packages));
|
2023-08-25 06:14:55 +02:00
|
|
|
|
2024-01-10 10:16:24 +01:00
|
|
|
checks = mapAttrs
|
|
|
|
(_: mapAttrs' (n: nameValuePair ("packages-" + n)))
|
|
|
|
packages;
|
2023-08-25 06:14:55 +02:00
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|