{ description = "Run the PostgreSQL server off a temporary data directory"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; crane.url = "github:ipetkov/crane"; }; outputs = inputs@{ self, nixpkgs, flake-parts, crane, ... }: flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; perSystem = { self', pkgs, lib, ... }: let craneLib = crane.mkLib pkgs; src = craneLib.cleanCargoSource ./.; commonArgs = { inherit src; strictDeps = true; }; cargoArtifacts = craneLib.buildDepsOnly commonArgs; crate = craneLib.buildPackage ( commonArgs // { inherit cargoArtifacts; nativeBuildInputs = [ pkgs.coreutils pkgs.postgresql ]; meta.mainProgram = "temp-postgres"; VERGEN_GIT_SHA = if self ? shortRev then self.shortRev else if self ? dirtyShortRev then lib.strings.removeSuffix "-dirty" self.dirtyShortRev else "unknown"; VERGEN_GIT_DIRTY = if self ? dirtyShortRev then "true" else "false"; } ); version = crate.version; revision = self.shortRev or self.dirtyShortRev or "unknown"; wrap = { postgresql, suffix ? "", }: pkgs.stdenv.mkDerivation { name = "temp-postgres-${version}-${revision}${suffix}"; version = "${version}-${revision}"; nativeBuildInputs = [ pkgs.makeBinaryWrapper ]; buildCommand = '' mkdir -p $out/bin makeWrapper ${crate}/bin/temp-postgres $out/bin/temp-postgres \ --prefix PATH : ${lib.makeBinPath [ postgresql ]} ''; }; postgresqlVersions = lib.mapAttrs' ( name: drv: let postgresqlVersion = lib.removePrefix "postgresql_" name; in lib.nameValuePair "temp-postgres_${postgresqlVersion}" (wrap { postgresql = drv; suffix = "_${postgresqlVersion}"; }) ) pkgs.postgresqlVersions; in { packages = { default = self'.packages.temp-postgres; temp-postgres = wrap { postgresql = pkgs.postgresql; }; temp-postgres-unwrapped = crate; } // postgresqlVersions; devShells.default = pkgs.mkShell { nativeBuildInputs = with pkgs; [ cargo cargo-audit cargo-deny cargo-edit clippy just nixfmt postgresql rust-analyzer rustc rustfmt taplo watchexec ]; shellHook = '' export FLAKE=${self} ''; }; formatter = pkgs.nixfmt-tree; }; }; }