-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
161 lines (155 loc) · 5.06 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
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
{
description = "";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
alejandra = {
url = "github:kamadorueda/alejandra";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs @ {
self,
nixpkgs,
...
}:
with builtins; let
std = nixpkgs.lib;
systems = attrNames inputs.crane.packages;
nixpkgsFor = std.genAttrs systems (system:
import nixpkgs {
localSystem = builtins.currentSystem or system;
crossSystem = system;
overlays = [inputs.rust-overlay.overlays.default];
});
toolchainToml = fromTOML (readFile ./rust-toolchain.toml);
toolchainFor = std.mapAttrs (system: pkgs: pkgs.rust-bin.fromRustupToolchain toolchainToml.toolchain) nixpkgsFor;
craneFor = std.mapAttrs (system: pkgs: (inputs.crane.mkLib pkgs).overrideToolchain toolchainFor.${system}) nixpkgsFor;
stdenvFor = std.mapAttrs (system: pkgs: pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_latest.stdenv) nixpkgsFor;
commonArgsFor =
std.mapAttrs (system: pkgs: let
crane = craneFor.${system};
in {
src = crane.cleanCargoSource (crane.path ./.);
stdenv = stdenvFor.${system};
strictDeps = true;
hardeningDisable = [
"fortify"
];
nativeBuildInputs = with pkgs; [
pkg-config
cmake
];
buildInputs = with pkgs; [
fontconfig
];
})
nixpkgsFor;
cargoToml = fromTOML (readFile ./Cargo.toml);
name = cargoToml.package.metadata.crane.name or cargoToml.package.name or cargoToml.workspace.metadata.crane.name;
version = cargoToml.package.version or cargoToml.workspace.package.version;
in {
formatter = std.mapAttrs (system: pkgs: pkgs.default) inputs.alejandra.packages;
packages =
std.mapAttrs (system: pkgs: let
crane = craneFor.${system};
src = crane.cleanCargoSource (crane.path ./.);
in {
default = self.packages.${system}.${name};
"${name}-artifacts" = crane.buildDepsOnly commonArgsFor.${system};
${name} = crane.buildPackage (commonArgsFor.${system}
// {
cargoArtifacts = self.packages.${system}."${name}-artifacts";
});
})
nixpkgsFor;
checks =
std.mapAttrs (system: pkgs: let
crane = craneFor.${system};
commonArgs = commonArgsFor.${system};
cargoArtifacts = self.packages.${system}."${name}-artifacts";
in {
${name} = pkgs.${name};
"${name}-clippy" = crane.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
});
"${name}-coverage" = crane.cargoTarpaulin (commonArgs
// {
inherit cargoArtifacts;
});
"${name}-audit" = crane.cargoAudit (commonArgs
// {
pname = name;
inherit version;
inherit cargoArtifacts;
advisory-db = inputs.advisory-db;
});
"${name}-deny" = crane.cargoDeny (commonArgs
// {
inherit cargoArtifacts;
});
})
self.packages;
apps =
std.mapAttrs (system: pkgs: {
${name} = {
type = "app";
program = "${pkgs.${name}}/bin/${name}";
};
default = self.apps.${system}.${name};
})
self.packages;
devShells =
std.mapAttrs (system: pkgs: let
selfPkgs = self.packages.${system};
toolchain = toolchainFor.${system}.override {
extensions = [
"rust-analyzer"
"rustfmt"
"clippy"
"rust-src"
];
};
crane = (inputs.crane.mkLib pkgs).overrideToolchain toolchain;
commonArgs = commonArgsFor.${system};
in {
${name} = (pkgs.mkShell.override {inherit (commonArgs) stdenv;}) {
inputsFrom = (attrValues self.checks.${system}) ++ [selfPkgs.${name}];
packages =
[toolchain]
++ (with pkgs; [
cargo-audit
cargo-license
cargo-dist
]);
inherit (commonArgs) hardeningDisable;
shellHook = let
extraLdPaths = pkgs.lib.makeLibraryPath (with pkgs; [
vulkan-loader
libGL
libxkbcommon
wayland
]);
in ''
export LD_LIBRARY_PATH="${extraLdPaths}:$LD_LIBRARY_PATH"
'';
env = {
};
};
default = self.devShells.${system}.${name};
})
nixpkgsFor;
};
}