{
    inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
    };

    outputs = { self, nixpkgs, ... }: 
    let
        lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
        version = builtins.substring 0 8 lastModifiedDate;

        nixpkgsFor = system: import nixpkgs { inherit system; overlays = [ self.overlay ]; };
    in
    {
        overlay = final: prev: with final; {
            signatureProxy = stdenv.mkDerivation {
                pname = "SignatureProxy";
                inherit version;

                buildScript = ''
                    make
                '';

                installScript = ''
                    mkdir -p $out/bin
                    cp app $out/bin
                    cp enclave.so $out/bin
                '';

                nativeBuildInputs = with pkgs; [
                    clang
                    glibc
                    sgx-sdk
                    gmp.dev
                    openssl.dev
                    pkg-config
                ];

                env = {
                    SGX_SDK = pkgs.sgx-sdk;
                    SGX_MODE = "SIM";
                };
            };
        };

        defaultPackage."x86_64-linux" = (nixpkgsFor "x86_64-linux").signatureProxy;
    };
}
