-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
168 lines (143 loc) · 4.46 KB
/
Copy pathflake.nix
File metadata and controls
168 lines (143 loc) · 4.46 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
{
description = "A devShell example";
inputs = {
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
outputs = {
self,
nixpkgs,
crane,
flake-utils,
fenix,
advisory-db,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [fenix.overlays.default];
};
inherit (pkgs) lib;
rustToolchain = pkgs.fenix.default.toolchain;
# rustToolchain = pkgs.fenix.combine (with pkgs.fenix; [
# stable.cargo
# stable.clippy
# stable.rustc
# latest.rustfmt
# ]);
#
craneLib = (crane.mkLib pkgs).overrideToolchain (p: rustToolchain);
craneDev = craneLib;
# craneDev = craneLib.overrideToolchain (p:
# p.fenix.combine (with p.fenix.stable; [
# rustToolchain
# rust-analyzer
# rust-src
# ]));
#
# craneNightly = craneLib.overrideToolchain pkgs.fenix.minimal.toolchain;
src = craneLib.cleanCargoSource self;
# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
strictDeps = true;
buildInputs = with pkgs; [] ++ lib.optionals stdenv.isDarwin [];
nativeBuildInputs = with pkgs; [
freetype
gumbo
harfbuzz
jbig2dec
libjpeg
openjpeg
openssl
pkg-config
llvmPackages.clangUseLLVM
];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
};
mkCargoArtifacts = craneLib: craneLib.buildDepsOnly commonArgs;
mkIndividualCrateArgs = craneLib:
commonArgs
// {
cargoArtifacts = mkCargoArtifacts craneLib;
inherit (craneLib.crateNameFromCargoToml {inherit src;}) version;
# NB: we disable tests since we'll run them all via cargo-nextest
doCheck = false;
};
fileSetForCrate = crate:
lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
(craneLib.fileset.commonCargoSources crate)
(lib.fileset.maybeMissing ./meta)
];
};
mkPackage = craneLib: name:
craneLib.buildPackage (mkIndividualCrateArgs craneLib
// {
pname = "runemail-${name}";
cargoExtraArgs = "-p runemail-${name}";
src = fileSetForCrate ./crates/${name};
});
mkPackages = craneLib: {
cofd-miner = mkPackage craneLib "miner";
};
mkChecks = craneLib: let
cargoArtifacts = mkCargoArtifacts craneLib;
in {
# Run clippy
workspace-clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
# Check formatting
workspace-fmt = craneLib.cargoFmt {
inherit src;
};
# Audit dependencies
workspace-audit = craneLib.cargoAudit {
inherit src advisory-db;
};
# Audit licenses
workspace-deny = craneLib.cargoDeny {
inherit src;
};
# Run tests with cargo-nextest
# Consider setting `doCheck = false` on other crate derivations
# if you do not want the tests to run twice
workspace-nextest = craneLib.cargoNextest (commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
cargoNextestPartitionsExtraArgs = "--no-tests=pass";
});
};
packages = mkPackages craneLib;
in {
checks =
mkChecks craneLib
// packages;
packages = {default = packages.cofd-miner;} // packages;
# apps.default = flake-utils.lib.mkApp {
# drv = cofd;
# };
devShells.default = craneDev.devShell {
checks = (mkChecks craneDev) // mkPackages craneDev;
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = "${pkgs.llvmPackages.clangUseLLVM}/bin/clang";
CARGO_ENCODED_RUSTFLAGS = "-Clink-arg=-fuse-ld=${pkgs.mold}/bin/mold";
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
packages = [];
};
});
}