Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to a crane based build #42

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v12
- name: Building package
run: nix build .#all --extra-experimental-features 'nix-command flakes'
run: nix build .#workspace --extra-experimental-features 'nix-command flakes'
51 changes: 19 additions & 32 deletions flake.lock

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

124 changes: 92 additions & 32 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,58 +1,118 @@
{
inputs = {
naersk.url = "github:nix-community/naersk/master";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};

nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
nixtract.url = "github:tweag/nixtract";
};

outputs =
{ self
, crane
, nixpkgs
, utils
, naersk
, nixtract
}:
utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; };
naersk-lib = pkgs.callPackage naersk { };
crane-lib = crane.lib.${system};
cyclonedx = pkgs.callPackage ./nix/cyclonedx.nix { };
nixtract-cli = nixtract.defaultPackage.${system};

# Here we start the crane stuff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I'm often that guy but.... not a very high entropy comment 😛

common-crane-args = {
pname = "genealogos";
src = crane-lib.cleanCargoSource (crane-lib.path ./.);
strictDeps = true;

cargoArtifacts = cargo-artifacts;
Copy link
Member

@yannham yannham Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it seems to work in practice, the cyclic dependency between common-crane-args and cargo-artifacts looks a bit surprising at first.


# Genealogos uses the reqwest crate to query for narinfo on the substituters.
# reqwest depends on openssl.
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl ];
};

cargo-artifacts = crane-lib.buildDepsOnly common-crane-args;

workspace = (common-crane-args // {
cargoBuildCommand = "${pkgs.cargo-hack}/bin/cargo-hack hack build --profile release";
cargoTestCommand = "${pkgs.cargo-hack}/bin/cargo-hack hack test --profile release";
});

# Crane buildPackage arguments for every crate
crates = {
genealogos = (common-crane-args // {
cargoExtraArgs = "-p genealogos";
});
genealogos-cli = (common-crane-args // {
pname = "genealogos-cli";
cargoExtraArgs = "-p genealogos-cli";
});
genealogos-api = (common-crane-args // {
pname = "genealogos-api";
cargoExtraArgs = "-p genealogos-api";
});
};
rust-packages =
builtins.mapAttrs (_: crane-lib.buildPackage) crates;
in
rec {
packages = import ./nix/packages.nix { inherit pkgs naersk-lib cyclonedx nixtract-cli; };
devShells = {
default =
pkgs.mkShell {
buildInputs = with pkgs; [
cargo
cargo-dist
rust-analyzer
rustPackages.clippy
rustc
rustfmt

nixtract-cli

pkg-config
openssl

# https://github.com/rust-lang/cargo/issues/4463
cargo-hack
];
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
RUST_BACKTRACE = 1;
checks =
# Builds
rust-packages
# Clippy
// builtins.mapAttrs
(_: args: crane-lib.cargoClippy (args // {
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}))
crates
# Doc
// builtins.mapAttrs (_: crane-lib.cargoDoc) crates
# fmt
// builtins.mapAttrs (_: crane-lib.cargoFmt) crates;

packages =
rust-packages // {
default = packages.genealogos;

workspace = crane-lib.buildPackage workspace;

update-fixture-output-files = pkgs.writeShellApplication {
name = "update-fixture-output-files";
runtimeInputs = [ (packages.genealogos-cli.overrideAttrs (_: { doCheck = false; })) pkgs.jq ];
text = builtins.readFile ./scripts/update-fixture-output-files.sh;
};
scripts =
pkgs.mkShell {
buildInputs = with packages; [
update-fixture-input-files
update-fixture-output-files
verify-fixture-files
];
update-fixture-input-files = pkgs.writeShellApplication {
name = "update-fixture-input-files";
runtimeInputs = [ nixtract-cli ];
text = builtins.readFile ./scripts/update-fixture-input-files.sh;
};
verify-fixture-files = pkgs.writeShellApplication {
name = "verify-fixture-files";
runtimeInputs = [ cyclonedx ];
text = builtins.readFile ./scripts/verify-fixture-files.sh;
};
};

apps.default = utils.lib.mkApp {
drv = packages.genealogos-cli;
};


devShells.default = crane-lib.devShell {
inherit checks;

packages = with pkgs; [
rust-analyzer
cargo-hack
];
};
});
}
59 changes: 0 additions & 59 deletions nix/packages.nix

This file was deleted.

Loading