Fediversity/website/structure/assets.nix

45 lines
1 KiB
Nix
Raw Normal View History

{ config, lib, ... }:
let
inherit (lib)
mkOption
types
;
cfg = config;
in
{
options.assets = mkOption {
description = ''
Collection of assets, i.e. static files that can be linked to from within documents
'';
2025-02-19 18:34:19 +01:00
type =
with types;
attrsOf (
submodule (
{ config, ... }:
{
imports = [ cfg.content-types.document ];
options.path = mkOption {
type = types.path;
};
config.outputs."" = if lib.isStorePath config.path then config.path else "${config.path}";
}
)
);
default = { };
};
2025-02-19 18:34:19 +01:00
config.files =
with lib;
let
2025-02-19 18:34:19 +01:00
flatten =
attrs:
mapAttrsToList (
2025-02-19 18:38:05 +01:00
_name: value:
# HACK: we somehow have to distinguish a module value from regular attributes.
# arbitrary choice: the outputs attribute
2025-02-19 18:34:19 +01:00
if value ? outputs then value else mapAttrsToList value
) attrs;
in
cfg.templates.files (flatten cfg.assets);
}