No description
Find a file
sterni 93a746aaaa feat(web/bubblegum): nix CGI programming framework
So here is what has been keeping me up at night: At some point I
realized that nix actually made a somewhat passable language for CGI
programming:

* That `builtins.getEnv` exists as one of the impurities of Nix is
  perfect as environment variables are the main way of communication
  from the web server to the CGI application.

* We can actually read from the filesystem via builtins.readDir and
  builtins.readFile with bearable overhead if we avoid importing the
  used paths into the nix store.

* Templating and routing are convenient to implement via indented strings
  and attribute sets respectively.

Of course there are obvious limitation:

* The overhead of derivations is probably much to great for them to be
  useful via IfD.

* Even without derivations, nix evaluation is very slow to the point
  were a trivial application takes between 100ms and 400ms to produce a
  response.

* We can't really cause effects other than producing a response which
  makes it not viable for a lot of applications. There are some ways
  around this:

  * With a custom interpreter we could have streaming and multiplexed
    I/O (using lazy lists emulated via attrsets) to cause such effects,
    but it would probably perform terribly.

  * We can use builtins.fetchurl to call other HTTP-based microservices,
    but only in very limited constraints, i. e. only GET, no headers,
    and only if the tarball ttl is set to 0 in the global nix.conf.

* Terrible error handling capabilities because builtins.tryEval actually
  doesn't catch a lot of errors.

To prove that it actually works, there are some demo applications,
which I invite you to run and potentially break horribly:

    nix-build -A web.bubblegum.examples && ./result
    # navigate to http://localhost:9000

The setup uses thttpd and executes the nix CGI scripts using
users.sterni.nint which automatically passed `depot`, so they can
import the cgi library.

Change-Id: I3a22a749612211627e5f8301c31ec2e7a872812c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2746
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
2021-04-01 18:50:36 +00:00
bin chore(3p): Clean up unused third-party packages 2021-03-25 18:37:33 +00:00
docs docs(REVIEWS): Update example commit for adding a new user 2021-03-27 00:51:04 +00:00
fun fix(clbot): Avoid pinging users for their own user folder CLs 2021-03-28 01:21:42 +00:00
lisp feat(klatre): support offsets in format-dottime 2021-01-25 20:09:21 +00:00
net chore(net): Remove mushroom 2020-08-26 22:21:10 +00:00
nix feat(nix/buildManPages): infra for generating man page dirs from nix 2021-03-31 23:06:10 +00:00
ops feat(ops/nixos/www): Serve rendered Tvix component SVG (hack!) 2021-03-31 23:10:54 +00:00
third_party feat(web/bubblegum): nix CGI programming framework 2021-04-01 18:50:36 +00:00
tools feat(cheddar): Set front_matter_delimiter = '---' extension 2021-03-31 22:20:49 +00:00
tvix chore(tvix): Make docs multi output 2021-03-31 22:41:07 +00:00
users feat(sterni/nint): shebang interpreter for nix scripts 2021-04-01 18:50:36 +00:00
web feat(web/bubblegum): nix CGI programming framework 2021-04-01 18:50:36 +00:00
.envrc chore: Unfuck NIX_PATH in the .envrc 2020-06-15 16:50:44 +00:00
.git-blame-ignore-revs chore: Add an ignoreRevsFile for git blame 2020-05-19 22:18:53 +01:00
.gitignore chore(gitignore): Ignore garbage/ folder 2019-12-20 20:05:40 +00:00
.hgignore chore(hgignore): ignore .git for hg 2020-06-14 18:23:13 +00:00
.mailmap chore(mailmap): add my name to mailmap 2020-07-18 18:15:05 +00:00
.rgignore chore: Only exclude //third_party/git from ripgrep 2020-05-17 23:58:22 +01:00
.rustfmt.toml feat: Add rustfmt configuration for the whole depot 2020-08-02 21:57:35 +00:00
buf.yaml feat(buf.yaml): add protobuf linter config 2020-07-17 20:01:29 +00:00
default.nix fix(tvix): Add //tvix to readTree roots 2021-03-31 19:23:39 +00:00
LICENSE chore: Keep project root under MIT license 2019-06-28 22:56:48 +01:00
OWNERS feat: Configure OWNERS file for the depot root 2020-06-14 15:41:55 +00:00
README.md revert(web/tvl): Revert 's/The V/tazjin's v/"' 2021-03-31 19:21:04 +00:00
RULES docs: Add the RULE 2020-08-06 00:23:13 +00:00

depot

Build status

This repository is the monorepo for the community around The Virus Lounge, containing our personal tools and infrastructure. Everything in here is built using Nix.

A large portion of the software here is very self-referential, meaning that it exists to sustain the operation of the repository. This is the case because we partially see this as an experiment in tooling for monorepos.

If you've ended up here and have no idea who I am, feel free to follow me on Twitter.

Highlights

Services

  • Source code is available primarily through Sourcegraph on cs.tvl.fyi, where it is searchable and even semantically indexed. A lower-tech view of the repository is also available via cgit on code.tvl.fyi.

    The repository can be cloned using git from https://cl.tvl.fyi/depot.

  • All code in the depot, with the exception of code that is checked in to individual //users folders, needs to be reviewed. We use Gerrit on cl.tvl.fyi for this.

  • Issues are tracked via our own issue tracker on b.tvl.fyi. Its source code lives at //web/panettone/.

  • Smaller todo-list entries which do not warrant a separate issue are listed at todo.tvl.fyi.

  • We use Buildkite for CI. Recent builds are listed on tvl.fyi/builds and pipelines are configured dynamically via //ops/pipelines.

All services that we host are deployed on NixOS machines that we manage. Their configuration is tracked in //ops/nixos.

Nix

  • //third_party/nix contains Tvix, our fork of the Nix package manager
  • //nix/readTree contains the Nix code which automatically registers projects in our Nix attribute hierarchy based on their in-tree location
  • //nix/yants contains Yet Another Nix Type System, which we use for a variety of things throughout the repository
  • //nix/buildGo implements a Nix library that can build Go software in the style of Bazel's rules_go. Go programs in this repository are built using this library.
  • //nix/buildLisp implements a Nix library that can build Common Lisp software. Currently only SBCL is supported. Lisp programs in this repository are built using this library.

We have a variety of other tools and libraries in the //nix folder which may be of interest.

Packages / Libraries

  • //net/alcoholic_jwt contains an easy-to-use JWT-validation library for Rust
  • //net/crimp contains a high-level HTTP client using cURL for Rust
  • //tools/emacs-pkgs contains various useful Emacs libraries, for example:
    • dottime.el provides dottime in the Emacs modeline
    • nix-util.el provides editing utilities for Nix files
    • term-switcher.el is an ivy-function for switching between vterm buffers
    • tvl.el provides helper functions for interacting with the TVL monorepo
  • //lisp/klatre provides a grab-bag utility library for Common Lisp

User packages

Contributors to the repository have user directories under //users, which can be used for personal or experimental code that does not require review.

Some examples:

  • //users/tazjin/homepage && //users/tazjin/blog: A Nix-based static site generator which generates the web page and Atom feed for tazj.in
  • //users/tazjin/finito: A persistent finite-state machine library for Rust.
  • //users/glittershark/xanthous: A (WIP) TUI RPG, written in Haskell.
  • //users/tazjin/emacs: tazjin's Emacs & EXWM configuration

Licensing

Unless otherwise stated in a subdirectory, all code is licensed under the MIT license. See LICENSE for details.

Contributing

If you'd like to contribute to any of the tools in here, please check out the contribution guidelines and our code of conduct.