blob: e202361e337f3fb020b469b2ea73bd6649a1e08f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
{
config,
pkgs,
lib,
...
}:
let
inherit (lib) mkOption types;
in
{
imports =
with lib.fileset;
toList (difference (fileFilter (file: file.hasExt "nix") ./.) ./default.nix);
options = {
types = mkOption {
description = "Datentypen für Website-Inhalte";
type = with types; lazyAttrsOf deferredModule;
default = { };
};
title = mkOption {
description = "Titel, der bei allen Seiten vorangestellt wird";
type = types.singleLineStr;
readOnly = true;
};
files = mkOption {
description = ''
Dateien, aus denen die Website besteht, als Abbildung vom Dateipfad zum Inhalt
'';
type = with types; attrsOf (either path (submodule config.types.file));
};
events = mkOption {
description = ''
Termine
'';
type = with types; attrsOf (submodule config.types.event);
default = { };
};
redirects.raw = mkOption {
description = ''
Weiterleitungen aller historischen Dateipfade auf Kanonische Pfade
'';
type = with types; lazyAttrsOf str;
readOnly = true;
default =
with lib;
listToAttrs (
concatMap (
name:
if config.files.${name} ? locations then
map (loc: {
name = "/" + loc;
value = "/" + name;
}) (tail config.files.${name}.locations)
else
[ ]
) (attrNames config.files)
);
};
redirects.caddy = mkOption {
description = ''
Weiterleitungen im Caddyfile-Format
'';
type = types.str;
readOnly = true;
default =
with lib;
let
lines = mapAttrsToList (name: value: ''redir "${name}" ${value} permanent'') config.redirects.raw;
in
concatStringsSep "\n" lines;
};
result = mkOption {
description = ''
Fertige Website als Verzeichnis
'';
type = types.package;
readOnly = true;
default =
let
script = ''
mkdir $out
''
+ lib.concatStringsSep "\n" copy;
copy = lib.mapAttrsToList (
path: file:
let
content = if file ? path then file.path else file;
in
''
mkdir -p $out/$(dirname '${toString path}')
${
"" # `--no-preserve-mode` ist erforderlich da Nix store paths read-only sind, und man andernfalls `cp -r` nicht durchführen kann.
}cp -r --no-preserve=mode ${content} $out/'${toString path}'
''
) config.files;
in
pkgs.runCommand "source" { } script;
};
};
config.types.document =
{ lib, ... }:
let
inherit (lib) mkOption types;
in
{
options = {
locations = mkOption {
description = ''
Frühere Pfade dieses Dokuments
Einträge sind relative Pfade.
Der erste Eintrag ist der kanonische Pfad.
Alle anderen Elemente werden für Weiterleitungen zum kanonischen Pfad benutzt.
'';
type = with types; nonEmptyListOf str;
example = [
"about/overview"
"index"
];
};
};
};
config.types.file =
{ lib, ... }:
let
inherit (lib) mkOption types;
in
{
imports = [ config.types.document ];
options = {
path = mkOption {
type = types.path;
description = ''
Datei mit manuell gesteuertem Pfad
'';
};
};
};
}
|