about summary refs log tree commit diff
path: root/users/Profpatsch/blog
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-01-30T16·06+0300
committertazjin <tazjin@tvl.su>2022-01-31T16·11+0000
commitaa122cbae78ce97d60c0c98ba14df753d97e40b1 (patch)
tree12b98d85c4b18fe870feb26de70db9ba61837bd7 /users/Profpatsch/blog
parent2d10d60fac0fd00a71b65cfdcb9fba0477b2086c (diff)
style: format entire depot with nixpkgs-fmt r/3723
This CL can be used to compare the style of nixpkgs-fmt against other
formatters (nixpkgs, alejandra).

Change-Id: I87c6abff6bcb546b02ead15ad0405f81e01b6d9e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4397
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: lukegb <lukegb@tvl.fyi>
Reviewed-by: wpcarro <wpcarro@gmail.com>
Reviewed-by: Profpatsch <mail@profpatsch.de>
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: cynthia <cynthia@tvl.fyi>
Reviewed-by: edef <edef@edef.eu>
Reviewed-by: eta <tvl@eta.st>
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'users/Profpatsch/blog')
-rw-r--r--users/Profpatsch/blog/default.nix338
1 files changed, 214 insertions, 124 deletions
diff --git a/users/Profpatsch/blog/default.nix b/users/Profpatsch/blog/default.nix
index d3c5c596b4..44a7a21aa3 100644
--- a/users/Profpatsch/blog/default.nix
+++ b/users/Profpatsch/blog/default.nix
@@ -2,11 +2,11 @@
 
 let
   bins = depot.nix.getBins pkgs.lowdown [ "lowdown" ]
-      // 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" ]
-      ;
+    // 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" ]
+  ;
 
   # /
   # TODO: use
