Skip to content

Commit 01921eb

Browse files
authored
Merge pull request #811 from input-output-hk/add-flake-nix
Add flake.nix
2 parents 19b0bfa + 4a7a11c commit 01921eb

File tree

2 files changed

+270
-0
lines changed

2 files changed

+270
-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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
buildInputs =
43+
[
44+
pkgs.gnum4
45+
pkgs.pkg-config
46+
pkgs.openssl
47+
]
48+
++ lib.optional (pkgs.stdenv.isDarwin) [
49+
pkgs.darwin.apple_sdk.frameworks.Security
50+
pkgs.darwin.configdHeaders
51+
];
52+
53+
buildPackage = name: cargoToml:
54+
craneLib.buildPackage {
55+
inherit (craneLib.crateNameFromCargoToml {inherit cargoToml;}) pname version;
56+
cargoExtraArgs = "-p ${name}";
57+
src = clean ./.;
58+
inherit buildInputs;
59+
};
60+
in {
61+
packages = {
62+
default = craneLib.buildPackage {
63+
pname = "mithril";
64+
version = "0.0.1";
65+
src = clean ./.;
66+
doCheck = false; # some tests require cardano-cli
67+
inherit buildInputs;
68+
};
69+
70+
mithril-client = buildPackage "mithril-client" ./mithril-client/Cargo.toml;
71+
mithril-aggregator = buildPackage "mithril-aggregator" ./mithril-aggregator/Cargo.toml;
72+
mithril-signer = buildPackage "mithril-signer" ./mithril-signer/Cargo.toml;
73+
mithrildemo = buildPackage "mithrildemo" ./demo/protocol-demo/Cargo.toml;
74+
mithril-end-to-end = buildPackage "mithril-end-to-end" ./mithril-test-lab/mithril-end-to-end/Cargo.toml;
75+
};
76+
77+
devShells.default = pkgs.mkShell {
78+
inputsFrom = [self'.packages.mithril-client];
79+
80+
nativeBuildInputs = [
81+
pkgs.cargo
82+
pkgs.rustc
83+
pkgs.libiconv
84+
config.treefmt.package
85+
];
86+
87+
shellHook = ''
88+
export RUST_BACKTRACE=1
89+
ln -sf ${config.treefmt.build.configFile} treefmt.toml
90+
'';
91+
};
92+
93+
formatter = pkgs.writeShellApplication {
94+
name = "treefmt";
95+
text = "exec ${config.treefmt.package}/bin/treefmt";
96+
};
97+
98+
treefmt = {
99+
programs.alejandra.enable = true;
100+
programs.rustfmt.enable = true;
101+
projectRootFile = "flake.nix";
102+
};
103+
};
104+
};
105+
}

0 commit comments

Comments
 (0)