-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
120 lines (104 loc) · 3.35 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{
description = "CDK Flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
};
outputs = { self, nixpkgs, rust-overlay, flake-utils, pre-commit-hooks, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
lib = pkgs.lib;
stdenv = pkgs.stdenv;
isDarwin = stdenv.isDarwin;
libsDarwin = with pkgs; lib.optionals isDarwin [
# Additional darwin specific inputs can be set here
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
];
# Dependencies
pkgs = import nixpkgs {
inherit system overlays;
};
# Toolchains
# latest stable
stable_toolchain = pkgs.rust-bin.stable.latest.default;
# Common inputs
envVars = { };
buildInputs = with pkgs; [
# Add additional build inputs here
git
pkg-config
curl
just
nixpkgs-fmt
rust-analyzer
typos
] ++ libsDarwin;
# WASM deps
WASMInputs = with pkgs; [
];
nativeBuildInputs = with pkgs; [
#Add additional build inputs here
] ++ lib.optionals isDarwin [
# Additional darwin specific native inputs can be set here
];
in
{
checks = {
# Pre-commit checks
pre-commit-check =
let
# this is a hack based on https://github.com/cachix/pre-commit-hooks.nix/issues/126
# we want to use our own rust stuff from oxalica's overlay
_rust = pkgs.rust-bin.stable.latest.default;
rust = pkgs.buildEnv {
name = _rust.name;
inherit (_rust) meta;
buildInputs = [ pkgs.makeWrapper ];
paths = [ _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 = ./.;
hooks = {
rustfmt = {
enable = true;
entry = lib.mkForce "${rust}/bin/cargo-fmt fmt --all -- --config format_code_in_doc_comments=true --check --color always";
};
nixpkgs-fmt.enable = true;
typos.enable = true;
commitizen.enable = true; # conventional commits
};
};
};
devShells =
let
# pre-commit-checks
_shellHook = (self.checks.${system}.pre-commit-check.shellHook or "");
stable = pkgs.mkShell ({
shellHook = "${_shellHook}";
buildInputs = buildInputs ++ WASMInputs ++ [ stable_toolchain ];
inherit nativeBuildInputs;
} // envVars);
in
{
inherit stable;
default = stable;
};
}
);
}