nix: init flake environment

This commit is contained in:
Bruno BELANYI 2022-08-22 17:09:07 +02:00
parent 7797f40d2e
commit e53634976c
2 changed files with 268 additions and 0 deletions

116
flake.lock Normal file
View File

@ -0,0 +1,116 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"ref": "master",
"repo": "flake-utils",
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1659610603,
"narHash": "sha256-LYgASYSPYo7O71WfeUOaEUzYfzuXm8c8eavJcel+pfI=",
"owner": "nix-community",
"repo": "naersk",
"rev": "c6a45e4277fa58abd524681466d3450f896dc094",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "master",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1661151577,
"narHash": "sha256-++S0TuJtuz9IpqP8rKktWyHZKpgdyrzDFUXVY07MTRI=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "54060e816971276da05970a983487a25810c38a7",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1660830093,
"narHash": "sha256-HUhx3a82C7bgp2REdGFeHJdhEAzMGCk3V8xIvfBqg1I=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "8cb8ea5f1c7bc2984f460587fddd5f2e558f6eb8",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "master",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"naersk": "naersk",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1661136859,
"narHash": "sha256-o3y1elFGRs/9kqaIeziAnTy9lIWA6VHtQfq0ARRVO2A=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "6d1418192be90968acfa25e7d7b089e246eb15c4",
"type": "github"
},
"original": {
"owner": "oxalica",
"ref": "master",
"repo": "rust-overlay",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

152
flake.nix Normal file
View File

@ -0,0 +1,152 @@
{
description = "A simple payment processor";
inputs = {
flake-utils = {
type = "github";
owner = "numtide";
repo = "flake-utils";
ref = "master";
};
naersk = {
type = "github";
owner = "nix-community";
repo = "naersk";
ref = "master";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
nixpkgs = {
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "nixpkgs-unstable";
};
pre-commit-hooks = {
type = "github";
owner = "cachix";
repo = "pre-commit-hooks.nix";
ref = "master";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};
rust-overlay = {
type = "github";
owner = "oxalica";
repo = "rust-overlay";
ref = "master";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};
};
outputs =
{ self
, flake-utils
, naersk
, nixpkgs
, pre-commit-hooks
, rust-overlay
}:
let
inherit (flake-utils.lib) eachSystem system;
mySystems = [
system.aarch64-linux
system.x86_64-darwin
system.x86_64-linux
];
eachMySystem = eachSystem mySystems;
in
eachMySystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit overlays system; };
my-rust = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
};
naersk-lib = naersk.lib."${system}".override {
cargo = my-rust;
rustc = my-rust;
};
inherit (pkgs) lib;
pre-commit =
let
# See https://github.com/cachix/pre-commit-hooks.nix/issues/126
rust-env = pkgs.buildEnv {
name = "rust-env";
buildInputs = [ pkgs.makeWrapper ];
paths = [ my-rust ];
pathsToLink = [ "/" "/bin" ];
postBuild = ''
for i in $out/bin/*; do
wrapProgram "$i" --prefix PATH : "$out/bin"
done
'';
};
in
pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
clippy = {
enable = true;
entry = lib.mkForce "${rust-env}/bin/cargo-clippy clippy";
};
nixpkgs-fmt = {
enable = true;
};
rustfmt = {
enable = true;
entry = lib.mkForce "${rust-env}/bin/cargo-fmt fmt -- --check --color always";
};
};
};
in
rec {
devShells = {
default = pkgs.mkShell {
inputsFrom = [
packages.processor
];
nativeBuildInputs = with pkgs; [
rust-analyzer
# Clippy, rustfmt, etc...
my-rust
];
inherit (pre-commit) shellHook;
RUST_SRC_PATH = "${my-rust}/lib/rustlib/src/rust/library";
};
};
packages = {
default = self.packages."${system}".processor;
processor = naersk-lib.buildPackage {
src = self;
doCheck = true;
passthru = {
inherit my-rust;
};
};
};
});
}