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-10 10:16:24 +01:00
|
|
|
{ config, lib, flakelight, genSystems, ... }:
|
2023-08-25 06:14:55 +02:00
|
|
|
let
|
2024-02-20 10:25:27 +01:00
|
|
|
inherit (lib) isStringLike mapAttrs mkIf mkMerge mkOption mkOptionType;
|
2024-02-20 11:31:44 +01:00
|
|
|
inherit (lib.types) coercedTo lazyAttrsOf pathInStore;
|
2024-02-20 10:25:27 +01:00
|
|
|
inherit (lib.options) mergeEqualOption;
|
2024-02-07 09:54:03 +01:00
|
|
|
inherit (flakelight.types) nullable optFunctionTo;
|
2023-08-25 06:14:55 +02:00
|
|
|
|
2024-02-20 10:25:27 +01:00
|
|
|
app = mkOptionType {
|
|
|
|
name = "app";
|
|
|
|
description = "flake app";
|
|
|
|
descriptionClass = "noun";
|
2024-02-20 11:31:44 +01:00
|
|
|
check = x: (x ? type) && (x.type == "app") &&
|
|
|
|
(x ? program) && (pathInStore.check x.program);
|
2024-02-20 10:25:27 +01:00
|
|
|
merge = mergeEqualOption;
|
|
|
|
};
|
|
|
|
|
|
|
|
stringLike = mkOptionType {
|
|
|
|
name = "stringLike";
|
|
|
|
description = "string-convertible value";
|
|
|
|
descriptionClass = "noun";
|
|
|
|
check = isStringLike;
|
|
|
|
merge = mergeEqualOption;
|
|
|
|
};
|
|
|
|
|
|
|
|
mkApp = app: { type = "app"; program = "${app}"; };
|
2023-08-25 06:14:55 +02:00
|
|
|
|
2024-02-20 10:25:27 +01:00
|
|
|
appType = optFunctionTo (coercedTo stringLike mkApp app);
|
2023-08-25 06:14:55 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
app = mkOption {
|
2024-02-20 10:25:27 +01:00
|
|
|
type = nullable appType;
|
2023-08-25 06:14:55 +02:00
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
apps = mkOption {
|
2024-02-20 10:25:27 +01:00
|
|
|
type = nullable (optFunctionTo (lazyAttrsOf appType));
|
2023-08-25 06:14:55 +02:00
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
(mkIf (config.app != null) {
|
|
|
|
apps.default = config.app;
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (config.apps != null) {
|
2024-01-10 10:16:24 +01:00
|
|
|
outputs.apps = genSystems (pkgs:
|
2024-02-20 10:25:27 +01:00
|
|
|
mapAttrs (_: v: v pkgs) (config.apps pkgs));
|
2023-08-25 06:14:55 +02:00
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|