-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
167 lines (158 loc) · 4.96 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
162
163
164
165
166
167
{
description = "Vaultix";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
crane.url = "github:ipetkov/crane";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{
flake-parts,
self,
crane,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } (
{
flake-parts-lib,
withSystem,
...
}:
let
inherit (flake-parts-lib) importApply;
flakeModules.default = importApply ./flake-module.nix {
inherit (self) packages;
inherit withSystem;
};
in
{
partitionedAttrs = {
checks = "dev";
nixosConfigurations = "dev";
vaultix = "dev";
};
partitions = {
dev.extraInputsFlake = ./dev;
dev.module =
{ inputs, ... }:
{
imports = [
inputs.pre-commit-hooks.flakeModule
flakeModules.default
./dev/pre-commit-hooks.nix
./dev/test.nix
];
};
};
imports =
let
inherit (inputs) flake-parts;
in
[
flake-parts.flakeModules.easyOverlay
flake-parts.flakeModules.partitions
./compatible.nix
];
systems = [
"x86_64-linux"
"aarch64-linux"
];
perSystem =
{
self',
pkgs,
system,
config,
...
}:
let
target = (pkgs.lib.systems.elaborate system).config;
mkOverriddenToolchain =
scale:
scale.override {
extensions = [ "rust-src" ];
targets = [ target ];
};
mkCraneLib = toolchain: (crane.mkLib pkgs).overrideToolchain toolchain;
releaseToolChain = mkOverriddenToolchain pkgs.rust-bin.nightly.latest.minimal;
releaseCraneLib = mkCraneLib releaseToolChain;
devCraneLib = mkCraneLib (mkOverriddenToolchain pkgs.rust-bin.nightly.latest.complete);
inherit (releaseCraneLib) buildPackage;
in
{
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = with inputs; [
rust-overlay.overlays.default
self.overlays.default
];
};
apps = {
default = {
type = "app";
program = pkgs.lib.getExe self'.packages.default;
};
};
packages = rec {
default = buildPackage rec {
src = releaseCraneLib.cleanCargoSource ./.;
nativeBuildInputs = [
pkgs.rustPlatform.bindgenHook
];
cargoVendorDir = releaseCraneLib.vendorMultipleCargoDeps {
inherit (releaseCraneLib.findCargoFiles src) cargoConfigs;
cargoLockList = [
./Cargo.lock
# Unfortunately this approach requires IFD (import-from-derivation)
# otherwise Nix will refuse to read the Cargo.lock from our toolchain
# (unless we build with `--impure`).
#
# Another way around this is to manually copy the rustlib `Cargo.lock`
# to the repo and import it with `./path/to/rustlib/Cargo.lock` which
# will avoid IFD entirely but will require manually keeping the file
# up to date!
"${releaseToolChain.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/library/Cargo.lock"
];
};
cargoExtraArgs = ''-Z build-std -Z build-std-features="optimize_for_size" --target ${target}'';
meta.mainProgram = "vaultix";
};
vaultix = default;
};
overlayAttrs = config.packages;
formatter = pkgs.nixfmt-rfc-style;
devShells.default = devCraneLib.devShell {
inputsFrom = [
pkgs.vaultix
];
buildInputs = with pkgs; [
just
nushell
cargo-fuzz
mdbook-alerts
statix
typos
];
};
};
flake = {
inherit flakeModules;
nixosModules = rec {
default =
{ pkgs, ... }:
{
imports = [ ./module ];
vaultix.package = withSystem pkgs.stdenv.hostPlatform.system (
{ config, ... }: config.packages.vaultix
);
};
vaultix = default;
};
};
}
);
}