2021-05-15 02:51:50 +03:00
|
|
|
{ lib, pkgs }:
|
2021-05-15 02:39:30 +03:00
|
|
|
let pkgBin = name: "${pkgs.${name}}/bin/${name}"; in
|
|
|
|
{
|
2021-05-15 04:02:06 +03:00
|
|
|
mkServePathScript = path: pkgs.writeScriptBin "serve" ''
|
|
|
|
#!${pkgs.stdenv.shell}
|
2021-05-15 02:39:30 +03:00
|
|
|
${pkgBin "miniserve"} --index index.html ${path}
|
|
|
|
'';
|
2021-05-15 04:02:06 +03:00
|
|
|
|
|
|
|
mkSitePath = site:
|
|
|
|
let
|
|
|
|
fileAttrPaths = lib.recursiveAttrPaths site;
|
|
|
|
texts = lib.mapAttrsRecursive (path: value: pkgs.writeText (lib.concatStringsSep "-" path) value) site;
|
|
|
|
mkCreateFileCmd = path: value: let p = lib.concatStringsSep "/" (lib.init path); in "mkdir -p $out/${p} && ln -s ${value} $out/${p}/${lib.last path}";
|
|
|
|
createFileCmds = map (path: mkCreateFileCmd path (lib.getAttrFromPath path texts)) fileAttrPaths;
|
|
|
|
in
|
|
|
|
pkgs.runCommand "site-path" { } ''
|
|
|
|
mkdir -p $out
|
|
|
|
${lib.concatStringsSep "\n" createFileCmds}
|
|
|
|
'';
|
2021-05-15 02:39:30 +03:00
|
|
|
}
|