Skip to content

Commit

Permalink
chore: Switch to a crane based build
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin van der Veen committed Apr 2, 2024
1 parent 0550d05 commit f87f8b9
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 124 deletions.
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
common-crane-args = {
pname = "genealogos";
src = crane-lib.cleanCargoSource (crane-lib.path ./.);
strictDeps = true;

cargoArtifacts = cargo-artifacts;

# 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.

0 comments on commit f87f8b9

Please sign in to comment.