@@ -14,7 +14,7 @@ let
     {
       route = [ "notes" ];
       name = "Notes";
-      page = {cssFile}: router cssFile;
+      page = { cssFile }: router cssFile;
     }
     {
       route = [ "projects" ];
@@ -28,7 +28,7 @@ let
     {
       route = [ "notes" "preventing-oom" ];
       name = "Preventing out-of-memory (OOM) errors on Linux";
-      page = {cssFile}: markdownToHtml {
+      page = { cssFile }: markdownToHtml {
         name = "preventing-oom";
         markdown = ./notes/preventing-oom.md;
         inherit cssFile;
@@ -37,7 +37,7 @@ let
     {
       route = [ "notes" "rust-string-conversions" ];
       name = "Converting between different String types in Rust";
-      page = {cssFile}: markdownToHtml {
+      page = { cssFile }: markdownToHtml {
         name = "rust-string-conversions";
         markdown = ./notes/rust-string-conversions.md;
         inherit cssFile;
@@ -69,48 +69,52 @@ let
       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.";
-      page = {cssFile}: markdownToHtml {
+      page = { cssFile }: markdownToHtml {
         name = "2017-05-04-ligature-emluation-in-emacs";
         markdown = ./posts/2017-05-04-ligature-emulation-in-emacs.md;
         inherit cssFile;
       };
       route = [ "posts" "2017-05-04-ligature-emluation-in-emacs" ];
-      tags = ["emacs"];
+      tags = [ "emacs" ];
     }
   ];
 
   # convert a markdown file to html via lowdown
-  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"
+  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"
       (depot.users.Profpatsch.lib.debugExec "")
       bins.lowdown
-        "-s" "-Thtml"
-      ] ++
-        (lib.optional (cssFile != null) (["-M" "css=${mkRoute cssFile.route}"]))
-      ++ [
-        "-o" "$out"
-        markdown
+      "-s"
+      "-Thtml"
+    ] ++
+    (lib.optional (cssFile != null) ([ "-M" "css=${mkRoute cssFile.route}" ]))
+    ++ [
+      "-o"
+      "$out"
+      markdown
     ]);
 
   # takes a { route … } attrset and converts the route lists to an absolute path
   fullRoute = attrs: lib.pipe attrs [
-    (map (x@{route, ...}: x // { route = mkRoute route; }))
+    (map (x@{ route, ... }: x // { route = mkRoute route; }))
   ];
 
   # a cdb from route to a netencoded version of data for each route
   router = cssFile: lib.pipe (notes ++ posts) [
     (map (r: with depot.users.Profpatsch.lens;
-      lib.pipe r [
-        (over (field "route") mkRoute)
-        (over (field "page") (_ { inherit cssFile; }))
-      ]))
+    lib.pipe r [
+      (over (field "route") mkRoute)
+      (over (field "page") (_ { inherit cssFile; }))
+    ]))
     (map (x: {
       name = x.route;
       value = depot.users.Profpatsch.netencode.gen.dwim x;
@@ -121,11 +125,12 @@ let
 
   # 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.
-  depotCgitLink = {
-    # relative path from the depot root (without leading /).
-    relativePath
-  }:
-    assert
+  depotCgitLink =
+    {
+      # relative path from the depot root (without leading /).
+      relativePath
+    }:
+      assert
       (lib.assertMsg
         (builtins.pathExists (depot.path.origSrc + "/${relativePath}"))
         "depotCgitLink: path /${relativePath} does not exist in depot, and depot.path was ${toString depot.path}");
@@ -133,12 +138,20 @@ let
 
   # look up a route by path ($1)
   router-lookup = cssFile: depot.nix.writeExecline "router-lookup" { readNArgs = 1; } [
-    cdbLookup (router cssFile) "$1"
+    cdbLookup
+    (router cssFile)
+    "$1"
   ];
 
   runExeclineStdout = name: args: cmd: depot.nix.runExecline name args ([
-    "importas" "-ui" "out" "out"
-    "redirfd" "-w" "1" "$out"
+    "importas"
+    "-ui"
+    "out"
+    "out"
+    "redirfd"
+    "-w"
+    "1"
+    "$out"
   ] ++ cmd);
 
   notes-index-html =
@@ -170,106 +183,167 @@ let
   html = s: s;
 
   projects-index-html =
-  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>
-  '';
+    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>
+    '';
 
   projects-index = pkgs.writeText "projects-index.html" projects-index-html;
 
   posts-index-html =
-  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>
-  '';
+    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>
+    '';
 
   posts-index = pkgs.writeText "projects-index.html" posts-index-html;
 
   arglibNetencode = val: depot.nix.writeExecline "arglib-netencode" { } [
-    "export" "ARGLIB_NETENCODE" (depot.users.Profpatsch.netencode.gen.dwim val)
+    "export"
+    "ARGLIB_NETENCODE"
+    (depot.users.Profpatsch.netencode.gen.dwim val)
     "$@"
   ];
 
   # A simple http server that serves the site. Yes, it’s horrible.
-  site-server = { cssFile, port }: depot.nix.writeExecline "blog-server" {} [
+  site-server = { cssFile, port }: depot.nix.writeExecline "blog-server" { } [
     (depot.users.Profpatsch.lib.runInEmptyEnv [ "PATH" ])
-    bins.s6-tcpserver "127.0.0.1" port
-    bins.time "--format=time: %es" "--"
-    runOr return400
-    "pipeline" [
+    bins.s6-tcpserver
+    "127.0.0.1"
+    port
+    bins.time
+    "--format=time: %es"
+    "--"
+    runOr
+    return400
+    "pipeline"
+    [
       (arglibNetencode {
         what = "request";
       })
       depot.users.Profpatsch.read-http
     ]
     depot.users.Profpatsch.netencode.record-splice-env
-    runOr return500
-    "importas" "-i" "path" "path"
-    "if" [ depot.tools.eprintf "GET \${path}\n" ]
-    runOr return404
-    "backtick" "-ni" "TEMPLATE_DATA" [
+    runOr
+    return500
+    "importas"
+    "-i"
+    "path"
+    "path"
+    "if"
+    [ depot.tools.eprintf "GET \${path}\n" ]
+    runOr
+    return404
+    "backtick"
+    "-ni"
+    "TEMPLATE_DATA"
+    [
       # TODO: factor this out of here, this is routing not serving
-      "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
-        ]
+      "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
+      ]
       # TODO: ignore potential query arguments. See 404 message
-      "pipeline" [ (router-lookup cssFile) "$path" ]
+      "pipeline"
+      [ (router-lookup cssFile) "$path" ]
       depot.users.Profpatsch.netencode.record-splice-env
-      "importas" "-ui" "page" "page"
-      "export" "content-type" "text/html"
-      "export" "serve-file" "$page"
+      "importas"
+      "-ui"
+      "page"
+      "page"
+      "export"
+      "content-type"
+      "text/html"
+      "export"
+      "serve-file"
+      "$page"
       depot.users.Profpatsch.netencode.env-splice-record
     ]
-    runOr return500
-    "if" [
-      "pipeline" [ bins.printf ''
-        HTTP/1.1 200 OK
-        Content-Type: {{{content-type}}}; charset=UTF-8
-        Connection: close
-
-      '' ]
+    runOr
+    return500
+    "if"
+    [
+      "pipeline"
+      [
+        bins.printf
+        ''
+          HTTP/1.1 200 OK
+          Content-Type: {{{content-type}}}; charset=UTF-8
+          Connection: close
+
+        ''
+      ]
       depot.users.Profpatsch.netencode.netencode-mustache
     ]
-    "pipeline" [ "importas" "t" "TEMPLATE_DATA" bins.printf "%s" "$t" ]
+    "pipeline"
+    [ "importas" "t" "TEMPLATE_DATA" bins.printf "%s" "$t" ]
     depot.users.Profpatsch.netencode.record-splice-env
-    "importas" "-ui" "serve-file" "serve-file"
-    bins.cat "$serve-file"
+    "importas"
+    "-ui"
+    "serve-file"
+    "serve-file"
+    bins.cat
+    "$serve-file"
   ];
 
   # run argv or $1 if argv returns a failure status code.
   runOr = depot.nix.writeExecline "run-or" { readNArgs = 1; } [
-    "foreground" [ "$@" ]
-    "importas" "?" "?"
-    "ifelse" [ bins.test "$?" "-eq" "0" ]
-    []
-    "if" [ depot.tools.eprintf "runOr: exited \${?}, running \${1}\n" ]
+    "foreground"
+    [ "$@" ]
+    "importas"
+    "?"
+    "?"
+    "ifelse"
+    [ bins.test "$?" "-eq" "0" ]
+    [ ]
+    "if"
+    [ depot.tools.eprintf "runOr: exited \${?}, running \${1}\n" ]
     "$1"
   ];
 
-  return400 = depot.nix.writeExecline "return400" {} [
-    bins.printf "%s" ''
+  return400 = depot.nix.writeExecline "return400" { } [
+    bins.printf
+    "%s"
+    ''
       HTTP/1.1 400 Bad Request
       Content-Type: text/plain; charset=UTF-8
       Connection: close
@@ -277,8 +351,10 @@ let
     ''
   ];
 
-  return404 = depot.nix.writeExecline "return404" {} [
-    bins.printf "%s" ''
+  return404 = depot.nix.writeExecline "return404" { } [
+    bins.printf
+    "%s"
+    ''
       HTTP/1.1 404 Not Found
       Content-Type: text/plain; charset=UTF-8
       Connection: close
@@ -287,8 +363,10 @@ let
     ''
   ];
 
-  return500 = depot.nix.writeExecline "return500" {} [
-    bins.printf "%s" ''
+  return500 = depot.nix.writeExecline "return500" { } [
+    bins.printf
+    "%s"
+    ''
       HTTP/1.1 500 Internal Server Error
       Content-Type: text/plain; charset=UTF-8
       Connection: close
@@ -297,10 +375,11 @@ let
     ''
   ];
 
-  capture-stdin = depot.nix.writers.rustSimple {
-    name = "capture-stdin";
-    dependencies = [ depot.users.Profpatsch.execline.exec-helpers ];
-  } ''
+  capture-stdin = depot.nix.writers.rustSimple
+    {
+      name = "capture-stdin";
+      dependencies = [ depot.users.Profpatsch.execline.exec-helpers ];
+    } ''
     extern crate exec_helpers;
     use std::io::Read;
     fn main() {
@@ -337,29 +416,40 @@ let
   cdbRecords =
     with depot.nix.yants;
     defun [ (attrs (either drv string)) string ]
-    (attrs:
-      (lib.concatStrings (lib.mapAttrsToList cdbRecord attrs)) + "\n");
+      (attrs:
+        (lib.concatStrings (lib.mapAttrsToList cdbRecord attrs)) + "\n");
 
   # run cdbmake on a list of key/value pairs (strings
-  cdbMake = name: attrs: depot.nix.runExecline "${name}.cdb" {
-    stdin = cdbRecords attrs;
-  } [
-    "importas" "out" "out"
+  cdbMake = name: attrs: depot.nix.runExecline "${name}.cdb"
+    {
+      stdin = cdbRecords attrs;
+    } [
+    "importas"
+    "out"
+    "out"
     depot.users.Profpatsch.lib.eprint-stdin
-    "if" [ bins.cdbmake "db" "tmp" ]
-    bins.mv "db" "$out"
+    "if"
+    [ bins.cdbmake "db" "tmp" ]
+    bins.mv
+    "db"
+    "$out"
   ];
 
   # look up a key ($2) in the given cdb ($1)
   cdbLookup = depot.nix.writeExecline "cdb-lookup" { readNArgs = 2; } [
     # cdb ($1) on stdin
-    "redirfd" "-r" "0" "$1"
+    "redirfd"
+    "-r"
+    "0"
+    "$1"
     # key ($2) lookup
-    bins.cdbget "$2"
+    bins.cdbget
+    "$2"
   ];
 
-in depot.nix.readTree.drvTargets {
-   inherit
+in
+depot.nix.readTree.drvTargets {
+  inherit
     router
     depotCgitLink
     site-server