{
  lib,
  clangStdenv,

  cargo,
  darwin,
  libiconv,
  libsodium,
  openssl,
  pkg-config,
  rustPlatform,
  rustc,
}: let
  cargoMeta = builtins.fromTOML (builtins.readFile ./pijul/Cargo.toml);
in
  clangStdenv.mkDerivation (self: {
    pname = cargoMeta.package.name;
    version = cargoMeta.package.version;

    src = ./.;
    buildAndTestSubdir = "pijul";

    doCheck = true;
    cargoBuildType = "release";

    cargoDeps = rustPlatform.importCargoLock {
      lockFile = ./Cargo.lock;
    };

    nativeBuildInputs = [
      cargo
      libiconv
      pkg-config
      rustc
    ];

    buildInputs =
      [
        libsodium
        openssl

        rustPlatform.cargoBuildHook
        rustPlatform.cargoInstallHook
        rustPlatform.cargoSetupHook
      ]
      ++ lib.optionals clangStdenv.isDarwin [
        darwin.apple_sdk.frameworks.SystemConfiguration
      ];

    postInstall = ''
      install -d $out/share/zsh/site-functions
      install \
        $src/share/zsh/site-functions/VCS_INFO_{detect,get_data}_pijul \
        $out/share/zsh/site-functions/
    '';
  })