Fediversity/website/structure/assets.nix
Valentin Gagarin 419f2b881b implement raw assets
this allows adding files to the output as they are
2024-11-13 15:47:12 +01:00

36 lines
942 B
Nix

{ 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
'';
type = with types; attrsOf (submodule ({ config, ... }: {
imports = [ cfg.content-types.document ];
options.path = mkOption {
type = types.path;
};
config.name = builtins.baseNameOf config.path;
config.outputs."" = builtins.readFile config.path;
}));
default = { };
};
config.files = with lib;
let
flatten = attrs: mapAttrsToList
(name: value:
# HACK: we somehow have to distinguish a module value from regular attributes.
# arbitrary choice: the outputs attribute
if value ? outputs then value else mapAttrsToList value)
attrs;
in
cfg.templates.files (flatten cfg.assets);
}