Skip to content

Commit

Permalink
Merge pull request #811 from input-output-hk/add-flake-nix
Browse files Browse the repository at this point in the history
Add flake.nix
  • Loading branch information
jpraynaud authored Apr 20, 2023
2 parents 19b0bfa + 4a7a11c commit 01921eb
Show file tree
Hide file tree
Showing 2 changed files with 270 additions and 0 deletions.
165 changes: 165 additions & 0 deletions flake.lock

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

105 changes: 105 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = inputs:
inputs.flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];

imports = [inputs.treefmt-nix.flakeModule];

perSystem = {
pkgs,
config,
system,
self',
...
}: let
inherit (inputs.nixpkgs) lib;
craneLib = inputs.crane.lib.${system};

clean = root:
lib.cleanSourceWith {
src = lib.cleanSource root;
filter = orig_path: type: let
path = builtins.toString orig_path;
base = builtins.baseNameOf path;
parentDir = builtins.baseNameOf (builtins.dirOf path);
matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [".rs" ".toml" ".md"];
isCargoFile = base == "Cargo.lock";
isCargoConfig = parentDir == ".cargo" && base == "config";
isOpenApiYaml = base == "openapi.yaml";
in
type == "directory" || matchesSuffix || isCargoFile || isCargoConfig || isOpenApiYaml;
};

buildInputs =
[
pkgs.gnum4
pkgs.pkg-config
pkgs.openssl
]
++ lib.optional (pkgs.stdenv.isDarwin) [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.configdHeaders
];

buildPackage = name: cargoToml:
craneLib.buildPackage {
inherit (craneLib.crateNameFromCargoToml {inherit cargoToml;}) pname version;
cargoExtraArgs = "-p ${name}";
src = clean ./.;
inherit buildInputs;
};
in {
packages = {
default = craneLib.buildPackage {
pname = "mithril";
version = "0.0.1";
src = clean ./.;
doCheck = false; # some tests require cardano-cli
inherit buildInputs;
};

mithril-client = buildPackage "mithril-client" ./mithril-client/Cargo.toml;
mithril-aggregator = buildPackage "mithril-aggregator" ./mithril-aggregator/Cargo.toml;
mithril-signer = buildPackage "mithril-signer" ./mithril-signer/Cargo.toml;
mithrildemo = buildPackage "mithrildemo" ./demo/protocol-demo/Cargo.toml;
mithril-end-to-end = buildPackage "mithril-end-to-end" ./mithril-test-lab/mithril-end-to-end/Cargo.toml;
};

devShells.default = pkgs.mkShell {
inputsFrom = [self'.packages.mithril-client];

nativeBuildInputs = [
pkgs.cargo
pkgs.rustc
pkgs.libiconv
config.treefmt.package
];

shellHook = ''
export RUST_BACKTRACE=1
ln -sf ${config.treefmt.build.configFile} treefmt.toml
'';
};

formatter = pkgs.writeShellApplication {
name = "treefmt";
text = "exec ${config.treefmt.package}/bin/treefmt";
};

treefmt = {
programs.alejandra.enable = true;
programs.rustfmt.enable = true;
projectRootFile = "flake.nix";
};
};
};
}

0 comments on commit 01921eb

Please sign in to comment.