Skip to content

Commit a12e640

Browse files
committed
Add flake.nix
1 parent a35fc91 commit a12e640

File tree

2 files changed

+251
-0
lines changed

2 files changed

+251
-0
lines changed

flake.lock

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

flake.nix

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
inputs = {
3+
flake-parts.url = "github:hercules-ci/flake-parts";
4+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
5+
treefmt-nix.url = "github:numtide/treefmt-nix";
6+
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
7+
crane.url = "github:ipetkov/crane";
8+
crane.inputs.nixpkgs.follows = "nixpkgs";
9+
};
10+
11+
outputs = inputs:
12+
inputs.flake-parts.lib.mkFlake {inherit inputs;} {
13+
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
14+
15+
imports = [inputs.treefmt-nix.flakeModule];
16+
17+
perSystem = {
18+
pkgs,
19+
config,
20+
system,
21+
self',
22+
...
23+
}: let
24+
inherit (inputs.nixpkgs) lib;
25+
craneLib = inputs.crane.lib.${system};
26+
27+
clean = root:
28+
lib.cleanSourceWith {
29+
src = lib.cleanSource root;
30+
filter = orig_path: type: let
31+
path = builtins.toString orig_path;
32+
base = builtins.baseNameOf path;
33+
parentDir = builtins.baseNameOf (builtins.dirOf path);
34+
matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [".rs" ".toml" ".md"];
35+
isCargoFile = base == "Cargo.lock";
36+
isCargoConfig = parentDir == ".cargo" && base == "config";
37+
isOpenApiYaml = base == "openapi.yaml";
38+
in
39+
type == "directory" || matchesSuffix || isCargoFile || isCargoConfig || isOpenApiYaml;
40+
};
41+
42+
buildPackage = name: cargoToml:
43+
craneLib.buildPackage {
44+
inherit (craneLib.crateNameFromCargoToml {inherit cargoToml;}) pname version;
45+
cargoExtraArgs = "-p ${name}";
46+
src = clean ./.;
47+
buildInputs = [
48+
pkgs.gnum4
49+
pkgs.pkg-config
50+
pkgs.openssl
51+
];
52+
};
53+
in {
54+
packages = {
55+
mithril-client = buildPackage "mithril-client" ./mithril-client/Cargo.toml;
56+
mithril-aggregator = buildPackage "mithril-aggregator" ./mithril-aggregator/Cargo.toml;
57+
mithril-signer = buildPackage "mithril-signer" ./mithril-signer/Cargo.toml;
58+
};
59+
60+
devShells.default = pkgs.mkShell {
61+
inputsFrom = [self'.packages.mithril-client];
62+
63+
nativeBuildInputs = [
64+
pkgs.cargo
65+
pkgs.rustc
66+
config.treefmt.package
67+
];
68+
69+
shellHook = ''
70+
ln -sf ${config.treefmt.build.configFile} treefmt.toml
71+
'';
72+
};
73+
74+
formatter = pkgs.writeShellApplication {
75+
name = "treefmt";
76+
text = "exec ${config.treefmt.package}/bin/treefmt";
77+
};
78+
79+
treefmt = {
80+
programs.alejandra.enable = true;
81+
programs.rustfmt.enable = true;
82+
projectRootFile = "flake.nix";
83+
};
84+
};
85+
};
86+
}

0 commit comments

Comments
 (0)