{
  description = "jelqd, a roguelike played entirely over HTTP";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

  outputs =
    { self, nixpkgs }:
    let
      inherit (nixpkgs) lib;
      systems = [
        "x86_64-linux"
        "aarch64-linux"
        "x86_64-darwin"
        "aarch64-darwin"
      ];
      pkgsFor = lib.genAttrs systems (system: nixpkgs.legacyPackages.${system});
      forAllSystems = f: lib.genAttrs systems (system: f pkgsFor.${system});

      src = lib.fileset.toSource {
        root = ./.;
        fileset = lib.fileset.unions [
          ./Cargo.toml
          ./Cargo.lock
          ./src
          ./tests
        ];
      };
    in
    {
      packages = forAllSystems (pkgs: {
        default = pkgs.rustPlatform.buildRustPackage {
          pname = "jelqd";
          version = "0.6.9";
          inherit src;
          cargoLock.lockFile = ./Cargo.lock;
          meta.mainProgram = "jelqd";
        };
      });

      apps = forAllSystems (pkgs: {
        default = {
          type = "app";
          program = lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.default;
          meta.description = "Run the jelqd server";
        };
      });

      checks = forAllSystems (
        pkgs:
        let
          jelqd = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
        in
        {
          inherit jelqd;
          clippy = jelqd.overrideAttrs (old: {
            pname = "jelqd-clippy";
            nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.clippy ];
            buildPhase = "cargo clippy --offline --all-targets -- --deny warnings";
            doCheck = false;
            installPhase = "touch $out";
          });
          fmt =
            pkgs.runCommand "jelqd-fmt"
              {
                nativeBuildInputs = [
                  pkgs.cargo
                  pkgs.rustfmt
                ];
              }
              ''
                cd ${src}
                cargo fmt --check
                touch $out
              '';
        }
      );

      devShells = forAllSystems (pkgs: {
        default = pkgs.mkShell {
          inputsFrom = [ self.packages.${pkgs.stdenv.hostPlatform.system}.default ];
          packages = [
            pkgs.clippy
            pkgs.rustfmt
            pkgs.rust-analyzer
            pkgs.nushell
            pkgs.curl
          ];
        };
      });

      formatter = forAllSystems (pkgs: pkgs.nixfmt);
    };
}
