1
1
forked from extern/flakelight
flakelight/builtinModules/apps.nix

57 lines
1.4 KiB
Nix
Raw Normal View History

# flakelight -- Framework for simplifying flake setup
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
# SPDX-License-Identifier: MIT
{ config, lib, flakelight, genSystems, ... }:
let
2024-02-20 10:25:27 +01:00
inherit (lib) isStringLike mapAttrs mkIf mkMerge mkOption mkOptionType;
inherit (lib.types) coercedTo lazyAttrsOf pathInStore;
2024-02-20 10:25:27 +01:00
inherit (lib.options) mergeEqualOption;
inherit (flakelight.types) nullable optFunctionTo;
2024-02-20 10:25:27 +01:00
app = mkOptionType {
name = "app";
description = "flake app";
descriptionClass = "noun";
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}"; };
2024-02-20 10:25:27 +01:00
appType = optFunctionTo (coercedTo stringLike mkApp app);
in
{
options = {
app = mkOption {
2024-02-20 10:25:27 +01:00
type = nullable appType;
default = null;
};
apps = mkOption {
2024-02-20 10:25:27 +01:00
type = nullable (optFunctionTo (lazyAttrsOf appType));
default = null;
};
};
config = mkMerge [
(mkIf (config.app != null) {
apps.default = config.app;
})
(mkIf (config.apps != null) {
outputs.apps = genSystems (pkgs:
2024-02-20 10:25:27 +01:00
mapAttrs (_: v: v pkgs) (config.apps pkgs));
})
];
}