{
  description = "felschr's CV";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    typix = {
      url = "github:loqusion/typix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    typst-packages = {
      url = "github:typst/packages";
      flake = false;
    };
  };

  outputs =
    inputs:
    inputs.flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = import inputs.nixpkgs { inherit system; };
        inherit (pkgs) lib;

        typixLib = inputs.typix.lib.${system};

        typstPackagesSrc = "${inputs.typst-packages}/packages";
        typstPackagesCache = pkgs.stdenvNoCC.mkDerivation {
          name = "typst-packages-cache";
          src = typstPackagesSrc;
          dontBuild = true;
          installPhase = ''
            mkdir -p "$out/typst/packages"
            cp -LR --reflink=auto --no-preserve=mode -t "$out/typst/packages" "$src"/*
          '';
        };

        src = lib.fileset.toSource {
          root = ./.;
          fileset = lib.fileset.unions [
            (lib.fileset.fromSource (typixLib.cleanTypstSource ./.))
            ./src/info.toml
            # ./src/signature.svg
          ];
        };
        commonArgs = {
          typstSource = "src/main.typ";
          typstOutput = "out/main.pdf";

          fontPaths = [
            "${pkgs.work-sans}/share/fonts/opentype"
          ];

          virtualPaths = [ ];
        };

        commonBuildArgs = commonArgs // {
          XDG_CACHE_HOME = typstPackagesCache;
        };

        build-drv = typixLib.buildTypstProject (
          commonBuildArgs
          // {
            inherit src;
          }
        );

        build-script = typixLib.buildTypstProjectLocal (
          commonBuildArgs
          // {
            inherit src;
          }
        );

        watch-script = typixLib.watchTypstProject commonArgs;
      in
      {
        checks = {
          inherit build-drv build-script watch-script;
        };

        packages.default = build-drv;

        apps = rec {
          default = watch;
          build = inputs.flake-utils.lib.mkApp {
            drv = build-script;
          };
          watch = inputs.flake-utils.lib.mkApp {
            drv = watch-script;
          };
        };

        devShells.default = typixLib.devShell {
          inherit (commonArgs) fontPaths virtualPaths;
          packages = [
            watch-script
            pkgs.typstyle
            pkgs.tinymist

            pkgs.nixfmt-rfc-style
          ];
        };

        formatter = pkgs.nixfmt-rfc-style;
      }
    );
}