Skip to content

Commit 369489b

Browse files
committed
merge main
2 parents bbd72e8 + dc51bc7 commit 369489b

File tree

2 files changed

+272
-47
lines changed

2 files changed

+272
-47
lines changed

flake.lock

Lines changed: 103 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 169 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,173 @@
11
{
2-
inputs = {
3-
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
4-
utils.url = "github:kreisys/flake-utils";
5-
naersk.url = "github:nmattia/naersk";
6-
naersk.inputs.nixpkgs.follows = "nixpkgs";
7-
};
8-
outputs = { self, nixpkgs, utils, naersk }:
9-
utils.lib.simpleFlake rec {
10-
inherit nixpkgs;
11-
systems = [ "x86_64-linux" "aarch64-linux" ];
12-
preOverlays = [ naersk overlay ];
13-
overlay = final: prev: {
14-
catalyst-toolbox = prev.naersk.buildPackage {
15-
inherit ((builtins.fromTOML
16-
(builtins.readFile (./Cargo.toml))).package)
17-
name version;
18-
root = ./.;
19-
nativeBuildInputs = with final; [ pkg-config protobuf rustfmt ];
20-
buildInputs = with final; [ openssl ];
21-
PROTOC = "${final.protobuf}/bin/protoc";
22-
PROTOC_INCLUDE = "${final.protobuf}/include";
2+
nixConfig.extra-substituters = [
3+
"https://vit.cachix.org"
4+
"https://hydra.iohk.io"
5+
];
6+
nixConfig.extra-trusted-public-keys = [
7+
"vit.cachix.org-1:tuLYwbnzbxLzQHHN0fvZI2EMpVm/+R7AKUGqukc6eh8="
8+
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
9+
];
10+
11+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
12+
inputs.flake-compat.url = "github:edolstra/flake-compat";
13+
inputs.flake-compat.flake = false;
14+
inputs.flake-utils.url = "github:numtide/flake-utils";
15+
inputs.gitignore.url = "github:hercules-ci/gitignore.nix";
16+
inputs.gitignore.inputs.nixpkgs.follows = "nixpkgs";
17+
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
18+
inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
19+
inputs.pre-commit-hooks.inputs.flake-utils.follows = "flake-utils";
20+
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
21+
inputs.rust-overlay.inputs.flake-utils.follows = "flake-utils";
22+
inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
23+
inputs.naersk.url = "github:nix-community/naersk";
24+
inputs.naersk.inputs.nixpkgs.follows = "nixpkgs";
25+
26+
outputs = {
27+
self,
28+
nixpkgs,
29+
flake-compat,
30+
flake-utils,
31+
gitignore,
32+
pre-commit-hooks,
33+
rust-overlay,
34+
naersk,
35+
}:
36+
flake-utils.lib.eachSystem
37+
[
38+
flake-utils.lib.system.x86_64-linux
39+
flake-utils.lib.system.aarch64-linux
40+
]
41+
(
42+
system: let
43+
readTOML = file: builtins.fromTOML (builtins.readFile file);
44+
workspaceCargo = readTOML ./Cargo.toml;
45+
46+
pkgs = import nixpkgs {
47+
inherit system;
48+
overlays = [(import rust-overlay)];
2349
};
24-
};
25-
packages = { catalyst-toolbox }@pkgs: pkgs;
26-
devShell =
27-
{ mkShell, rustc, cargo, pkg-config, openssl, protobuf, rustfmt }:
28-
mkShell {
29-
PROTOC = "${protobuf}/bin/protoc";
30-
PROTOC_INCLUDE = "${protobuf}/include";
31-
buildInputs = [ rustc cargo pkg-config openssl protobuf rustfmt ];
50+
51+
mkRust = {channel ? "stable"}: let
52+
_rust = pkgs.rust-bin.${channel}.latest.default.override {
53+
extensions = [
54+
"rust-src"
55+
"rust-analysis"
56+
"rls-preview"
57+
"rustfmt-preview"
58+
"clippy-preview"
59+
];
60+
};
61+
in
62+
pkgs.buildEnv {
63+
name = _rust.name;
64+
inherit (_rust) meta;
65+
buildInputs = [pkgs.makeWrapper pkgs.openssl];
66+
paths = [_rust];
67+
pathsToLink = ["/" "/bin"];
68+
# XXX: This is needed because cargo and clippy commands need to
69+
# also be aware of other binaries in order to work properly.
70+
# https://github.com/cachix/pre-commit-hooks.nix/issues/126
71+
postBuild = ''
72+
for i in $out/bin/*; do
73+
wrapProgram "$i" --prefix PATH : "$out/bin"
74+
done
75+
'';
76+
};
77+
78+
rust-stable = mkRust {channel = "stable";};
79+
rust-nightly = mkRust {channel = "nightly";};
80+
81+
naersk-lib = naersk.lib."${system}".override {
82+
cargo = rust-stable;
83+
rustc = rust-stable;
3284
};
33-
};
85+
86+
mkPackage = name: let
87+
pkgCargo = readTOML ./${name}/Cargo.toml;
88+
cargoOptions = [
89+
"--package"
90+
"file://$PWD/\"${name}\""
91+
];
92+
in
93+
naersk-lib.buildPackage {
94+
inherit (pkgCargo.package) name version;
95+
96+
root = gitignore.lib.gitignoreSource self;
97+
98+
cargoBuildOptions = x: x ++ cargoOptions;
99+
cargoTestOptions = x: x ++ cargoOptions;
100+
101+
PROTOC = "${pkgs.protobuf}/bin/protoc";
102+
PROTOC_INCLUDE = "${pkgs.protobuf}/include";
103+
104+
nativeBuildInputs = with pkgs; [
105+
pkg-config
106+
protobuf
107+
rustfmt
108+
];
109+
110+
buildInputs = with pkgs; [
111+
openssl
112+
];
113+
};
114+
115+
workspace =
116+
builtins.listToAttrs
117+
(
118+
builtins.map
119+
(name: {
120+
inherit name;
121+
value = mkPackage name;
122+
})
123+
workspaceCargo.workspace.members
124+
);
125+
126+
pre-commit = pre-commit-hooks.lib.${system}.run {
127+
src = self;
128+
hooks = {
129+
alejandra = {
130+
enable = true;
131+
};
132+
rustfmt = {
133+
enable = true;
134+
entry = pkgs.lib.mkForce "${rust-nightly}/bin/cargo-fmt fmt -- --check --color always";
135+
};
136+
};
137+
};
138+
139+
warnToUpdateNix = pkgs.lib.warn "Consider updating to Nix > 2.7 to remove this warning!";
140+
in rec {
141+
packages =
142+
workspace
143+
// {
144+
default = workspace.catalyst-toolbox;
145+
};
146+
147+
devShells.default = pkgs.mkShell {
148+
PROTOC = "${pkgs.protobuf}/bin/protoc";
149+
PROTOC_INCLUDE = "${pkgs.protobuf}/include";
150+
buildInputs =
151+
[rust-stable]
152+
++ (with pkgs; [
153+
pkg-config
154+
openssl
155+
protobuf
156+
]);
157+
shellHook =
158+
pre-commit.shellHook
159+
+ ''
160+
echo "=== Catalyst toolbox development shell ==="
161+
echo "Info: Git hooks can be installed using \`pre-commit install\`"
162+
'';
163+
};
164+
165+
checks.pre-commit = pre-commit;
166+
167+
hydraJobs = packages;
168+
169+
defaultPackage = warnToUpdateNix packages.default;
170+
devShell = warnToUpdateNix devShells.default;
171+
}
172+
);
34173
}

0 commit comments

Comments
 (0)