2023-01-02 14:46:12 +00:00
|
|
|
# For distribution from this repository as well as CI, we use Crane to build
|
|
|
|
# Attic.
|
|
|
|
#
|
|
|
|
# For a nixpkgs-acceptable form of the package expression, see `package.nixpkgs.nix`
|
|
|
|
# which will be submitted when the Attic API is considered stable. However, that
|
|
|
|
# expression is not tested by CI so to not slow down the hot path.
|
|
|
|
|
|
|
|
{ stdenv
|
|
|
|
, lib
|
|
|
|
, craneLib
|
|
|
|
, rustPlatform
|
|
|
|
, runCommand
|
|
|
|
, writeReferencesToFile
|
|
|
|
, pkg-config
|
|
|
|
, installShellFiles
|
|
|
|
, jq
|
|
|
|
|
|
|
|
, nix
|
|
|
|
, boost
|
|
|
|
, darwin
|
|
|
|
, libiconv
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
version = "0.1.0";
|
|
|
|
|
2023-01-06 07:59:38 +00:00
|
|
|
ignoredPaths = [ ".github" "target" "book" "nixos" "integration-tests" ];
|
2023-01-02 14:46:12 +00:00
|
|
|
|
|
|
|
src = lib.cleanSourceWith {
|
|
|
|
filter = name: type: !(type == "directory" && builtins.elem (baseNameOf name) ignoredPaths);
|
|
|
|
src = lib.cleanSource ./.;
|
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
|
|
|
installShellFiles
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
nix boost
|
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
darwin.apple_sdk.frameworks.SystemConfiguration
|
|
|
|
libiconv
|
|
|
|
];
|
|
|
|
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly {
|
|
|
|
pname = "attic";
|
2023-06-13 00:20:11 +00:00
|
|
|
inherit src version nativeBuildInputs buildInputs;
|
2023-01-02 14:46:12 +00:00
|
|
|
|
|
|
|
# By default it's "use-symlink", which causes Crane's `inheritCargoArtifactsHook`
|
|
|
|
# to copy the artifacts using `cp --no-preserve=mode` which breaks the executable
|
|
|
|
# bit of bindgen's build-script binary.
|
|
|
|
#
|
|
|
|
# With `use-zstd`, the cargo artifacts are archived in a `tar.zstd`. This is
|
|
|
|
# actually set if you use `buildPackage` without passing `cargoArtifacts`.
|
|
|
|
installCargoArtifactsMode = "use-zstd";
|
|
|
|
};
|
|
|
|
|
2023-03-22 00:45:34 +00:00
|
|
|
mkAttic = args: craneLib.buildPackage ({
|
2023-01-02 14:46:12 +00:00
|
|
|
pname = "attic";
|
|
|
|
inherit src version nativeBuildInputs buildInputs cargoArtifacts;
|
|
|
|
|
|
|
|
ATTIC_DISTRIBUTOR = "attic";
|
|
|
|
|
2024-03-27 21:14:45 +00:00
|
|
|
# See comment in `attic/build.rs`
|
|
|
|
NIX_INCLUDE_PATH = "${lib.getDev nix}/include";
|
|
|
|
|
2023-01-02 14:46:12 +00:00
|
|
|
# See comment in `attic-tests`
|
|
|
|
doCheck = false;
|
|
|
|
|
2023-01-08 07:57:22 +00:00
|
|
|
cargoExtraArgs = "-p attic-client -p attic-server";
|
|
|
|
|
2023-01-02 14:46:12 +00:00
|
|
|
postInstall = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
|
|
|
|
if [[ -f $out/bin/attic ]]; then
|
|
|
|
installShellCompletion --cmd attic \
|
|
|
|
--bash <($out/bin/attic gen-completions bash) \
|
|
|
|
--zsh <($out/bin/attic gen-completions zsh) \
|
|
|
|
--fish <($out/bin/attic gen-completions fish)
|
|
|
|
fi
|
|
|
|
'';
|
2023-01-09 06:00:53 +00:00
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Multi-tenant Nix binary cache system";
|
|
|
|
homepage = "https://github.com/zhaofengli/attic";
|
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ zhaofengli ];
|
|
|
|
platforms = platforms.linux ++ platforms.darwin;
|
|
|
|
};
|
2023-03-22 00:45:34 +00:00
|
|
|
} // args);
|
|
|
|
|
|
|
|
attic = mkAttic {
|
|
|
|
cargoExtraArgs = "-p attic-client -p attic-server";
|
2023-01-02 14:46:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# Client-only package.
|
2023-03-22 00:45:34 +00:00
|
|
|
attic-client = mkAttic {
|
2023-01-08 07:57:22 +00:00
|
|
|
cargoExtraArgs = " -p attic-client";
|
2023-03-22 00:45:34 +00:00
|
|
|
};
|
2023-01-02 14:46:12 +00:00
|
|
|
|
|
|
|
# Server-only package with fat LTO enabled.
|
|
|
|
#
|
|
|
|
# Because of Cargo's feature unification, the common `attic` crate always
|
|
|
|
# has the `nix_store` feature enabled if the client and server are built
|
|
|
|
# together, leading to `atticd` linking against `libnixstore` as well. This
|
|
|
|
# package is slimmer with more optimization.
|
|
|
|
#
|
|
|
|
# We don't enable fat LTO in the default `attic` package since it
|
|
|
|
# dramatically increases build time.
|
|
|
|
attic-server = craneLib.buildPackage {
|
|
|
|
pname = "attic-server";
|
|
|
|
|
|
|
|
# We don't pull in the common cargoArtifacts because the feature flags
|
|
|
|
# and LTO configs are different
|
|
|
|
inherit src version nativeBuildInputs buildInputs;
|
|
|
|
|
|
|
|
# See comment in `attic-tests`
|
|
|
|
doCheck = false;
|
|
|
|
|
|
|
|
cargoExtraArgs = "-p attic-server";
|
|
|
|
|
|
|
|
CARGO_PROFILE_RELEASE_LTO = "fat";
|
|
|
|
CARGO_PROFILE_RELEASE_CODEGEN_UNITS = "1";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Attic interacts with Nix directly and its tests require trusted-user access
|
|
|
|
# to nix-daemon to import NARs, which is not possible in the build sandbox.
|
|
|
|
# In the CI pipeline, we build the test executable inside the sandbox, then
|
|
|
|
# run it outside.
|
|
|
|
attic-tests = craneLib.mkCargoDerivation {
|
|
|
|
pname = "attic-tests";
|
|
|
|
|
|
|
|
inherit src version buildInputs cargoArtifacts;
|
|
|
|
|
|
|
|
nativeBuildInputs = nativeBuildInputs ++ [ jq ];
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
|
|
|
|
buildPhaseCargoCommand = "";
|
|
|
|
checkPhaseCargoCommand = "cargoWithProfile test --no-run --message-format=json >cargo-test.json";
|
|
|
|
doInstallCargoArtifacts = false;
|
|
|
|
|
2024-03-27 21:14:45 +00:00
|
|
|
# See comment in `attic/build.rs`
|
|
|
|
NIX_INCLUDE_PATH = "${lib.getDev nix}/include";
|
|
|
|
|
2023-01-02 14:46:12 +00:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p $out/bin
|
|
|
|
jq -r 'select(.reason == "compiler-artifact" and .target.test and .executable) | .executable' <cargo-test.json | \
|
|
|
|
xargs -I _ cp _ $out/bin
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
inherit cargoArtifacts attic attic-client attic-server attic-tests;
|
|
|
|
}
|