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 07:48:57 +02:00
|
|
|
{ config, inputs, lib, flakelight, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
|
|
|
inherit (builtins) all head isAttrs length;
|
2024-01-12 10:26:49 +01:00
|
|
|
inherit (lib) foldAttrs genAttrs getFiles getValues mapAttrs mergeAttrs
|
|
|
|
mkOption mkOptionType showFiles showOption;
|
2023-08-25 06:14:55 +02:00
|
|
|
inherit (lib.types) functionTo lazyAttrsOf listOf nonEmptyStr raw uniq;
|
2023-08-27 07:48:57 +02:00
|
|
|
inherit (flakelight.types) optListOf overlay;
|
2023-08-25 06:14:55 +02:00
|
|
|
|
|
|
|
outputs = mkOptionType {
|
|
|
|
name = "outputs";
|
|
|
|
description = "output values";
|
|
|
|
descriptionClass = "noun";
|
|
|
|
merge = loc: defs:
|
|
|
|
if (length defs) == 1 then (head defs).value
|
|
|
|
else if all isAttrs (getValues defs) then
|
|
|
|
(lazyAttrsOf outputs).merge loc defs
|
|
|
|
else throw "The option `${showOption loc}' has conflicting definitions in ${showFiles (getFiles defs)}";
|
|
|
|
};
|
2024-01-10 08:52:36 +01:00
|
|
|
|
|
|
|
pkgsFor = genAttrs config.systems (system: import inputs.nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
inherit (config.nixpkgs) config;
|
|
|
|
overlays = config.withOverlays ++ [ config.packageOverlay ];
|
|
|
|
});
|
2024-01-10 10:16:24 +01:00
|
|
|
|
|
|
|
genSystems = f: genAttrs config.systems (system: f pkgsFor.${system});
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
inputs = mkOption {
|
|
|
|
type = lazyAttrsOf raw;
|
|
|
|
};
|
|
|
|
|
|
|
|
systems = mkOption {
|
|
|
|
type = uniq (listOf nonEmptyStr);
|
|
|
|
default = [ "x86_64-linux" "aarch64-linux" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
outputs = mkOption {
|
|
|
|
type = lazyAttrsOf outputs;
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
perSystem = mkOption {
|
|
|
|
type = functionTo (lazyAttrsOf outputs);
|
|
|
|
default = _: { };
|
|
|
|
};
|
|
|
|
|
|
|
|
nixpkgs.config = mkOption {
|
|
|
|
type = lazyAttrsOf raw;
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
withOverlays = mkOption {
|
|
|
|
type = optListOf overlay;
|
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2024-01-10 08:52:36 +01:00
|
|
|
_module.args = {
|
|
|
|
inherit (config) inputs outputs;
|
2024-01-10 10:16:24 +01:00
|
|
|
inherit pkgsFor genSystems;
|
2024-01-10 08:52:36 +01:00
|
|
|
};
|
2023-08-25 06:14:55 +02:00
|
|
|
|
|
|
|
outputs = foldAttrs mergeAttrs { } (map
|
|
|
|
(system: mapAttrs
|
|
|
|
(_: v: { ${system} = v; })
|
2024-01-10 08:52:36 +01:00
|
|
|
(config.perSystem pkgsFor.${system}))
|
2023-08-25 06:14:55 +02:00
|
|
|
config.systems);
|
|
|
|
};
|
|
|
|
}
|