From aa122cbae78ce97d60c0c98ba14df753d97e40b1 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 30 Jan 2022 19:06:58 +0300 Subject: style: format entire depot with nixpkgs-fmt 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 Reviewed-by: lukegb Reviewed-by: wpcarro Reviewed-by: Profpatsch Reviewed-by: kanepyork Reviewed-by: tazjin Reviewed-by: cynthia Reviewed-by: edef Reviewed-by: eta Reviewed-by: grfn --- users/Profpatsch/arglib/netencode.nix | 18 +- users/Profpatsch/atomically-write.nix | 3 +- users/Profpatsch/blog/default.nix | 338 +++++++++++++-------- users/Profpatsch/cdb.nix | 20 +- .../Profpatsch/emacs-tree-sitter-move/default.nix | 4 +- users/Profpatsch/emacs-tree-sitter-move/shell.nix | 7 +- users/Profpatsch/execline/default.nix | 24 +- users/Profpatsch/git-db/default.nix | 6 +- users/Profpatsch/imap-idle.nix | 23 +- users/Profpatsch/lens.nix | 7 +- users/Profpatsch/lib.nix | 79 +++-- users/Profpatsch/netencode/default.nix | 105 ++++--- users/Profpatsch/netencode/gen.nix | 40 +-- users/Profpatsch/netstring/default.nix | 19 +- users/Profpatsch/netstring/tests/default.nix | 29 +- users/Profpatsch/nix-home/default.nix | 180 +++++++---- users/Profpatsch/nixpkgs-rewriter/default.nix | 128 +++++--- users/Profpatsch/read-http.nix | 25 +- users/Profpatsch/reverse-haskell-deps.nix | 25 +- users/Profpatsch/struct-edit/default.nix | 20 +- users/Profpatsch/tree-sitter.nix | 176 ++++++----- users/Profpatsch/writers/default.nix | 115 ++++--- users/Profpatsch/writers/tests/default.nix | 40 ++- users/Profpatsch/ytextr/create-symlink-farm.nix | 13 +- users/Profpatsch/ytextr/default.nix | 91 +++--- 25 files changed, 932 insertions(+), 603 deletions(-) (limited to 'users/Profpatsch') diff --git a/users/Profpatsch/arglib/netencode.nix b/users/Profpatsch/arglib/netencode.nix index 50f4c11c2d8f..3f1d121e5132 100644 --- a/users/Profpatsch/arglib/netencode.nix +++ b/users/Profpatsch/arglib/netencode.nix @@ -2,13 +2,14 @@ let netencode = { - rust = depot.nix.writers.rustSimpleLib { - name = "arglib-netencode"; - dependencies = [ - depot.users.Profpatsch.execline.exec-helpers - depot.users.Profpatsch.netencode.netencode-rs - ]; - } '' + rust = depot.nix.writers.rustSimpleLib + { + name = "arglib-netencode"; + dependencies = [ + depot.users.Profpatsch.execline.exec-helpers + depot.users.Profpatsch.netencode.netencode-rs + ]; + } '' extern crate netencode; extern crate exec_helpers; @@ -37,4 +38,5 @@ let ''; }; -in depot.nix.readTree.drvTargets netencode +in +depot.nix.readTree.drvTargets netencode diff --git a/users/Profpatsch/atomically-write.nix b/users/Profpatsch/atomically-write.nix index d5039d3e46b9..c4d07cfbb1fa 100644 --- a/users/Profpatsch/atomically-write.nix +++ b/users/Profpatsch/atomically-write.nix @@ -25,4 +25,5 @@ let mv "$tmp/out" "$to" ''; -in atomically-write +in +atomically-write diff --git a/users/Profpatsch/blog/default.nix b/users/Profpatsch/blog/default.nix index d3c5c596b444..44a7a21aa3c3 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 prettify-symbols-mode 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 '' -
- ${scope o (o: '' -
${esc o.name}
-
${html o.description}
- '')} -
- ''; + let o = projects; + in '' +
+ ${scope o (o: '' +
${esc o.name}
+
${html o.description}
+ '')} +
+ ''; projects-index = pkgs.writeText "projects-index.html" projects-index-html; posts-index-html = - let o = fullRoute posts; - in '' -
- ${scope o (o: '' -
${str o.date} ${esc o.title}
-
${html o.description}
- '')} -
- ''; + let o = fullRoute posts; + in '' +
+ ${scope o (o: '' +
${str o.date} ${esc o.title}
+
${html o.description}
+ '')} +
+ ''; 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 diff --git a/users/Profpatsch/cdb.nix b/users/Profpatsch/cdb.nix index 8cfaa3ea7ac6..86e0a2d58f24 100644 --- a/users/Profpatsch/cdb.nix +++ b/users/Profpatsch/cdb.nix @@ -1,14 +1,15 @@ { depot, pkgs, ... }: let - cdbListToNetencode = depot.nix.writers.rustSimple { - name = "cdb-list-to-netencode"; - dependencies = [ - depot.third_party.rust-crates.nom - depot.users.Profpatsch.execline.exec-helpers - depot.users.Profpatsch.netencode.netencode-rs - ]; - } '' + cdbListToNetencode = depot.nix.writers.rustSimple + { + name = "cdb-list-to-netencode"; + dependencies = [ + depot.third_party.rust-crates.nom + depot.users.Profpatsch.execline.exec-helpers + depot.users.Profpatsch.netencode.netencode-rs + ]; + } '' extern crate nom; extern crate exec_helpers; extern crate netencode; @@ -84,7 +85,8 @@ let ''; -in { +in +{ inherit cdbListToNetencode ; diff --git a/users/Profpatsch/emacs-tree-sitter-move/default.nix b/users/Profpatsch/emacs-tree-sitter-move/default.nix index fdc059c089b6..a9f259d96d20 100644 --- a/users/Profpatsch/emacs-tree-sitter-move/default.nix +++ b/users/Profpatsch/emacs-tree-sitter-move/default.nix @@ -1,3 +1,3 @@ # nothing yet (TODO: expose shell & tool) -{...}: -{} +{ ... }: +{ } diff --git a/users/Profpatsch/emacs-tree-sitter-move/shell.nix b/users/Profpatsch/emacs-tree-sitter-move/shell.nix index 81d622ac73e5..f400d5c02161 100644 --- a/users/Profpatsch/emacs-tree-sitter-move/shell.nix +++ b/users/Profpatsch/emacs-tree-sitter-move/shell.nix @@ -1,14 +1,15 @@ -{ pkgs ? import ../../../third_party {}, ... }: +{ pkgs ? import ../../../third_party { }, ... }: let inherit (pkgs) lib; - treeSitterGrammars = pkgs.runCommandLocal "grammars" {} '' + treeSitterGrammars = pkgs.runCommandLocal "grammars" { } '' mkdir -p $out/bin ${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: src: "ln -s ${src}/parser $out/bin/${name}.so") pkgs.tree-sitter.builtGrammars)}; ''; -in pkgs.mkShell { +in +pkgs.mkShell { buildInputs = [ pkgs.tree-sitter.builtGrammars.python ]; diff --git a/users/Profpatsch/execline/default.nix b/users/Profpatsch/execline/default.nix index c6a8d284a634..752774e6ad0c 100644 --- a/users/Profpatsch/execline/default.nix +++ b/users/Profpatsch/execline/default.nix @@ -1,16 +1,19 @@ { depot, pkgs, lib, ... }: let - exec-helpers = depot.nix.writers.rustSimpleLib { - name = "exec-helpers"; - } (builtins.readFile ./exec_helpers.rs); + exec-helpers = depot.nix.writers.rustSimpleLib + { + name = "exec-helpers"; + } + (builtins.readFile ./exec_helpers.rs); - print-one-env = depot.nix.writers.rustSimple { - name = "print-one-env"; - dependencies = [ - depot.users.Profpatsch.execline.exec-helpers - ]; - } '' + print-one-env = depot.nix.writers.rustSimple + { + name = "print-one-env"; + dependencies = [ + depot.users.Profpatsch.execline.exec-helpers + ]; + } '' extern crate exec_helpers; use std::os::unix::ffi::OsStrExt; use std::io::Write; @@ -25,7 +28,8 @@ let } ''; -in depot.nix.readTree.drvTargets { +in +depot.nix.readTree.drvTargets { inherit exec-helpers print-one-env diff --git a/users/Profpatsch/git-db/default.nix b/users/Profpatsch/git-db/default.nix index 7c6f1aee7c5c..ad5d927677bf 100644 --- a/users/Profpatsch/git-db/default.nix +++ b/users/Profpatsch/git-db/default.nix @@ -1,8 +1,10 @@ { depot, pkgs, lib, ... }: -depot.nix.writers.rustSimple { +depot.nix.writers.rustSimple +{ name = "git-db"; dependencies = [ depot.third_party.rust-crates.git2 ]; -} (builtins.readFile ./git-db.rs) +} + (builtins.readFile ./git-db.rs) diff --git a/users/Profpatsch/imap-idle.nix b/users/Profpatsch/imap-idle.nix index 3ad5375d89af..84af5d0e54a9 100644 --- a/users/Profpatsch/imap-idle.nix +++ b/users/Profpatsch/imap-idle.nix @@ -1,14 +1,17 @@ { depot, pkgs, lib, ... }: let - imap-idle = depot.nix.writers.rustSimple { - name = "imap-idle"; - dependencies = [ - depot.users.Profpatsch.arglib.netencode.rust - depot.third_party.rust-crates.imap - depot.third_party.rust-crates.epoll - depot.users.Profpatsch.execline.exec-helpers - ]; - } (builtins.readFile ./imap-idle.rs); + imap-idle = depot.nix.writers.rustSimple + { + name = "imap-idle"; + dependencies = [ + depot.users.Profpatsch.arglib.netencode.rust + depot.third_party.rust-crates.imap + depot.third_party.rust-crates.epoll + depot.users.Profpatsch.execline.exec-helpers + ]; + } + (builtins.readFile ./imap-idle.rs); -in imap-idle +in +imap-idle diff --git a/users/Profpatsch/lens.nix b/users/Profpatsch/lens.nix index 58d9c27f5242..28f7506bddae 100644 --- a/users/Profpatsch/lens.nix +++ b/users/Profpatsch/lens.nix @@ -32,7 +32,7 @@ let inherit fst snd; }; - swap = {fst, snd}: { + swap = { fst, snd }: { fst = snd; snd = fst; }; @@ -71,7 +71,7 @@ let lensP = strong: to: pab: strong.dimap to - ({fst,snd}: snd fst) + ({ fst, snd }: snd fst) (strong.firstP pab); # first element of a tuple @@ -112,7 +112,8 @@ let (map (accessor: accessor profunctorSubclass) accessors); -in { +in +{ inherit id _ diff --git a/users/Profpatsch/lib.nix b/users/Profpatsch/lib.nix index e3d59b7d8beb..879d87755d56 100644 --- a/users/Profpatsch/lib.nix +++ b/users/Profpatsch/lib.nix @@ -1,34 +1,49 @@ { depot, pkgs, ... }: let bins = depot.nix.getBins pkgs.coreutils [ "printf" "echo" "cat" "printenv" "tee" ] - // depot.nix.getBins pkgs.bash [ "bash" ] - // depot.nix.getBins pkgs.fdtools [ "multitee" ] - ; + // depot.nix.getBins pkgs.bash [ "bash" ] + // depot.nix.getBins pkgs.fdtools [ "multitee" ] + ; # Print `msg` and and argv to stderr, then execute into argv - debugExec = msg: depot.nix.writeExecline "debug-exec" {} [ - "if" [ - "fdmove" "-c" "1" "2" - "if" [ bins.printf "%s: " msg ] - "if" [ bins.echo "$@" ] + debugExec = msg: depot.nix.writeExecline "debug-exec" { } [ + "if" + [ + "fdmove" + "-c" + "1" + "2" + "if" + [ bins.printf "%s: " msg ] + "if" + [ bins.echo "$@" ] ] "$@" ]; # Print stdin to stderr and stdout - eprint-stdin = depot.nix.writeExecline "eprint-stdin" {} [ - "pipeline" [ bins.multitee "0-1,2" ] "$@" + eprint-stdin = depot.nix.writeExecline "eprint-stdin" { } [ + "pipeline" + [ bins.multitee "0-1,2" ] + "$@" ]; # Assume the input on stdin is netencode, pretty print it to stderr and forward it to stdout - eprint-stdin-netencode = depot.nix.writeExecline "eprint-stdin-netencode" {} [ - "pipeline" [ + eprint-stdin-netencode = depot.nix.writeExecline "eprint-stdin-netencode" { } [ + "pipeline" + [ # move stdout to 3 - "fdmove" "3" "1" + "fdmove" + "3" + "1" # the multitee copies stdin to 1 (the other pipeline end) and 3 (the stdout of the outer pipeline block) - "pipeline" [ bins.multitee "0-1,3" ] + "pipeline" + [ bins.multitee "0-1,3" ] # make stderr the stdout of pretty, merging with the stderr of pretty - "fdmove" "-c" "1" "2" + "fdmove" + "-c" + "1" + "2" depot.users.Profpatsch.netencode.pretty ] "$@" @@ -36,9 +51,11 @@ let # print the given environment variable in $1 to stderr, then execute into the rest of argv eprintenv = depot.nix.writeExecline "eprintenv" { readNArgs = 1; } [ - "ifelse" [ "fdmove" "-c" "1" "2" bins.printenv "$1" ] + "ifelse" + [ "fdmove" "-c" "1" "2" bins.printenv "$1" ] [ "$@" ] - "if" [ depot.tools.eprintf "eprintenv: could not find \"\${1}\" in the environment\n" ] + "if" + [ depot.tools.eprintf "eprintenv: could not find \"\${1}\" in the environment\n" ] "$@" ]; @@ -52,24 +69,34 @@ let # stdout: foo\n # stderr: foo\nbar\n split-stdin = depot.nix.writeExecline "split-stdin" { argMode = "env"; } [ - "pipeline" [ + "pipeline" + [ # this is horrible yes but the quickest way I knew how to implement it - "runblock" "1" bins.bash "-c" ''${bins.tee} >("$@")'' "bash-split-stdin" + "runblock" + "1" + bins.bash + "-c" + ''${bins.tee} >("$@")'' + "bash-split-stdin" ] - "runblock" "-r" "1" + "runblock" + "-r" + "1" ]; # remove everything but a few selected environment variables runInEmptyEnv = keepVars: let - importas = pkgs.lib.concatMap (var: [ "importas" "-i" var var ]) keepVars; - # we have to explicitely call export here, because PATH is probably empty - export = pkgs.lib.concatMap (var: [ "${pkgs.execline}/bin/export" var ''''${${var}}'' ]) keepVars; - in depot.nix.writeExecline "empty-env" {} - (importas ++ [ "emptyenv" ] ++ export ++ [ "${pkgs.execline}/bin/exec" "$@" ]); + importas = pkgs.lib.concatMap (var: [ "importas" "-i" var var ]) keepVars; + # we have to explicitely call export here, because PATH is probably empty + export = pkgs.lib.concatMap (var: [ "${pkgs.execline}/bin/export" var ''''${${var}}'' ]) keepVars; + in + depot.nix.writeExecline "empty-env" { } + (importas ++ [ "emptyenv" ] ++ export ++ [ "${pkgs.execline}/bin/exec" "$@" ]); -in { +in +{ inherit debugExec eprint-stdin diff --git a/users/Profpatsch/netencode/default.nix b/users/Profpatsch/netencode/default.nix index 739bda3d78c9..d38925814832 100644 --- a/users/Profpatsch/netencode/default.nix +++ b/users/Profpatsch/netencode/default.nix @@ -1,31 +1,36 @@ { depot, pkgs, lib, ... }: let - netencode-rs = depot.nix.writers.rustSimpleLib { + netencode-rs = depot.nix.writers.rustSimpleLib + { name = "netencode"; dependencies = [ depot.third_party.rust-crates.nom depot.users.Profpatsch.execline.exec-helpers ]; - } (builtins.readFile ./netencode.rs); + } + (builtins.readFile ./netencode.rs); gen = import ./gen.nix { inherit lib; }; - pretty-rs = depot.nix.writers.rustSimpleLib { - name = "netencode-pretty"; - dependencies = [ - netencode-rs - ]; - } (builtins.readFile ./pretty.rs); + pretty-rs = depot.nix.writers.rustSimpleLib + { + name = "netencode-pretty"; + dependencies = [ + netencode-rs + ]; + } + (builtins.readFile ./pretty.rs); - pretty = depot.nix.writers.rustSimple { - name = "netencode-pretty"; - dependencies = [ - netencode-rs - pretty-rs - depot.users.Profpatsch.execline.exec-helpers - ]; - } '' + pretty = depot.nix.writers.rustSimple + { + name = "netencode-pretty"; + dependencies = [ + netencode-rs + pretty-rs + depot.users.Profpatsch.execline.exec-helpers + ]; + } '' extern crate netencode; extern crate netencode_pretty; extern crate exec_helpers; @@ -41,24 +46,27 @@ let } ''; - netencode-mustache = depot.nix.writers.rustSimple { - name = "netencode_mustache"; - dependencies = [ - depot.users.Profpatsch.arglib.netencode.rust - netencode-rs - depot.third_party.rust-crates.mustache - ]; - } (builtins.readFile ./netencode-mustache.rs); + netencode-mustache = depot.nix.writers.rustSimple + { + name = "netencode_mustache"; + dependencies = [ + depot.users.Profpatsch.arglib.netencode.rust + netencode-rs + depot.third_party.rust-crates.mustache + ]; + } + (builtins.readFile ./netencode-mustache.rs); - record-get = depot.nix.writers.rustSimple { - name = "record-get"; - dependencies = [ - netencode-rs - depot.users.Profpatsch.execline.exec-helpers - depot.users.Profpatsch.arglib.netencode.rust - ]; - } '' + record-get = depot.nix.writers.rustSimple + { + name = "record-get"; + dependencies = [ + netencode-rs + depot.users.Profpatsch.execline.exec-helpers + depot.users.Profpatsch.arglib.netencode.rust + ]; + } '' extern crate netencode; extern crate arglib_netencode; extern crate exec_helpers; @@ -80,13 +88,14 @@ let } ''; - record-splice-env = depot.nix.writers.rustSimple { - name = "record-splice-env"; - dependencies = [ - netencode-rs - depot.users.Profpatsch.execline.exec-helpers - ]; - } '' + record-splice-env = depot.nix.writers.rustSimple + { + name = "record-splice-env"; + dependencies = [ + netencode-rs + depot.users.Profpatsch.execline.exec-helpers + ]; + } '' extern crate netencode; extern crate exec_helpers; use netencode::dec::{Record, Try, ScalarAsBytes, Decoder, DecodeError}; @@ -109,13 +118,14 @@ let } ''; - env-splice-record = depot.nix.writers.rustSimple { - name = "env-splice-record"; - dependencies = [ - netencode-rs - depot.users.Profpatsch.execline.exec-helpers - ]; - } '' + env-splice-record = depot.nix.writers.rustSimple + { + name = "env-splice-record"; + dependencies = [ + netencode-rs + depot.users.Profpatsch.execline.exec-helpers + ]; + } '' extern crate netencode; extern crate exec_helpers; use netencode::{T}; @@ -135,7 +145,8 @@ let } ''; -in depot.nix.readTree.drvTargets { +in +depot.nix.readTree.drvTargets { inherit netencode-rs pretty-rs diff --git a/users/Profpatsch/netencode/gen.nix b/users/Profpatsch/netencode/gen.nix index 305ff7b08dd6..efc9629ca0df 100644 --- a/users/Profpatsch/netencode/gen.nix +++ b/users/Profpatsch/netencode/gen.nix @@ -27,29 +27,33 @@ let concatStrings = builtins.concatStringsSep ""; record = lokv: netstring "{" "}" - (concatStrings (map ({key, val}: tag key val) lokv)); + (concatStrings (map ({ key, val }: tag key val) lokv)); list = l: netstring "[" "]" (concatStrings l); dwim = val: - let match = { - "bool" = n1; - "int" = i6; - "string" = text; - "set" = attrs: - # it could be a derivation, then just return the path - if attrs.type or "" == "derivation" then text "${attrs}" - else - record (lib.mapAttrsToList - (k: v: { - key = k; - val = dwim v; - }) attrs); - "list" = l: list (map dwim l); - }; - in match.${builtins.typeOf val} val; + let + match = { + "bool" = n1; + "int" = i6; + "string" = text; + "set" = attrs: + # it could be a derivation, then just return the path + if attrs.type or "" == "derivation" then text "${attrs}" + else + record (lib.mapAttrsToList + (k: v: { + key = k; + val = dwim v; + }) + attrs); + "list" = l: list (map dwim l); + }; + in + match.${builtins.typeOf val} val; -in { +in +{ inherit unit n1 diff --git a/users/Profpatsch/netstring/default.nix b/users/Profpatsch/netstring/default.nix index b4990cae6766..e85cf24dd8e6 100644 --- a/users/Profpatsch/netstring/default.nix +++ b/users/Profpatsch/netstring/default.nix @@ -12,9 +12,10 @@ let (k: v: toNetstring (toNetstring k + toNetstring v)) attrs); - python-netstring = depot.users.Profpatsch.writers.python3Lib { - name = "netstring"; - } '' + python-netstring = depot.users.Profpatsch.writers.python3Lib + { + name = "netstring"; + } '' def read_netstring(bytes): (int_length, rest) = bytes.split(sep=b':', maxsplit=1) val = rest[:int(int_length)] @@ -39,9 +40,10 @@ let return res ''; - rust-netstring = depot.nix.writers.rustSimpleLib { - name = "netstring"; - } '' + rust-netstring = depot.nix.writers.rustSimpleLib + { + name = "netstring"; + } '' pub fn to_netstring(s: &[u8]) -> Vec { let len = s.len(); // length of the integer as ascii @@ -55,12 +57,13 @@ let } ''; -in depot.nix.readTree.drvTargets { +in +depot.nix.readTree.drvTargets { inherit toNetstring toNetstringList toNetstringKeyVal python-netstring rust-netstring - ; + ; } diff --git a/users/Profpatsch/netstring/tests/default.nix b/users/Profpatsch/netstring/tests/default.nix index 710ba3d30526..6a1062988f1e 100644 --- a/users/Profpatsch/netstring/tests/default.nix +++ b/users/Profpatsch/netstring/tests/default.nix @@ -2,12 +2,13 @@ let - python-netstring-test = depot.users.Profpatsch.writers.python3 { - name = "python-netstring-test"; - libraries = p: [ - depot.users.Profpatsch.netstring.python-netstring - ]; - } '' + python-netstring-test = depot.users.Profpatsch.writers.python3 + { + name = "python-netstring-test"; + libraries = p: [ + depot.users.Profpatsch.netstring.python-netstring + ]; + } '' import netstring def assEq(left, right): @@ -33,12 +34,13 @@ let ) ''; - rust-netstring-test = depot.nix.writers.rustSimple { - name = "rust-netstring-test"; - dependencies = [ - depot.users.Profpatsch.netstring.rust-netstring - ]; - } '' + rust-netstring-test = depot.nix.writers.rustSimple + { + name = "rust-netstring-test"; + dependencies = [ + depot.users.Profpatsch.netstring.rust-netstring + ]; + } '' extern crate netstring; fn main() { @@ -53,7 +55,8 @@ let } ''; -in depot.nix.readTree.drvTargets { +in +depot.nix.readTree.drvTargets { inherit python-netstring-test rust-netstring-test diff --git a/users/Profpatsch/nix-home/default.nix b/users/Profpatsch/nix-home/default.nix index cf9ab0d4d4ae..8f52055ade31 100644 --- a/users/Profpatsch/nix-home/default.nix +++ b/users/Profpatsch/nix-home/default.nix @@ -2,97 +2,145 @@ let bins = depot.nix.getBins pkgs.stow [ "stow" ] - // depot.nix.getBins pkgs.coreutils [ "mkdir" "ln" "printenv" "rm" ] - // depot.nix.getBins pkgs.xe [ "xe" ] - // depot.nix.getBins pkgs.lr [ "lr" ] - // depot.nix.getBins pkgs.nix [ "nix-store" ] - ; + // depot.nix.getBins pkgs.coreutils [ "mkdir" "ln" "printenv" "rm" ] + // depot.nix.getBins pkgs.xe [ "xe" ] + // depot.nix.getBins pkgs.lr [ "lr" ] + // depot.nix.getBins pkgs.nix [ "nix-store" ] + ; # run stow to populate the target directory with the given stow package, read from stowDir. # Bear in mind that `stowDirOriginPath` should always be semantically bound to the given `stowDir`, otherwise stow might become rather confused. - runStow = { - # “stow package” to stow (see manpage) - stowPackage, - # “target directory” to stow in (see manpage) - targetDir, - # The “stow directory” (see manpage), containing “stow packages” (see manpage) - stowDir, - # representative directory for the stowDir in the file system, against which stow will create relative links. - # ATTN: this is always overwritten with the contents of `stowDir`! You shouldn’t re-use the same `stowDirOriginPath` for different `stowDir`s, otherwise there might be surprises. - stowDirOriginPath, - }: depot.nix.writeExecline "stow-${stowPackage}" {} [ - # first, create a temporary stow directory to use as source - # (stow will use it to determine the origin of files) - "if" [ bins.mkdir "-p" stowDirOriginPath ] - # remove old symlinks - "if" [ - "pipeline" [ - bins.lr "-0" "-t" "depth == 1 && type == l" stowDirOriginPath + runStow = + { + # “stow package” to stow (see manpage) + stowPackage + , # “target directory” to stow in (see manpage) + targetDir + , # The “stow directory” (see manpage), containing “stow packages” (see manpage) + stowDir + , # representative directory for the stowDir in the file system, against which stow will create relative links. + # ATTN: this is always overwritten with the contents of `stowDir`! You shouldn’t re-use the same `stowDirOriginPath` for different `stowDir`s, otherwise there might be surprises. + stowDirOriginPath + , + }: depot.nix.writeExecline "stow-${stowPackage}" { } [ + # first, create a temporary stow directory to use as source + # (stow will use it to determine the origin of files) + "if" + [ bins.mkdir "-p" stowDirOriginPath ] + # remove old symlinks + "if" + [ + "pipeline" + [ + bins.lr + "-0" + "-t" + "depth == 1 && type == l" + stowDirOriginPath + ] + bins.xe + "-0" + bins.rm ] - bins.xe "-0" bins.rm - ] - # create an indirect gc root so our config is not cleaned under our asses by a garbage collect - "if" [ - bins.nix-store + # create an indirect gc root so our config is not cleaned under our asses by a garbage collect + "if" + [ + bins.nix-store "--realise" "--indirect" - "--add-root" "${stowDirOriginPath}/.nix-stowdir-gc-root" + "--add-root" + "${stowDirOriginPath}/.nix-stowdir-gc-root" stowDir - ] - # populate with new stow targets - "if" [ - "elglob" "-w0" "stowPackages" "${stowDir}/*" - bins.ln "--force" "-st" stowDirOriginPath "$stowPackages" - ] - # stow always looks for $HOME/.stowrc to read more arguments - "export" "HOME" "/homeless-shelter" - bins.stow + ] + # populate with new stow targets + "if" + [ + "elglob" + "-w0" + "stowPackages" + "${stowDir}/*" + bins.ln + "--force" + "-st" + stowDirOriginPath + "$stowPackages" + ] + # stow always looks for $HOME/.stowrc to read more arguments + "export" + "HOME" + "/homeless-shelter" + bins.stow # always run restow for now; this does more stat but will remove stale links "--restow" - "--dir" stowDirOriginPath - "--target" targetDir + "--dir" + stowDirOriginPath + "--target" + targetDir stowPackage - ]; + ]; # create a stow dir from a list of drv paths and a stow package name. makeStowDir = (with depot.nix.yants; - defun - [ (list (struct { + defun + [ + (list (struct { originalDir = drv; stowPackage = string; })) drv - ] ) - (dirs: - depot.nix.runExecline "make-stow-dir" { - stdin = lib.pipe dirs [ - (map depot.users.Profpatsch.netencode.gen.dwim) - depot.users.Profpatsch.netstring.toNetstringList - ]; - } [ - "importas" "out" "out" - "if" [ bins.mkdir "-p" "$out" ] - "forstdin" "-d" "" "-o" "0" "line" - "pipeline" [ - depot.users.Profpatsch.execline.print-one-env "line" - ] - depot.users.Profpatsch.netencode.record-splice-env - "importas" "-ui" "originalDir" "originalDir" - "importas" "-ui" "stowPackage" "stowPackage" - bins.ln "-sT" "$originalDir" "\${out}/\${stowPackage}" - ]); + ]) + (dirs: + depot.nix.runExecline "make-stow-dir" + { + stdin = lib.pipe dirs [ + (map depot.users.Profpatsch.netencode.gen.dwim) + depot.users.Profpatsch.netstring.toNetstringList + ]; + } [ + "importas" + "out" + "out" + "if" + [ bins.mkdir "-p" "$out" ] + "forstdin" + "-d" + "" + "-o" + "0" + "line" + "pipeline" + [ + depot.users.Profpatsch.execline.print-one-env + "line" + ] + depot.users.Profpatsch.netencode.record-splice-env + "importas" + "-ui" + "originalDir" + "originalDir" + "importas" + "-ui" + "stowPackage" + "stowPackage" + bins.ln + "-sT" + "$originalDir" + "\${out}/\${stowPackage}" + ]); in # TODO: temp setup -lib.pipe {} [ +lib.pipe { } [ (_: makeStowDir [{ stowPackage = "scripts"; originalDir = pkgs.linkFarm "scripts-farm" [ - { name = "scripts/ytextr"; - path = depot.users.Profpatsch.ytextr; } - ]; + { + name = "scripts/ytextr"; + path = depot.users.Profpatsch.ytextr; + } + ]; }]) (d: runStow { stowDir = d; diff --git a/users/Profpatsch/nixpkgs-rewriter/default.nix b/users/Profpatsch/nixpkgs-rewriter/default.nix index 787162d4973a..0740a870aa4a 100644 --- a/users/Profpatsch/nixpkgs-rewriter/default.nix +++ b/users/Profpatsch/nixpkgs-rewriter/default.nix @@ -8,12 +8,12 @@ let ; bins = depot.nix.getBins pkgs.coreutils [ "head" "shuf" ] - // depot.nix.getBins pkgs.jq [ "jq" ] - // depot.nix.getBins pkgs.findutils [ "xargs" ] - // depot.nix.getBins pkgs.gnused [ "sed" ] - ; + // depot.nix.getBins pkgs.jq [ "jq" ] + // depot.nix.getBins pkgs.findutils [ "xargs" ] + // depot.nix.getBins pkgs.gnused [ "sed" ] + ; - export-json-object = pkgs.writers.writePython3 "export-json-object" {} '' + export-json-object = pkgs.writers.writePython3 "export-json-object" { } '' import json import sys import os @@ -29,34 +29,50 @@ let os.execvp(sys.argv[1], sys.argv[1:]) ''; - meta-stdenv-lib = pkgs.writers.writeHaskell "meta-stdenv-lib" { - libraries = [ - pkgs.haskellPackages.hnix - pkgs.haskellPackages.aeson - ]; - } ./MetaStdenvLib.hs; + meta-stdenv-lib = pkgs.writers.writeHaskell "meta-stdenv-lib" + { + libraries = [ + pkgs.haskellPackages.hnix + pkgs.haskellPackages.aeson + ]; + } ./MetaStdenvLib.hs; replace-between-lines = writeExecline "replace-between-lines" { readNArgs = 1; } [ - "importas" "-ui" "file" "fileName" - "importas" "-ui" "from" "fromLine" - "importas" "-ui" "to" "toLine" - "if" [ depot.tools.eprintf "%s-%s\n" "$from" "$to" ] + "importas" + "-ui" + "file" + "fileName" + "importas" + "-ui" + "from" + "fromLine" + "importas" + "-ui" + "to" + "toLine" + "if" + [ depot.tools.eprintf "%s-%s\n" "$from" "$to" ] (debugExec "adding lib") bins.sed - "-e" "\${from},\${to} \${1}" - "-i" "$file" + "-e" + "\${from},\${to} \${1}" + "-i" + "$file" ]; add-lib-if-necessary = writeExecline "add-lib-if-necessary" { readNArgs = 1; } [ - "pipeline" [ meta-stdenv-lib "$1" ] - export-json-object - # first replace any stdenv.lib mentions in the arg header - # if this is not done, the replace below kills these. - # Since we want it anyway ultimately, let’s do it here. - "if" [ replace-between-lines "s/stdenv\.lib/lib/" ] - # then add the lib argument - # (has to be before stdenv, otherwise default arguments might be in the way) - replace-between-lines "s/stdenv/lib, stdenv/" + "pipeline" + [ meta-stdenv-lib "$1" ] + export-json-object + # first replace any stdenv.lib mentions in the arg header + # if this is not done, the replace below kills these. + # Since we want it anyway ultimately, let’s do it here. + "if" + [ replace-between-lines "s/stdenv\.lib/lib/" ] + # then add the lib argument + # (has to be before stdenv, otherwise default arguments might be in the way) + replace-between-lines + "s/stdenv/lib, stdenv/" ]; metaString = ''meta = with stdenv.lib; {''; @@ -80,33 +96,53 @@ let ''; instantiate-nixpkgs-randomly = writeExecline "instantiate-nixpkgs-randomly" { readNArgs = 1; } [ - "export" "NIXPKGS_ALLOW_BROKEN" "1" - "export" "NIXPKGS_ALLOW_UNFREE" "1" - "export" "NIXPKGS_ALLOW_INSECURE" "1" - "export" "NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM" "1" - "pipeline" [ + "export" + "NIXPKGS_ALLOW_BROKEN" + "1" + "export" + "NIXPKGS_ALLOW_UNFREE" + "1" + "export" + "NIXPKGS_ALLOW_INSECURE" + "1" + "export" + "NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM" + "1" + "pipeline" + [ "nix" - "eval" - "--raw" - ''( + "eval" + "--raw" + ''( let pkgs = import ''${1} {}; in builtins.toJSON (builtins.attrNames pkgs) )'' ] - "pipeline" [ bins.jq "-r" ".[]" ] - "pipeline" [ bins.shuf ] - "pipeline" [ bins.head "-n" "1000" ] - bins.xargs "-I" "{}" "-n1" - "if" [ depot.tools.eprintf "instantiating %s\n" "{}" ] - "nix-instantiate" "$1" "-A" "{}" + "pipeline" + [ bins.jq "-r" ".[]" ] + "pipeline" + [ bins.shuf ] + "pipeline" + [ bins.head "-n" "1000" ] + bins.xargs + "-I" + "{}" + "-n1" + "if" + [ depot.tools.eprintf "instantiating %s\n" "{}" ] + "nix-instantiate" + "$1" + "-A" + "{}" ]; -in depot.nix.readTree.drvTargets { +in +depot.nix.readTree.drvTargets { inherit - instantiate-nixpkgs-randomly - # requires hnix, which we don’t want in tvl for now - # uncomment manually if you want to use it. - # meta-stdenv-lib - # replace-stdenv-lib + instantiate-nixpkgs-randomly + # requires hnix, which we don’t want in tvl for now + # uncomment manually if you want to use it. + # meta-stdenv-lib + # replace-stdenv-lib ; } diff --git a/users/Profpatsch/read-http.nix b/users/Profpatsch/read-http.nix index 854a11b7d099..d9ad6fc30d94 100644 --- a/users/Profpatsch/read-http.nix +++ b/users/Profpatsch/read-http.nix @@ -2,15 +2,18 @@ let - read-http = depot.nix.writers.rustSimple { - name = "read-http"; - dependencies = [ - depot.third_party.rust-crates.ascii - depot.third_party.rust-crates.httparse - depot.users.Profpatsch.netencode.netencode-rs - depot.users.Profpatsch.arglib.netencode.rust - depot.users.Profpatsch.execline.exec-helpers - ]; - } (builtins.readFile ./read-http.rs); + read-http = depot.nix.writers.rustSimple + { + name = "read-http"; + dependencies = [ + depot.third_party.rust-crates.ascii + depot.third_party.rust-crates.httparse + depot.users.Profpatsch.netencode.netencode-rs + depot.users.Profpatsch.arglib.netencode.rust + depot.users.Profpatsch.execline.exec-helpers + ]; + } + (builtins.readFile ./read-http.rs); -in read-http +in +read-http diff --git a/users/Profpatsch/reverse-haskell-deps.nix b/users/Profpatsch/reverse-haskell-deps.nix index b47347ea9fea..6df7bc6329cd 100644 --- a/users/Profpatsch/reverse-haskell-deps.nix +++ b/users/Profpatsch/reverse-haskell-deps.nix @@ -5,22 +5,27 @@ let - rev = depot.nix.writeExecline "reverse-haskell-deps" {} [ - "pipeline" [ - "${pkgs.curl}/bin/curl" "-L" "https://packdeps.haskellers.com/reverse" + rev = depot.nix.writeExecline "reverse-haskell-deps" { } [ + "pipeline" + [ + "${pkgs.curl}/bin/curl" + "-L" + "https://packdeps.haskellers.com/reverse" ] rev-hs ]; - rev-hs = pkgs.writers.writeHaskell "revers-haskell-deps-hs" { - libraries = [ - pkgs.haskellPackages.nicify-lib - pkgs.haskellPackages.tagsoup - ]; + rev-hs = pkgs.writers.writeHaskell "revers-haskell-deps-hs" + { + libraries = [ + pkgs.haskellPackages.nicify-lib + pkgs.haskellPackages.tagsoup + ]; - } + } ./reverse-haskell-deps.hs; -in rev +in +rev diff --git a/users/Profpatsch/struct-edit/default.nix b/users/Profpatsch/struct-edit/default.nix index 970cdd4d028b..11a7200ce427 100644 --- a/users/Profpatsch/struct-edit/default.nix +++ b/users/Profpatsch/struct-edit/default.nix @@ -1,13 +1,13 @@ { depot, ... }: depot.nix.buildGo.program { - name = "struct-edit"; - srcs = [ - ./main.go - ]; - deps = [ - depot.third_party.gopkgs."github.com".charmbracelet.bubbletea - depot.third_party.gopkgs."github.com".charmbracelet.lipgloss - depot.third_party.gopkgs."github.com".muesli.termenv - depot.third_party.gopkgs."github.com".mattn.go-isatty - ]; + name = "struct-edit"; + srcs = [ + ./main.go + ]; + deps = [ + depot.third_party.gopkgs."github.com".charmbracelet.bubbletea + depot.third_party.gopkgs."github.com".charmbracelet.lipgloss + depot.third_party.gopkgs."github.com".muesli.termenv + depot.third_party.gopkgs."github.com".mattn.go-isatty + ]; } diff --git a/users/Profpatsch/tree-sitter.nix b/users/Profpatsch/tree-sitter.nix index 4f81b8e7a77c..2224da2a3b8c 100644 --- a/users/Profpatsch/tree-sitter.nix +++ b/users/Profpatsch/tree-sitter.nix @@ -2,17 +2,18 @@ let bins = depot.nix.getBins pkgs.coreutils [ "head" "printf" "cat" ] - // depot.nix.getBins pkgs.ncurses [ "tput" ] - // depot.nix.getBins pkgs.bc [ "bc" ] - // depot.nix.getBins pkgs.ocamlPackages.sexp [ "sexp" ]; - - print-ast = depot.nix.writers.rustSimple { - name = "print-ast"; - dependencies = with depot.third_party.rust-crates; [ - libloading - tree-sitter - ]; - } '' + // depot.nix.getBins pkgs.ncurses [ "tput" ] + // depot.nix.getBins pkgs.bc [ "bc" ] + // depot.nix.getBins pkgs.ocamlPackages.sexp [ "sexp" ]; + + print-ast = depot.nix.writers.rustSimple + { + name = "print-ast"; + dependencies = with depot.third_party.rust-crates; [ + libloading + tree-sitter + ]; + } '' extern crate libloading; extern crate tree_sitter; use std::mem; @@ -58,13 +59,14 @@ let }; }; - watch-file-modified = depot.nix.writers.rustSimple { - name = "watch-file-modified"; - dependencies = [ - depot.third_party.rust-crates.inotify - depot.users.Profpatsch.netstring.rust-netstring - ]; - } '' + watch-file-modified = depot.nix.writers.rustSimple + { + name = "watch-file-modified"; + dependencies = [ + depot.third_party.rust-crates.inotify + depot.users.Profpatsch.netstring.rust-netstring + ]; + } '' extern crate inotify; extern crate netstring; use inotify::{EventMask, WatchMask, Inotify}; @@ -101,75 +103,103 @@ let ''; # clear screen and set LINES and COLUMNS to terminal height & width - clear-screen = depot.nix.writeExecline "clear-screen" {} [ - "if" [ bins.tput "clear" ] - "backtick" "-in" "LINES" [ bins.tput "lines" ] - "backtick" "-in" "COLUMNS" [ bins.tput "cols" ] + clear-screen = depot.nix.writeExecline "clear-screen" { } [ + "if" + [ bins.tput "clear" ] + "backtick" + "-in" + "LINES" + [ bins.tput "lines" ] + "backtick" + "-in" + "COLUMNS" + [ bins.tput "cols" ] "$@" ]; print-nix-file = depot.nix.writeExecline "print-nix-file" { readNArgs = 1; } [ - "pipeline" [ print-ast "${tree-sitter-nix}/parser" "tree_sitter_nix" "$1" ] - "pipeline" [ bins.sexp "print" ] + "pipeline" + [ print-ast "${tree-sitter-nix}/parser" "tree_sitter_nix" "$1" ] + "pipeline" + [ bins.sexp "print" ] clear-screen - "importas" "-ui" "lines" "LINES" - "backtick" "-in" "ls" [ + "importas" + "-ui" + "lines" + "LINES" + "backtick" + "-in" + "ls" + [ "pipeline" - # when you pull out bc to decrement an integer it’s time to switch to python lol - [ bins.printf "x=%s; --x\n" "$lines" ] - bins.bc + # when you pull out bc to decrement an integer it’s time to switch to python lol + [ bins.printf "x=%s; --x\n" "$lines" ] + bins.bc ] - "importas" "-ui" "l" "ls" - bins.head "-n\${l}" + "importas" + "-ui" + "l" + "ls" + bins.head + "-n\${l}" ]; print-nix-file-on-update = depot.nix.writeExecline "print-nix-file-on-update" { readNArgs = 1; } [ - "if" [ print-nix-file "$1" ] - "pipeline" [ watch-file-modified "$1" ] - "forstdin" "-d" "" "file" - "importas" "file" "file" - print-nix-file "$file" + "if" + [ print-nix-file "$1" ] + "pipeline" + [ watch-file-modified "$1" ] + "forstdin" + "-d" + "" + "file" + "importas" + "file" + "file" + print-nix-file + "$file" ]; # copied from nixpkgs buildTreeSitterGrammar = - { - # language name - language - # source for the language grammar - , source - }: - - pkgs.stdenv.mkDerivation { - - pname = "${language}-grammar"; - inherit (pkgs.tree-sitter) version; - - src = source; - - buildInputs = [ pkgs.tree-sitter ]; - - dontUnpack = true; - configurePhase= ":"; - buildPhase = '' - runHook preBuild - scanner_cc="$src/src/scanner.cc" - if [ ! -f "$scanner_cc" ]; then - scanner_cc="" - fi - $CXX -I$src/src/ -c $scanner_cc - $CC -I$src/src/ -shared -o parser -Os scanner.o $src/src/parser.c -lstdc++ - runHook postBuild - ''; - installPhase = '' - runHook preInstall - mkdir $out - mv parser $out/ - runHook postInstall - ''; - }; - -in depot.nix.readTree.drvTargets { + { + # language name + language + # source for the language grammar + , source + }: + + pkgs.stdenv.mkDerivation { + + pname = "${language}-grammar"; + inherit (pkgs.tree-sitter) version; + + src = source; + + buildInputs = [ pkgs.tree-sitter ]; + + dontUnpack = true; + configurePhase = ":"; + buildPhase = '' + runHook preBuild + scanner_cc="$src/src/scanner.cc" + if [ ! -f "$scanner_cc" ]; then + scanner_cc="" + fi + $CXX -I$src/src/ -c $scanner_cc + $CC -I$src/src/ -shared -o parser -Os scanner.o $src/src/parser.c -lstdc++ + runHook postBuild + ''; + installPhase = '' + runHook preInstall + mkdir $out + mv parser $out/ + runHook postInstall + ''; + }; + +in +depot.nix.readTree.drvTargets { inherit print-ast tree-sitter-nix diff --git a/users/Profpatsch/writers/default.nix b/users/Profpatsch/writers/default.nix index 3151a9d3bd44..02f39da02dbe 100644 --- a/users/Profpatsch/writers/default.nix +++ b/users/Profpatsch/writers/default.nix @@ -1,7 +1,7 @@ { depot, pkgs, lib, ... }: let - bins = depot.nix.getBins pkgs.s6-portable-utils ["s6-mkdir" "s6-cat" "s6-ln" "s6-ls" "s6-touch" ] - // depot.nix.getBins pkgs.coreutils ["printf" ]; + bins = depot.nix.getBins pkgs.s6-portable-utils [ "s6-mkdir" "s6-cat" "s6-ln" "s6-ls" "s6-touch" ] + // depot.nix.getBins pkgs.coreutils [ "printf" ]; inherit (depot.nix.yants) defun struct restrict attrs list string drv any; @@ -11,56 +11,76 @@ let restrict "flake error" (s: lib.any (prefix: (builtins.substring 0 1 s) == prefix) - [ "E" "W" ]) + [ "E" "W" ]) string; Libraries = defun [ (attrs any) (list drv) ]; - python3 = { - name, - libraries ? (_: []), - flakeIgnore ? [] - }: pkgs.writers.writePython3 name { - libraries = Libraries libraries pkgs.python3Packages; - flakeIgnore = - let ignoreTheseErrors = [ - # whitespace after { - "E201" - # whitespace before } - "E202" - # fuck 4-space indentation - "E121" "E111" - # who cares about blank lines … - # … at end of files - "W391" - # … between functions - "E302" "E305" - ]; - in list FlakeError (ignoreTheseErrors ++ flakeIgnore); - }; + python3 = + { name + , libraries ? (_: [ ]) + , flakeIgnore ? [ ] + }: pkgs.writers.writePython3 name { + libraries = Libraries libraries pkgs.python3Packages; + flakeIgnore = + let + ignoreTheseErrors = [ + # whitespace after { + "E201" + # whitespace before } + "E202" + # fuck 4-space indentation + "E121" + "E111" + # who cares about blank lines … + # … at end of files + "W391" + # … between functions + "E302" + "E305" + ]; + in + list FlakeError (ignoreTheseErrors ++ flakeIgnore); + }; # TODO: add the same flake check as the pyhon3 writer - python3Lib = { name, libraries ? (_: []) }: moduleString: - let srcTree = depot.nix.runExecline.local name { stdin = moduleString; } [ - "importas" "out" "out" - "if" [ bins.s6-mkdir "-p" "\${out}/${name}" ] - "if" [ - "redirfd" "-w" "1" "\${out}/setup.py" - bins.printf '' - from distutils.core import setup + python3Lib = { name, libraries ? (_: [ ]) }: moduleString: + let + srcTree = depot.nix.runExecline.local name { stdin = moduleString; } [ + "importas" + "out" + "out" + "if" + [ bins.s6-mkdir "-p" "\${out}/${name}" ] + "if" + [ + "redirfd" + "-w" + "1" + "\${out}/setup.py" + bins.printf + '' + from distutils.core import setup - setup( - name='%s', - packages=['%s'] - ) - '' name name - ] - "if" [ - # redirect stdin to the init py - "redirfd" "-w" "1" "\${out}/${name}/__init__.py" - bins.s6-cat - ] - ]; - in pkgs.python3Packages.buildPythonPackage { + setup( + name='%s', + packages=['%s'] + ) + '' + name + name + ] + "if" + [ + # redirect stdin to the init py + "redirfd" + "-w" + "1" + "\${out}/${name}/__init__.py" + bins.s6-cat + ] + ]; + in + pkgs.python3Packages.buildPythonPackage { inherit name; src = srcTree; propagatedBuildInputs = libraries pkgs.python3Packages; @@ -68,7 +88,8 @@ let }; -in { +in +{ inherit python3 python3Lib diff --git a/users/Profpatsch/writers/tests/default.nix b/users/Profpatsch/writers/tests/default.nix index dc760af9e16e..d0d62d3b0e1b 100644 --- a/users/Profpatsch/writers/tests/default.nix +++ b/users/Profpatsch/writers/tests/default.nix @@ -10,38 +10,46 @@ let coreutils ; - run = drv: depot.nix.runExecline.local "run-${drv.name}" {} [ - "if" [ drv ] - "importas" "out" "out" - "${coreutils}/bin/touch" "$out" + run = drv: depot.nix.runExecline.local "run-${drv.name}" { } [ + "if" + [ drv ] + "importas" + "out" + "out" + "${coreutils}/bin/touch" + "$out" ]; - pythonTransitiveLib = python3Lib { - name = "transitive"; - } '' + pythonTransitiveLib = python3Lib + { + name = "transitive"; + } '' def transitive(s): return s + " 1 2 3" ''; - pythonTestLib = python3Lib { - name = "test_lib"; - libraries = _: [ pythonTransitiveLib ]; - } '' + pythonTestLib = python3Lib + { + name = "test_lib"; + libraries = _: [ pythonTransitiveLib ]; + } '' import transitive def test(): return transitive.transitive("test") ''; - pythonWithLib = run (python3 { - name = "python-with-lib"; - libraries = _: [ pythonTestLib ]; - } '' + pythonWithLib = run (python3 + { + name = "python-with-lib"; + libraries = _: [ pythonTestLib ]; + } '' import test_lib assert(test_lib.test() == "test 1 2 3") ''); -in depot.nix.readTree.drvTargets { +in +depot.nix.readTree.drvTargets { inherit pythonWithLib ; diff --git a/users/Profpatsch/ytextr/create-symlink-farm.nix b/users/Profpatsch/ytextr/create-symlink-farm.nix index 583a3a90f5c5..7b3a45b91681 100644 --- a/users/Profpatsch/ytextr/create-symlink-farm.nix +++ b/users/Profpatsch/ytextr/create-symlink-farm.nix @@ -1,9 +1,10 @@ { # list of package attribute names to get at run time - packageNamesAtRuntimeJsonPath, + packageNamesAtRuntimeJsonPath +, }: let - pkgs = import {}; + pkgs = import { }; getPkg = pkgName: pkgs.${pkgName}; @@ -12,7 +13,7 @@ let runtime = map getPkg packageNamesAtRuntime; in - pkgs.symlinkJoin { - name = "symlink-farm"; - paths = runtime; - } +pkgs.symlinkJoin { + name = "symlink-farm"; + paths = runtime; +} diff --git a/users/Profpatsch/ytextr/default.nix b/users/Profpatsch/ytextr/default.nix index dba6bbb8b400..ac630603b90c 100644 --- a/users/Profpatsch/ytextr/default.nix +++ b/users/Profpatsch/ytextr/default.nix @@ -12,48 +12,71 @@ let bins = depot.nix.getBins pkgs.nix [ "nix-build" ] - // depot.nix.getBins pkgs.bubblewrap [ "bwrap" ]; + // depot.nix.getBins pkgs.bubblewrap [ "bwrap" ]; # Run a command, with the given packages in scope, and `packageNamesAtRuntime` being fetched at the start in the given nix `channel`. - nix-run-with-channel = { - # The channel to get `packageNamesAtRuntime` from - channel, - # executable to run with `packageNamesAtRuntime` in PATH - # and the argv - executable, - # A list of nixpkgs package attribute names that should be put into PATH when running `command`. - packageNamesAtRuntime, - }: depot.nix.writeExecline "nix-run-with-channel-${channel}" {} [ - # TODO: prevent race condition by writing a temporary gc root - "backtick" "-iE" "storepath" [ - bins.nix-build - "-I" "nixpkgs=channel:${channel}" + nix-run-with-channel = + { + # The channel to get `packageNamesAtRuntime` from + channel + , # executable to run with `packageNamesAtRuntime` in PATH + # and the argv + executable + , # A list of nixpkgs package attribute names that should be put into PATH when running `command`. + packageNamesAtRuntime + , + }: depot.nix.writeExecline "nix-run-with-channel-${channel}" { } [ + # TODO: prevent race condition by writing a temporary gc root + "backtick" + "-iE" + "storepath" + [ + bins.nix-build + "-I" + "nixpkgs=channel:${channel}" "--arg" - "packageNamesAtRuntimeJsonPath" - (pkgs.writeText "packageNamesAtRuntime.json" (builtins.toJSON packageNamesAtRuntime)) + "packageNamesAtRuntimeJsonPath" + (pkgs.writeText "packageNamesAtRuntime.json" (builtins.toJSON packageNamesAtRuntime)) ./create-symlink-farm.nix - ] - "importas" "-ui" "PATH" "PATH" - "export" "PATH" "\${storepath}/bin:\${PATH}" - executable "$@" - ]; + ] + "importas" + "-ui" + "PATH" + "PATH" + "export" + "PATH" + "\${storepath}/bin:\${PATH}" + executable + "$@" + ]; -in nix-run-with-channel { +in +nix-run-with-channel { channel = "nixos-unstable"; packageNamesAtRuntime = [ "yt-dlp" ]; executable = depot.nix.writeExecline "ytextr" { readNArgs = 1; } [ - "getcwd" "-E" "cwd" + "getcwd" + "-E" + "cwd" bins.bwrap - "--ro-bind" "/nix/store" "/nix/store" - "--ro-bind" "/etc" "/etc" - "--bind" "$cwd" "$cwd" - "yt-dlp" - "--no-playlist" - "--write-sub" - "--all-subs" - "--embed-subs" - "--merge-output-format" "mkv" - "-f" "bestvideo[height<=?1080]+bestaudio/best" - "$1" + "--ro-bind" + "/nix/store" + "/nix/store" + "--ro-bind" + "/etc" + "/etc" + "--bind" + "$cwd" + "$cwd" + "yt-dlp" + "--no-playlist" + "--write-sub" + "--all-subs" + "--embed-subs" + "--merge-output-format" + "mkv" + "-f" + "bestvideo[height<=?1080]+bestaudio/best" + "$1" ]; } -- cgit 1.4.1