2021-01-29 15:58:33 +01:00
|
|
|
|
{ depot, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
bins = depot.nix.getBins pkgs.lowdown [ "lowdown" ]
|
2022-01-30 17:06:58 +01:00
|
|
|
|
// depot.nix.getBins pkgs.cdb [ "cdbget" "cdbmake" "cdbdump" ]
|
|
|
|
|
// depot.nix.getBins pkgs.coreutils [ "mv" "cat" "printf" "test" ]
|
|
|
|
|
// depot.nix.getBins pkgs.s6-networking [ "s6-tcpserver" ]
|
|
|
|
|
// depot.nix.getBins pkgs.time [ "time" ]
|
|
|
|
|
;
|
2021-01-29 15:58:33 +01:00
|
|
|
|
|
2021-08-07 19:44:17 +02:00
|
|
|
|
# /
|
2021-11-13 01:04:15 +01:00
|
|
|
|
# TODO: use
|
2021-08-07 18:57:24 +02:00
|
|
|
|
toplevel = [
|
|
|
|
|
{
|
|
|
|
|
route = [ "notes" ];
|
|
|
|
|
name = "Notes";
|
2022-01-30 17:06:58 +01:00
|
|
|
|
page = { cssFile }: router cssFile;
|
2021-08-07 18:57:24 +02:00
|
|
|
|
}
|
2021-08-07 21:17:32 +02:00
|
|
|
|
{
|
|
|
|
|
route = [ "projects" ];
|
|
|
|
|
name = "Projects";
|
|
|
|
|
# page = projects;
|
|
|
|
|
}
|
2021-08-07 18:57:24 +02:00
|
|
|
|
];
|
|
|
|
|
|
2021-08-07 19:44:17 +02:00
|
|
|
|
# /notes/*
|
2021-01-29 15:58:33 +01:00
|
|
|
|
notes = [
|
2024-01-13 17:10:46 +01:00
|
|
|
|
{
|
|
|
|
|
route = [ "notes" "private-trackers-are-markets" ];
|
|
|
|
|
name = "Private bittorrent trackers are markets";
|
|
|
|
|
page = { cssFile }: markdownToHtml {
|
|
|
|
|
name = "private-trackers-are-markets";
|
|
|
|
|
markdown = ./notes/private-trackers-are-markets.md;
|
|
|
|
|
inherit cssFile;
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-01-29 15:58:33 +01:00
|
|
|
|
{
|
2022-04-19 15:07:31 +02:00
|
|
|
|
route = [ "notes" "an-idealized-conflang" ];
|
|
|
|
|
name = "An Idealized Configuration Language";
|
2022-01-30 17:06:58 +01:00
|
|
|
|
page = { cssFile }: markdownToHtml {
|
2022-04-19 15:07:31 +02:00
|
|
|
|
name = "an-idealized-conflang";
|
|
|
|
|
markdown = ./notes/an-idealized-conflang.md;
|
2021-11-13 01:04:15 +01:00
|
|
|
|
inherit cssFile;
|
|
|
|
|
};
|
2021-05-04 00:11:14 +02:00
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
route = [ "notes" "rust-string-conversions" ];
|
|
|
|
|
name = "Converting between different String types in Rust";
|
2022-01-30 17:06:58 +01:00
|
|
|
|
page = { cssFile }: markdownToHtml {
|
2021-11-13 01:04:15 +01:00
|
|
|
|
name = "rust-string-conversions";
|
|
|
|
|
markdown = ./notes/rust-string-conversions.md;
|
|
|
|
|
inherit cssFile;
|
|
|
|
|
};
|
2021-01-29 15:58:33 +01:00
|
|
|
|
}
|
2022-04-19 15:07:31 +02:00
|
|
|
|
{
|
|
|
|
|
route = [ "notes" "preventing-oom" ];
|
|
|
|
|
name = "Preventing out-of-memory (OOM) errors on Linux";
|
|
|
|
|
page = { cssFile }: markdownToHtml {
|
|
|
|
|
name = "preventing-oom";
|
|
|
|
|
markdown = ./notes/preventing-oom.md;
|
|
|
|
|
inherit cssFile;
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-01-29 15:58:33 +01:00
|
|
|
|
];
|
|
|
|
|
|
2021-08-07 21:17:32 +02:00
|
|
|
|
projects = [
|
|
|
|
|
{
|
|
|
|
|
name = "lorri";
|
|
|
|
|
description = "<code>nix-shell</code> replacement for projects";
|
|
|
|
|
link = "https://github.com/nix-community/lorri";
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
name = "netencode";
|
2021-08-08 10:50:04 +02:00
|
|
|
|
description = ''A human-readble nested data exchange format inspired by <a href="https://en.wikipedia.org/wiki/Netstring">netstrings</a> and <a href="https://en.wikipedia.org/wiki/Bencode">bencode</a>.'';
|
2021-08-07 21:17:32 +02:00
|
|
|
|
link = depotCgitLink { relativePath = "users/Profpatsch/netencode/README.md"; };
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
name = "yarn2nix";
|
|
|
|
|
description = ''nix dependency generator for the <a href="https://yarnpkg.com/"><code>yarn</code> Javascript package manager</a>'';
|
|
|
|
|
link = "https://github.com/Profpatsch/yarn2nix";
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2021-08-08 10:50:04 +02:00
|
|
|
|
posts = [
|
|
|
|
|
{
|
|
|
|
|
date = "2017-05-04";
|
|
|
|
|
title = "Ligature Emulation in Emacs";
|
|
|
|
|
subtitle = "It’s not pretty, but the results are";
|
|
|
|
|
description = "How to set up ligatures using <code>prettify-symbols-mode</code> and the Hasklig/FiraCode fonts.";
|
2022-01-30 17:06:58 +01:00
|
|
|
|
page = { cssFile }: markdownToHtml {
|
2021-11-13 01:04:15 +01:00
|
|
|
|
name = "2017-05-04-ligature-emluation-in-emacs";
|
|
|
|
|
markdown = ./posts/2017-05-04-ligature-emulation-in-emacs.md;
|
|
|
|
|
inherit cssFile;
|
|
|
|
|
};
|
2021-08-08 10:50:04 +02:00
|
|
|
|
route = [ "posts" "2017-05-04-ligature-emluation-in-emacs" ];
|
2022-01-30 17:06:58 +01:00
|
|
|
|
tags = [ "emacs" ];
|
2021-08-08 10:50:04 +02:00
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
# convert a markdown file to html via lowdown
|
2022-01-30 17:06:58 +01:00
|
|
|
|
markdownToHtml =
|
|
|
|
|
{ name
|
|
|
|
|
, # the file to convert
|
|
|
|
|
markdown
|
|
|
|
|
, # css file to add to the final result, as { route }
|
|
|
|
|
cssFile
|
|
|
|
|
}:
|
|
|
|
|
depot.nix.runExecline "${name}.html" { } ([
|
|
|
|
|
"importas"
|
|
|
|
|
"out"
|
|
|
|
|
"out"
|
2021-11-13 01:04:15 +01:00
|
|
|
|
(depot.users.Profpatsch.lib.debugExec "")
|
|
|
|
|
bins.lowdown
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"-s"
|
|
|
|
|
"-Thtml"
|
|
|
|
|
] ++
|
|
|
|
|
(lib.optional (cssFile != null) ([ "-M" "css=${mkRoute cssFile.route}" ]))
|
|
|
|
|
++ [
|
|
|
|
|
"-o"
|
|
|
|
|
"$out"
|
|
|
|
|
markdown
|
2021-11-13 01:04:15 +01:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
# takes a { route … } attrset and converts the route lists to an absolute path
|
|
|
|
|
fullRoute = attrs: lib.pipe attrs [
|
2022-01-30 17:06:58 +01:00
|
|
|
|
(map (x@{ route, ... }: x // { route = mkRoute route; }))
|
2021-08-08 10:50:04 +02:00
|
|
|
|
];
|
|
|
|
|
|
2021-08-07 19:44:17 +02:00
|
|
|
|
# a cdb from route to a netencoded version of data for each route
|
2021-11-13 01:04:15 +01:00
|
|
|
|
router = cssFile: lib.pipe (notes ++ posts) [
|
|
|
|
|
(map (r: with depot.users.Profpatsch.lens;
|
2022-01-30 17:06:58 +01:00
|
|
|
|
lib.pipe r [
|
|
|
|
|
(over (field "route") mkRoute)
|
|
|
|
|
(over (field "page") (_ { inherit cssFile; }))
|
|
|
|
|
]))
|
2021-01-29 15:58:33 +01:00
|
|
|
|
(map (x: {
|
|
|
|
|
name = x.route;
|
2021-08-07 19:19:33 +02:00
|
|
|
|
value = depot.users.Profpatsch.netencode.gen.dwim x;
|
2021-01-29 15:58:33 +01:00
|
|
|
|
}))
|
|
|
|
|
lib.listToAttrs
|
2021-08-08 10:50:04 +02:00
|
|
|
|
(cdbMake "router")
|
2021-01-29 15:58:33 +01:00
|
|
|
|
];
|
|
|
|
|
|
2021-08-07 21:17:32 +02:00
|
|
|
|
# Create a link to the given source file/directory, given the relative path in the depot repo.
|
|
|
|
|
# Checks that the file exists at evaluation time.
|
2022-01-30 17:06:58 +01:00
|
|
|
|
depotCgitLink =
|
|
|
|
|
{
|
|
|
|
|
# relative path from the depot root (without leading /).
|
|
|
|
|
relativePath
|
|
|
|
|
}:
|
|
|
|
|
assert
|
2021-08-07 21:17:32 +02:00
|
|
|
|
(lib.assertMsg
|
2022-05-26 14:43:06 +02:00
|
|
|
|
(builtins.pathExists (depot.path.origSrc + ("/" + relativePath)))
|
2022-01-14 10:21:14 +01:00
|
|
|
|
"depotCgitLink: path /${relativePath} does not exist in depot, and depot.path was ${toString depot.path}");
|
2021-08-07 21:17:32 +02:00
|
|
|
|
"https://code.tvl.fyi/tree/${relativePath}";
|
|
|
|
|
|
2021-08-07 19:44:17 +02:00
|
|
|
|
# look up a route by path ($1)
|
2021-11-13 01:04:15 +01:00
|
|
|
|
router-lookup = cssFile: depot.nix.writeExecline "router-lookup" { readNArgs = 1; } [
|
2022-01-30 17:06:58 +01:00
|
|
|
|
cdbLookup
|
|
|
|
|
(router cssFile)
|
|
|
|
|
"$1"
|
2021-01-29 15:58:33 +01:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
runExeclineStdout = name: args: cmd: depot.nix.runExecline name args ([
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"importas"
|
|
|
|
|
"-ui"
|
|
|
|
|
"out"
|
|
|
|
|
"out"
|
|
|
|
|
"redirfd"
|
|
|
|
|
"-w"
|
|
|
|
|
"1"
|
|
|
|
|
"$out"
|
2021-01-29 15:58:33 +01:00
|
|
|
|
] ++ cmd);
|
|
|
|
|
|
2021-08-07 21:17:32 +02:00
|
|
|
|
notes-index-html =
|
2021-11-13 01:04:15 +01:00
|
|
|
|
let o = fullRoute notes;
|
2021-08-07 21:17:32 +02:00
|
|
|
|
in ''
|
|
|
|
|
<ul>
|
|
|
|
|
${scope o (o: ''
|
|
|
|
|
<li><a href="${str o.route}">${esc o.name}</a></li>
|
|
|
|
|
'')}
|
|
|
|
|
</ul>
|
|
|
|
|
'';
|
|
|
|
|
|
2021-08-08 10:50:04 +02:00
|
|
|
|
notes-index = pkgs.writeText "notes-index.html" notes-index-html;
|
2021-01-29 15:58:33 +01:00
|
|
|
|
|
2021-08-07 21:17:32 +02:00
|
|
|
|
# A simple mustache-inspired string interpolation combinator
|
|
|
|
|
# that takes an object and a template (a function from o to string)
|
|
|
|
|
# and returns a string.
|
|
|
|
|
scope = o: tpl:
|
|
|
|
|
if builtins.typeOf o == "list" then
|
|
|
|
|
lib.concatMapStringsSep "\n" tpl o
|
|
|
|
|
else if builtins.typeOf o == "set" then
|
|
|
|
|
tpl o
|
|
|
|
|
else throw "${lib.generators.toPretty {} o} not allowed in template";
|
|
|
|
|
|
|
|
|
|
# string-escape html (TODO)
|
|
|
|
|
str = s: s;
|
|
|
|
|
# html-escape (TODO)
|
|
|
|
|
esc = s: s;
|
|
|
|
|
html = s: s;
|
|
|
|
|
|
|
|
|
|
projects-index-html =
|
2022-01-30 17:06:58 +01:00
|
|
|
|
let o = projects;
|
|
|
|
|
in ''
|
|
|
|
|
<dl>
|
|
|
|
|
${scope o (o: ''
|
|
|
|
|
<dt><a href="${str o.link}">${esc o.name}</a></dt>
|
|
|
|
|
<dd>${html o.description}</dd>
|
|
|
|
|
'')}
|
|
|
|
|
</dl>
|
|
|
|
|
'';
|
2021-08-07 21:17:32 +02:00
|
|
|
|
|
2021-08-08 10:50:04 +02:00
|
|
|
|
projects-index = pkgs.writeText "projects-index.html" projects-index-html;
|
|
|
|
|
|
|
|
|
|
posts-index-html =
|
2022-01-30 17:06:58 +01:00
|
|
|
|
let o = fullRoute posts;
|
|
|
|
|
in ''
|
|
|
|
|
<dl>
|
|
|
|
|
${scope o (o: ''
|
|
|
|
|
<dt>${str o.date} <a href="${str o.route}">${esc o.title}</a></dt>
|
|
|
|
|
<dd>${html o.description}</dd>
|
|
|
|
|
'')}
|
|
|
|
|
</dl>
|
|
|
|
|
'';
|
2021-08-08 10:50:04 +02:00
|
|
|
|
|
|
|
|
|
posts-index = pkgs.writeText "projects-index.html" posts-index-html;
|
2021-08-07 21:17:32 +02:00
|
|
|
|
|
2021-01-29 15:58:33 +01:00
|
|
|
|
arglibNetencode = val: depot.nix.writeExecline "arglib-netencode" { } [
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"export"
|
|
|
|
|
"ARGLIB_NETENCODE"
|
|
|
|
|
(depot.users.Profpatsch.netencode.gen.dwim val)
|
2021-01-29 15:58:33 +01:00
|
|
|
|
"$@"
|
|
|
|
|
];
|
|
|
|
|
|
2021-08-07 19:44:17 +02:00
|
|
|
|
# A simple http server that serves the site. Yes, it’s horrible.
|
2022-01-30 17:06:58 +01:00
|
|
|
|
site-server = { cssFile, port }: depot.nix.writeExecline "blog-server" { } [
|
2021-08-07 19:19:33 +02:00
|
|
|
|
(depot.users.Profpatsch.lib.runInEmptyEnv [ "PATH" ])
|
2022-01-30 17:06:58 +01:00
|
|
|
|
bins.s6-tcpserver
|
|
|
|
|
"127.0.0.1"
|
|
|
|
|
port
|
|
|
|
|
bins.time
|
|
|
|
|
"--format=time: %es"
|
|
|
|
|
"--"
|
|
|
|
|
runOr
|
|
|
|
|
return400
|
|
|
|
|
"pipeline"
|
|
|
|
|
[
|
2021-01-29 15:58:33 +01:00
|
|
|
|
(arglibNetencode {
|
|
|
|
|
what = "request";
|
|
|
|
|
})
|
2021-08-07 19:19:33 +02:00
|
|
|
|
depot.users.Profpatsch.read-http
|
2021-01-29 15:58:33 +01:00
|
|
|
|
]
|
2021-08-07 19:19:33 +02:00
|
|
|
|
depot.users.Profpatsch.netencode.record-splice-env
|
2022-01-30 17:06:58 +01:00
|
|
|
|
runOr
|
|
|
|
|
return500
|
|
|
|
|
"importas"
|
|
|
|
|
"-i"
|
|
|
|
|
"path"
|
|
|
|
|
"path"
|
|
|
|
|
"if"
|
|
|
|
|
[ depot.tools.eprintf "GET \${path}\n" ]
|
|
|
|
|
runOr
|
|
|
|
|
return404
|
|
|
|
|
"backtick"
|
|
|
|
|
"-ni"
|
|
|
|
|
"TEMPLATE_DATA"
|
|
|
|
|
[
|
2021-08-07 21:17:32 +02:00
|
|
|
|
# TODO: factor this out of here, this is routing not serving
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"ifelse"
|
|
|
|
|
[ bins.test "$path" "=" "/notes" ]
|
|
|
|
|
[
|
|
|
|
|
"export"
|
|
|
|
|
"content-type"
|
|
|
|
|
"text/html"
|
|
|
|
|
"export"
|
|
|
|
|
"serve-file"
|
|
|
|
|
notes-index
|
|
|
|
|
depot.users.Profpatsch.netencode.env-splice-record
|
|
|
|
|
]
|
|
|
|
|
"ifelse"
|
|
|
|
|
[ bins.test "$path" "=" "/projects" ]
|
|
|
|
|
[
|
|
|
|
|
"export"
|
|
|
|
|
"content-type"
|
|
|
|
|
"text/html"
|
|
|
|
|
"export"
|
|
|
|
|
"serve-file"
|
|
|
|
|
projects-index
|
|
|
|
|
depot.users.Profpatsch.netencode.env-splice-record
|
|
|
|
|
]
|
|
|
|
|
"ifelse"
|
|
|
|
|
[ bins.test "$path" "=" "/posts" ]
|
|
|
|
|
[
|
|
|
|
|
"export"
|
|
|
|
|
"content-type"
|
|
|
|
|
"text/html"
|
|
|
|
|
"export"
|
|
|
|
|
"serve-file"
|
|
|
|
|
posts-index
|
|
|
|
|
depot.users.Profpatsch.netencode.env-splice-record
|
|
|
|
|
]
|
2021-01-29 15:58:33 +01:00
|
|
|
|
# TODO: ignore potential query arguments. See 404 message
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"pipeline"
|
|
|
|
|
[ (router-lookup cssFile) "$path" ]
|
2021-08-07 19:19:33 +02:00
|
|
|
|
depot.users.Profpatsch.netencode.record-splice-env
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"importas"
|
|
|
|
|
"-ui"
|
|
|
|
|
"page"
|
|
|
|
|
"page"
|
|
|
|
|
"export"
|
|
|
|
|
"content-type"
|
|
|
|
|
"text/html"
|
|
|
|
|
"export"
|
|
|
|
|
"serve-file"
|
|
|
|
|
"$page"
|
2021-08-07 19:19:33 +02:00
|
|
|
|
depot.users.Profpatsch.netencode.env-splice-record
|
2021-01-29 15:58:33 +01:00
|
|
|
|
]
|
2022-01-30 17:06:58 +01:00
|
|
|
|
runOr
|
|
|
|
|
return500
|
|
|
|
|
"if"
|
|
|
|
|
[
|
|
|
|
|
"pipeline"
|
|
|
|
|
[
|
|
|
|
|
bins.printf
|
|
|
|
|
''
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
|
Content-Type: {{{content-type}}}; charset=UTF-8
|
|
|
|
|
Connection: close
|
|
|
|
|
|
|
|
|
|
''
|
|
|
|
|
]
|
2021-08-07 19:19:33 +02:00
|
|
|
|
depot.users.Profpatsch.netencode.netencode-mustache
|
2021-01-29 15:58:33 +01:00
|
|
|
|
]
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"pipeline"
|
|
|
|
|
[ "importas" "t" "TEMPLATE_DATA" bins.printf "%s" "$t" ]
|
2021-08-07 19:19:33 +02:00
|
|
|
|
depot.users.Profpatsch.netencode.record-splice-env
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"importas"
|
|
|
|
|
"-ui"
|
|
|
|
|
"serve-file"
|
|
|
|
|
"serve-file"
|
|
|
|
|
bins.cat
|
|
|
|
|
"$serve-file"
|
2021-01-29 15:58:33 +01:00
|
|
|
|
];
|
|
|
|
|
|
2021-08-07 19:44:17 +02:00
|
|
|
|
# run argv or $1 if argv returns a failure status code.
|
2021-01-29 15:58:33 +01:00
|
|
|
|
runOr = depot.nix.writeExecline "run-or" { readNArgs = 1; } [
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"foreground"
|
|
|
|
|
[ "$@" ]
|
|
|
|
|
"importas"
|
|
|
|
|
"?"
|
|
|
|
|
"?"
|
|
|
|
|
"ifelse"
|
|
|
|
|
[ bins.test "$?" "-eq" "0" ]
|
|
|
|
|
[ ]
|
|
|
|
|
"if"
|
|
|
|
|
[ depot.tools.eprintf "runOr: exited \${?}, running \${1}\n" ]
|
2021-01-29 15:58:33 +01:00
|
|
|
|
"$1"
|
|
|
|
|
];
|
|
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
|
return400 = depot.nix.writeExecline "return400" { } [
|
|
|
|
|
bins.printf
|
|
|
|
|
"%s"
|
|
|
|
|
''
|
2021-01-29 15:58:33 +01:00
|
|
|
|
HTTP/1.1 400 Bad Request
|
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
|
Connection: close
|
|
|
|
|
|
|
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
|
return404 = depot.nix.writeExecline "return404" { } [
|
|
|
|
|
bins.printf
|
|
|
|
|
"%s"
|
|
|
|
|
''
|
2021-01-29 15:58:33 +01:00
|
|
|
|
HTTP/1.1 404 Not Found
|
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
|
Connection: close
|
|
|
|
|
|
|
|
|
|
This page doesn’t exist! Query arguments are not handled at the moment.
|
|
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
|
return500 = depot.nix.writeExecline "return500" { } [
|
|
|
|
|
bins.printf
|
|
|
|
|
"%s"
|
|
|
|
|
''
|
2021-01-29 15:58:33 +01:00
|
|
|
|
HTTP/1.1 500 Internal Server Error
|
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
|
Connection: close
|
|
|
|
|
|
|
|
|
|
Encountered an internal server error. Please try again.
|
|
|
|
|
''
|
|
|
|
|
];
|
|
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
|
capture-stdin = depot.nix.writers.rustSimple
|
|
|
|
|
{
|
|
|
|
|
name = "capture-stdin";
|
|
|
|
|
dependencies = [ depot.users.Profpatsch.execline.exec-helpers ];
|
|
|
|
|
} ''
|
2021-01-29 15:58:33 +01:00
|
|
|
|
extern crate exec_helpers;
|
|
|
|
|
use std::io::Read;
|
|
|
|
|
fn main() {
|
|
|
|
|
let (args, prog) = exec_helpers::args_for_exec("capture-stdin", 1);
|
|
|
|
|
let valname = &args[1];
|
|
|
|
|
let mut v : Vec<u8> = vec![];
|
|
|
|
|
std::io::stdin().lock().read_to_end(&mut v).unwrap();
|
|
|
|
|
exec_helpers::exec_into_args("capture-stdin", prog, vec![(valname, v)]);
|
|
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
|
2021-08-07 19:44:17 +02:00
|
|
|
|
# go from a list of path elements to an absolute route string
|
2021-01-29 15:58:33 +01:00
|
|
|
|
mkRoute = route: "/" + lib.concatMapStringsSep "/" urlencodeAscii route;
|
|
|
|
|
|
|
|
|
|
# urlencodes, but only ASCII characters
|
|
|
|
|
# https://en.wikipedia.org/wiki/Percent-encoding
|
|
|
|
|
urlencodeAscii = urlPiece:
|
|
|
|
|
let
|
|
|
|
|
raw = [ "!" "#" "$" "%" "&" "'" "(" ")" "*" "+" "," "/" ":" ";" "=" "?" "@" "[" "]" ];
|
|
|
|
|
enc = [ "%21" "%23" "%24" "%25" "%26" "%27" "%28" "%29" "%2A" "%2B" "%2C" "%2F" "%3A" "%3B" "%3D" "%3F" "%40" "%5B" "%5D" ];
|
|
|
|
|
rest = [ "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "-" "_" "." "~" ];
|
|
|
|
|
in
|
|
|
|
|
assert lib.assertMsg (lib.all (c: builtins.elem c (raw ++ rest)) (lib.stringToCharacters urlPiece))
|
|
|
|
|
"urlencodeAscii: the urlPiece must only contain valid url ASCII characters, was: ${urlPiece}";
|
|
|
|
|
builtins.replaceStrings raw enc urlPiece;
|
|
|
|
|
|
|
|
|
|
|
2021-08-07 19:44:17 +02:00
|
|
|
|
# create a cdb record entry, as required by the cdbmake tool
|
2021-01-29 15:58:33 +01:00
|
|
|
|
cdbRecord = key: val:
|
|
|
|
|
"+${toString (builtins.stringLength key)},${toString (builtins.stringLength val)}:"
|
|
|
|
|
+ "${key}->${val}\n";
|
2021-08-07 19:44:17 +02:00
|
|
|
|
|
|
|
|
|
# create a full cdbmake input from an attribute set of keys to values (strings)
|
2021-01-29 15:58:33 +01:00
|
|
|
|
cdbRecords =
|
|
|
|
|
with depot.nix.yants;
|
|
|
|
|
defun [ (attrs (either drv string)) string ]
|
2022-01-30 17:06:58 +01:00
|
|
|
|
(attrs:
|
|
|
|
|
(lib.concatStrings (lib.mapAttrsToList cdbRecord attrs)) + "\n");
|
2021-01-29 15:58:33 +01:00
|
|
|
|
|
2021-08-07 19:44:17 +02:00
|
|
|
|
# run cdbmake on a list of key/value pairs (strings
|
2022-01-30 17:06:58 +01:00
|
|
|
|
cdbMake = name: attrs: depot.nix.runExecline "${name}.cdb"
|
|
|
|
|
{
|
|
|
|
|
stdin = cdbRecords attrs;
|
|
|
|
|
} [
|
|
|
|
|
"importas"
|
|
|
|
|
"out"
|
|
|
|
|
"out"
|
2021-08-07 19:19:33 +02:00
|
|
|
|
depot.users.Profpatsch.lib.eprint-stdin
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"if"
|
|
|
|
|
[ bins.cdbmake "db" "tmp" ]
|
|
|
|
|
bins.mv
|
|
|
|
|
"db"
|
|
|
|
|
"$out"
|
2021-01-29 15:58:33 +01:00
|
|
|
|
];
|
|
|
|
|
|
2021-08-07 19:44:17 +02:00
|
|
|
|
# look up a key ($2) in the given cdb ($1)
|
2021-01-29 15:58:33 +01:00
|
|
|
|
cdbLookup = depot.nix.writeExecline "cdb-lookup" { readNArgs = 2; } [
|
|
|
|
|
# cdb ($1) on stdin
|
2022-01-30 17:06:58 +01:00
|
|
|
|
"redirfd"
|
|
|
|
|
"-r"
|
|
|
|
|
"0"
|
|
|
|
|
"$1"
|
2021-01-29 15:58:33 +01:00
|
|
|
|
# key ($2) lookup
|
2022-01-30 17:06:58 +01:00
|
|
|
|
bins.cdbget
|
|
|
|
|
"$2"
|
2021-01-29 15:58:33 +01:00
|
|
|
|
];
|
|
|
|
|
|
2022-01-30 17:06:58 +01:00
|
|
|
|
in
|
|
|
|
|
depot.nix.readTree.drvTargets {
|
|
|
|
|
inherit
|
2021-01-29 15:58:33 +01:00
|
|
|
|
router
|
2021-08-07 21:17:32 +02:00
|
|
|
|
depotCgitLink
|
|
|
|
|
site-server
|
|
|
|
|
notes-index
|
|
|
|
|
notes-index-html
|
|
|
|
|
projects-index
|
|
|
|
|
projects-index-html
|
2021-08-08 10:50:04 +02:00
|
|
|
|
posts-index-html
|
2021-01-29 15:58:33 +01:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
}
|