feat: add web host
This commit is contained in:
parent
df9367d12f
commit
155801244a
3 changed files with 63 additions and 1 deletions
34
data/web.nix
Normal file
34
data/web.nix
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
let
|
||||
lib = import <nixpkgs/lib>;
|
||||
mapFileNameToContent = fileName: {
|
||||
status = 200;
|
||||
contentType = "text/html";
|
||||
content = builtins.readFile fileName;
|
||||
};
|
||||
findFiles = dir:
|
||||
let content = builtins.readDir dir;
|
||||
processEntry = name: type:
|
||||
if type == "directory" then
|
||||
findFiles (dir + "/${name}")
|
||||
else if type == "regular" then
|
||||
[ (dir + "/${name}") ]
|
||||
else
|
||||
[];
|
||||
in
|
||||
lib.concatLists (lib.mapAttrsToList processEntry content);
|
||||
removePrefix = str: prefix: if builtins.substring 0 (builtins.stringLength prefix) str == prefix
|
||||
then builtins.substring (builtins.stringLength prefix) (builtins.stringLength str - builtins.stringLength prefix) str
|
||||
else str;
|
||||
contentFn = basePath:
|
||||
let
|
||||
files = findFiles basePath;
|
||||
baseLength = builtins.stringLength basePath;
|
||||
files' = builtins.filter (file: builtins.match ".*\\.html$" file != null) files;
|
||||
in builtins.listToAttrs (map (file: {
|
||||
name = removePrefix file basePath;
|
||||
value = mapFileNameToContent file;
|
||||
}) files');
|
||||
in
|
||||
rec {
|
||||
"nudelerde.de" = contentFn "/etc/nixos/data/web/";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue