mirror of
https://github.com/nix-community/flakelight.git
synced 2025-02-02 02:29:23 +01:00
Refactor apps to use types
This commit is contained in:
parent
afa2a89bae
commit
bac4759bcb
@ -4,25 +4,40 @@
|
|||||||
|
|
||||||
{ config, lib, flakelight, genSystems, ... }:
|
{ config, lib, flakelight, genSystems, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) isFunction mapAttrs mkIf mkMerge mkOption;
|
inherit (lib) isStringLike mapAttrs mkIf mkMerge mkOption mkOptionType;
|
||||||
inherit (lib.types) lazyAttrsOf raw;
|
inherit (lib.types) coercedTo lazyAttrsOf;
|
||||||
|
inherit (lib.options) mergeEqualOption;
|
||||||
inherit (flakelight.types) nullable optFunctionTo;
|
inherit (flakelight.types) nullable optFunctionTo;
|
||||||
|
|
||||||
isApp = x: (x ? type) && (x.type == "app") && (x ? program);
|
app = mkOptionType {
|
||||||
|
name = "app";
|
||||||
|
description = "flake app";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = x: (x ? type) && (x.type == "app") && (x ? program);
|
||||||
|
merge = mergeEqualOption;
|
||||||
|
};
|
||||||
|
|
||||||
mkApp = pkgs: app:
|
stringLike = mkOptionType {
|
||||||
let app' = if isFunction app then app pkgs else app; in
|
name = "stringLike";
|
||||||
if isApp app' then app' else { type = "app"; program = "${app'}"; };
|
description = "string-convertible value";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = isStringLike;
|
||||||
|
merge = mergeEqualOption;
|
||||||
|
};
|
||||||
|
|
||||||
|
mkApp = app: { type = "app"; program = "${app}"; };
|
||||||
|
|
||||||
|
appType = optFunctionTo (coercedTo stringLike mkApp app);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
app = mkOption {
|
app = mkOption {
|
||||||
type = nullable raw;
|
type = nullable appType;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
apps = mkOption {
|
apps = mkOption {
|
||||||
type = nullable (optFunctionTo (lazyAttrsOf raw));
|
type = nullable (optFunctionTo (lazyAttrsOf appType));
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -34,7 +49,7 @@ in
|
|||||||
|
|
||||||
(mkIf (config.apps != null) {
|
(mkIf (config.apps != null) {
|
||||||
outputs.apps = genSystems (pkgs:
|
outputs.apps = genSystems (pkgs:
|
||||||
mapAttrs (_: mkApp pkgs) (config.apps pkgs));
|
mapAttrs (_: v: v pkgs) (config.apps pkgs));
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user