Skip to content

Commit

Permalink
tool: Use rust-checks as a library rather than programs
Browse files Browse the repository at this point in the history
Next step in unifying the architecture.
  • Loading branch information
jtojnar committed Jun 2, 2024
1 parent 349aa83 commit 197458e
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 379 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/.direnv
/rust-checks/target
/result*
/target
165 changes: 165 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,13 @@ path = "src/main.rs"
[dependencies]
clap = { version = "4.5.4", features = ["derive"] }
indoc = "2.0.5"
serde = { workspace = true }
serde_json = { workspace = true }
rust-checks = { path = "./rust-checks" }

[workspace]
members = ["rust-checks"]

[workspace.dependencies]
serde = { version = "1.0.203", features = ["serde_derive"] }
serde_json = "1.0.117"
65 changes: 23 additions & 42 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,34 @@

{
nixpkgs-hammering =
let
rust-checks = prev.rustPlatform.buildRustPackage {
pname = "rust-checks";
version = (prev.lib.importTOML ./rust-checks/Cargo.toml).package.version;
src = ./rust-checks;
cargoLock.lockFile = ./rust-checks/Cargo.lock;
};

# Find all of the binaries installed by rust-checks. Note, if this changes
# in the future to use wrappers or something else that pollute the bin/
# directory, this logic will have to grow.
rust-check-names = let
binContents = builtins.readDir "${rust-checks}/bin";
in
prev.lib.mapAttrsToList (name: type: assert type == "regular"; name) binContents;
in
prev.rustPlatform.buildRustPackage {
pname = "nixpkgs-hammering";
version = (prev.lib.importTOML ./Cargo.toml).package.version;
src = ./.;
prev.rustPlatform.buildRustPackage {
pname = "nixpkgs-hammering";
version = (prev.lib.importTOML ./Cargo.toml).package.version;
src = ./.;

cargoLock.lockFile = ./Cargo.lock;
cargoLock.lockFile = ./Cargo.lock;

nativeBuildInputs = with prev; [
makeWrapper
];
nativeBuildInputs = with prev; [
makeWrapper
];

passthru = {
inherit rust-checks;
exePath = "/bin/nixpkgs-hammer";
};
passthru = {
exePath = "/bin/nixpkgs-hammer";
};

postInstall = ''
datadir="$out/share/nixpkgs-hammering"
mkdir -p "$datadir"
postInstall = ''
datadir="$out/share/nixpkgs-hammering"
mkdir -p "$datadir"
wrapProgram "$out/bin/nixpkgs-hammer" \
--prefix PATH ":" ${prev.lib.makeBinPath [
prev.nix
rust-checks
]} \
--set AST_CHECK_NAMES ${prev.lib.concatStringsSep ":" rust-check-names} \
--set OVERLAYS_DIR "$datadir/overlays"
cp -r ${./overlays} "$datadir/overlays"
cp -r ${./lib} "$datadir/lib"
'';
};
wrapProgram "$out/bin/nixpkgs-hammer" \
--prefix PATH ":" ${prev.lib.makeBinPath [
prev.nix
]} \
--set OVERLAYS_DIR "$datadir/overlays"
cp -r ${./overlays} "$datadir/overlays"
cp -r ${./lib} "$datadir/lib"
'';
};
};
};
} // utils.lib.eachDefaultSystem (system: let
Expand Down
Loading

0 comments on commit 197458e

Please sign in to comment.