-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
158 lines (137 loc) · 4.66 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
{
description = "Fina devShell";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-parts.url = "github:hercules-ci/flake-parts";
buildbot-nix.url = "github:nix-community/buildbot-nix";
buildbot-nix.inputs.nixpkgs.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
};
nixConfig = {
extra-trusted-public-keys = "fina.cachix.org-1:Xaf+3HF5Wffl4Gtpi68Yz/wRQw0bH8tNVTlMnkLSRQc=";
extra-substituters = "https://fina.cachix.org";
};
outputs = inputs @ {
flake-parts,
nixpkgs,
rust-overlay,
crane,
...
}:
(flake-parts.lib.evalFlakeModule {inherit inputs;} (
{
lib,
self,
inputs,
...
}: {
imports = [
# ./devshells.nix
];
systems = [
"x86_64-linux"
];
perSystem = {
self',
system,
pkgs,
...
}: let
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default));
# rust = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
# NB: we don't need to overlay our custom toolchain for the *entire*
# pkgs (which would require rebuidling anything else which uses rust).
# Instead, we just want to update the scope that crane will use by appending
# our specific toolchain there.
## src = craneLib.cleanCargoSource ./.;
unfilteredRoot = ./.; # The original, unfiltered source
src = lib.fileset.toSource {
root = unfilteredRoot;
fileset = lib.fileset.unions [
# Default files from crane (Rust and cargo files)
(craneLib.fileset.commonCargoSources unfilteredRoot)
# Include all the .sql migrations as well
./migrations
./.sqlx
./templates
];
};
# Common arguments can be set here to avoid repeating them later
commonArgs = {
inherit src;
strictDeps = true;
RUSTFLAGS = "-Z threads=4";
};
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself, reusing the dependency
# artifacts from above.
## runs tests -> which will break currently due to network connectivity
## my-crate = craneLib.buildPackage (commonArgs
### my-crate = craneLib.cargoBuild (commonArgs
### // {
### inherit cargoArtifacts;
### });
my-crate = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
pname = "finnish";
meta.mainProgram = "finnish";
doCheck = false; # skip tests
});
in {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
# config.allowUnfree = true;
overlays = [
(import rust-overlay)
];
};
checks = {
# Build the crate as part of `nix flake check` for convenience
inherit my-crate;
# Run clippy (and deny all warnings) on the crate source,
# again, reusing the dependency artifacts from above.
#
# Note that this is done as a separate derivation so that
# we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself.
my-crate-clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
};
packages = {
default = my-crate;
cargoArtifacts = cargoArtifacts;
};
apps.default = {
type = "app";
program = my-crate;
};
devShells.default = craneLib.devShell {
RUSTFLAGS = "-Zthreads=4";
packages = with pkgs; [
bacon
cachix
cargo-expand
cargo-llvm-cov
cargo-nextest
jq
postgresql
python3
svix-cli
sqlx-cli
];
};
};
}
))
.config
.flake;
}