{
description = "quorum: trust a file when enough rebuilders you chose reproduced it";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, fenix }:
let
systems = [ "x86_64-linux" "aarch64-linux" ];
forAll = f: nixpkgs.lib.genAttrs systems (system:
f nixpkgs.legacyPackages.${system} fenix.packages.${system});
everywhere = nixpkgs.lib.genAttrs (systems ++ [ "aarch64-darwin" "x86_64-darwin" ]);
tools = pkgs: {
inherit (pkgs) cosign gnupg;
posix-oneshot = pkgs.buildGoModule {
pname = "tessera-posix-oneshot";
version = "1.0.4";
src = pkgs.fetchFromGitHub {
owner = "transparency-dev";
repo = "tessera";
rev = "v1.0.4";
hash = "sha256-y+uhfhKOk90taHO8Og+XFyZtcLNhS0GwCTqliWfrRao=";
};
vendorHash = "sha256-QSSablNUOxDpiNZSsMyOXWT09UDABkr64A41Ogp0poc=";
subPackages = [ "cmd/examples/posix-oneshot" ];
};
litewitness = pkgs.buildGoModule {
pname = "litewitness";
version = "0.10.0";
src = pkgs.fetchFromGitHub {
owner = "FiloSottile";
repo = "torchwood";
rev = "v0.10.0";
hash = "sha256-eSDbIOzWKRlmGXj+/LlaT22HDC77Uyz96fTTR9vWbWk=";
};
vendorHash = "sha256-S1/PInF5TvvuY/lcn5DPQS5NJJaiH3y1gXZZzJzWvtU=";
subPackages = [ "cmd/litewitness" "cmd/witnessctl" ];
doCheck = false;
};
tuftool = pkgs.rustPlatform.buildRustPackage rec {
pname = "tuftool";
version = "0.17.0";
src = pkgs.fetchCrate {
inherit pname version;
hash = "sha256-BlC152/Vd3hRSOI2/jf7DZ0ri27lw+kNLuOJ+0OaiUA=";
};
cargoHash = "sha256-GUbHOCnCy3hrlDL+2NDQwoK0V4ejRXiN2iwVdyFCCto=";
nativeBuildInputs = [ pkgs.cmake pkgs.perl ];
doCheck = false;
};
};
windowsPackages = forAll (pkgs: fx:
let
target = "x86_64-pc-windows-gnu";
toolchain = fx.combine [
fx.stable.rustc
fx.stable.cargo
fx.targets.${target}.stable.rust-std
];
vendor = pkgs.rustPlatform.importCargoLock { lockFile = ./Cargo.lock; };
src = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [ ./Cargo.toml ./Cargo.lock ./src ];
};
in
rec {
windows = pkgs.stdenv.mkDerivation {
pname = "quorum-windows";
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version;
inherit src;
nativeBuildInputs = [ toolchain pkgs.zig_0_16 pkgs.cargo-zigbuild ];
dontConfigure = true;
buildPhase = ''
export HOME=$TMPDIR CARGO_HOME=$TMPDIR/cargo XDG_CACHE_HOME=$TMPDIR/cache
export ZIG_GLOBAL_CACHE_DIR=$TMPDIR/zig-global ZIG_LOCAL_CACHE_DIR=$TMPDIR/zig-local
mkdir -p $TMPDIR/bin
printf '#!/bin/sh\nexec zig dlltool "$@"\n' > $TMPDIR/bin/x86_64-w64-mingw32-dlltool
chmod +x $TMPDIR/bin/x86_64-w64-mingw32-dlltool
export PATH=$TMPDIR/bin:$PATH
mkdir -p $TMPDIR/lib
printf 'LIBRARY api-ms-win-core-synch-l1-2-0.dll\nEXPORTS\nWaitOnAddress\nWakeByAddressAll\nWakeByAddressSingle\n' > $TMPDIR/synchronization.def
zig dlltool -m i386:x86-64 -d $TMPDIR/synchronization.def -l $TMPDIR/lib/libsynchronization.a
mkdir -p .cargo
cat > .cargo/config.toml <<EOF
[source.crates-io]
replace-with = "vendored"
[source.vendored]
directory = "${vendor}"
EOF
export RUSTFLAGS="-L native=$TMPDIR/lib --remap-path-prefix=$PWD=/quorum --remap-path-prefix=${vendor}=/vendor --remap-path-prefix=${toolchain}=/rust --remap-path-prefix=$TMPDIR=/tmp"
cargo zigbuild --release --frozen --offline --target ${target}
'';
installPhase = ''
install -Dm755 target/${target}/release/quorum.exe $out/bin/quorum.exe
sha256sum $out/bin/quorum.exe | cut -d' ' -f1 > $out/quorum.exe.sha256
'';
dontStrip = true;
dontFixup = true;
};
default = windows;
});
in
{
devShells = everywhere (system:
let pkgs = nixpkgs.legacyPackages.${system}; in {
default = pkgs.mkShell {
packages = builtins.attrValues (tools pkgs) ++ [ pkgs.openssh ];
};
});
checks = everywhere (system:
let pkgs = nixpkgs.legacyPackages.${system}; in {
tests = pkgs.rustPlatform.buildRustPackage {
pname = "quorum-tests";
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version;
src = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [ ./Cargo.toml ./Cargo.lock ./src ./tests ];
};
cargoLock.lockFile = ./Cargo.lock;
nativeCheckInputs = builtins.attrValues (tools pkgs) ++ [ pkgs.openssh ];
buildType = "debug";
};
});
packages = nixpkgs.lib.recursiveUpdate
(everywhere (system:
let
pkgs = nixpkgs.legacyPackages.${system};
quorum = pkgs.rustPlatform.buildRustPackage {
pname = "quorum";
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version;
src = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [ ./Cargo.toml ./Cargo.lock ./src ];
};
cargoLock.lockFile = ./Cargo.lock;
doCheck = false;
};
in
tools pkgs // {
inherit quorum;
rebuild = pkgs.writeShellApplication {
name = "rebuild";
runtimeInputs = [ quorum pkgs.cosign (tools pkgs).posix-oneshot pkgs.coreutils pkgs.findutils ];
text = builtins.readFile ./contrib/rebuild.sh;
};
}))
windowsPackages;
};
}