Skip to content

Commit

Permalink
feat(flake): use the crane nix lib
Browse files Browse the repository at this point in the history
https://crane.dev/

enables caching of artifacts and potentially reducing build time.

Even End to End(E2E) testing could be added:
https://crane.dev/examples/end-to-end-testing.html

Signed-off-by: Harald Hoyer <[email protected]>
  • Loading branch information
haraldh committed Mar 27, 2024
1 parent 9c20d29 commit 35b5eda
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 57 deletions.
21 changes: 21 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 68 additions & 57 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
};
url = "github:oxalica/rust-overlay";
};

crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, devenv, flake-utils, nixpkgs, rust-overlay, ... } @ inputs:
outputs = { self, devenv, flake-utils, nixpkgs, rust-overlay, crane, ... } @ inputs:
flake-utils.lib.eachDefaultSystem
(system:
let
features = "--all-features";
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit overlays system;
Expand All @@ -30,95 +36,100 @@
rustc = pkgs.rust-bin.stable.latest.minimal;
inherit stdenv;
};
baseDependencies = with pkgs; [

craneLib = (crane.mkLib pkgs).overrideToolchain pkgs.rust-bin.stable.latest.minimal;
buildInputs = with pkgs; [
openssl
sqlite
zlib
];
nativeDependencies = with pkgs; [

nativeBuildInputs = with pkgs; [
protobuf
pkg-config
rustPlatform.bindgenHook
];

cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
src = pkgs.lib.cleanSourceWith {
src = pkgs.lib.cleanSource ./.;
filter = name: type:
let baseName = baseNameOf (toString name);
in !(baseName == "flake.lock" || pkgs.lib.hasSuffix ".nix" baseName);
};
version = cargoToml.workspace.package.version;

basePackage = {
inherit version src;
commonArgs = {
inherit src stdenv buildInputs nativeBuildInputs;

strictDeps = true;

meta = {
description = "ActivityPub-federated microblogging";
homepage = "https://joinkitsune.org";
};

cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};

OPENSSL_NO_VENDOR = 1;

buildInputs = baseDependencies;

nativeBuildInputs = nativeDependencies;

checkFlags = [
# Depend on creating an HTTP client and that reads from the systems truststore
# Because nix is fully isolated, these types of tests fail
#
# Some (most?) of these also depend on the network? Not good??
"--skip=activitypub::fetcher::test::federation_allow"
"--skip=activitypub::fetcher::test::federation_deny"
"--skip=activitypub::fetcher::test::fetch_actor"
"--skip=activitypub::fetcher::test::fetch_note"
"--skip=resolve::post::test::parse_mentions"
"--skip=webfinger::test::fetch_qarnax_ap_id"
"--skip=basic_request"
"--skip=json_request"
"--skip=http::handler::well_known::webfinger::tests::basic"
"--skip=http::handler::well_known::webfinger::tests::custom_domain"
"--skip=test::default_resolver_works"
"--skip=fetcher::basic::fetch_actor"
"--skip=fetcher::basic::fetch_emoji"
"--skip=fetcher::basic::fetch_note"
"--skip=fetcher::filter::federation_allow"
"--skip=fetcher::filter::federation_deny"
"--skip=fetcher::infinite::fetch_infinitely_long_reply_chain"
"--skip=fetcher::origin::check_ap_content_type"
"--skip=fetcher::origin::check_ap_id_authority"
"--skip=fetcher::webfinger::fetch_actor_with_custom_acct"
"--skip=fetcher::webfinger::ignore_fake_webfinger_acct"
"--skip=accounts_username"
"--skip=users_username"
"--skip=test::abort_request_works"
"--skip=test::full_test"
];
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
};

cargoTestExtraArgs = pkgs.lib.strings.concatStringsSep " " [
"--"
# Depend on creating an HTTP client and that reads from the systems truststore
# Because nix is fully isolated, these types of tests fail
#
# Some (most?) of these also depend on the network? Not good??
"--skip=activitypub::fetcher::test::federation_allow"
"--skip=activitypub::fetcher::test::federation_deny"
"--skip=activitypub::fetcher::test::fetch_actor"
"--skip=activitypub::fetcher::test::fetch_note"
"--skip=resolve::post::test::parse_mentions"
"--skip=webfinger::test::fetch_qarnax_ap_id"
"--skip=basic_request"
"--skip=json_request"
"--skip=http::handler::well_known::webfinger::tests::basic"
"--skip=http::handler::well_known::webfinger::tests::custom_domain"
"--skip=test::default_resolver_works"
"--skip=fetcher::basic::fetch_actor"
"--skip=fetcher::basic::fetch_emoji"
"--skip=fetcher::basic::fetch_note"
"--skip=fetcher::filter::federation_allow"
"--skip=fetcher::filter::federation_deny"
"--skip=fetcher::infinite::fetch_infinitely_long_reply_chain"
"--skip=fetcher::origin::check_ap_content_type"
"--skip=fetcher::origin::check_ap_id_authority"
"--skip=fetcher::webfinger::fetch_actor_with_custom_acct"
"--skip=fetcher::webfinger::ignore_fake_webfinger_acct"
"--skip=accounts_username"
"--skip=users_username"
"--skip=test::abort_request_works"
"--skip=test::full_test"
"--skip=attachment::test::upload_jpeg"
"--skip=post::resolver::test::parse_post"
];

cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
version = cargoToml.workspace.package.version;

cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
pname = "kitsune-workspace";
cargoExtraArgs = "--locked ${features}";
src = craneLib.cleanCargoSource src;
});
in
{
formatter = pkgs.nixpkgs-fmt;
packages = rec {
# Hack to make latest devenv work
devenv-up = self.devShells.${system}.default.config.procfileScript;

default = main;

cli = rustPlatform.buildRustPackage (basePackage // {
cli = craneLib.buildPackage (commonArgs // rec {
pname = "kitsune-cli";
cargoBuildFlags = "-p kitsune-cli";
cargoExtraArgs = "--locked ${features} -p kitsune-cli ";
inherit cargoArtifacts cargoTestExtraArgs;
});

main = rustPlatform.buildRustPackage (basePackage // {
main = craneLib.buildPackage (commonArgs // rec {
pname = "kitsune";
buildFeatures = [ "meilisearch" "oidc" ];
cargoBuildFlags = "-p kitsune";
cargoExtraArgs = "--locked ${features} -p kitsune";
inherit cargoArtifacts cargoTestExtraArgs;
});

frontend = pkgs.mkYarnPackage {
Expand Down Expand Up @@ -155,7 +166,7 @@
rust-bin.stable.latest.default
]
++
baseDependencies ++ nativeDependencies;
buildInputs ++ nativeBuildInputs;

enterShell = ''
export PG_HOST=127.0.0.1
Expand Down

0 comments on commit 35b5eda

Please sign in to comment.