-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
130 lines (113 loc) · 3.55 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
{
nixConfig.extra-substituters = [
"https://vit.cachix.org"
"https://hydra.iohk.io"
];
nixConfig.extra-trusted-public-keys = [
"vit.cachix.org-1:tuLYwbnzbxLzQHHN0fvZI2EMpVm/+R7AKUGqukc6eh8="
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
];
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
flake-utils.url = "github:numtide/flake-utils";
gitignore.url = "github:hercules-ci/gitignore.nix";
gitignore.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.flake-utils.follows = "flake-utils";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
naersk.url = "github:nix-community/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{ self
, nixpkgs
, flake-compat
, flake-utils
, gitignore
, rust-overlay
, naersk
,
}:
flake-utils.lib.eachSystem
[
flake-utils.lib.system.x86_64-linux
flake-utils.lib.system.aarch64-linux
]
(
system:
let
readTOML = file: builtins.fromTOML (builtins.readFile file);
workspaceCargo = readTOML ./Cargo.toml;
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
mkRust = { channel ? "stable" }:
let
_rust = pkgs.rust-bin.${channel}.latest.default.override {
extensions = [
"rust-src"
"rust-analysis"
"rls-preview"
"rustfmt-preview"
"clippy-preview"
];
};
in
pkgs.buildEnv {
name = _rust.name;
inherit (_rust) meta;
buildInputs = [ pkgs.makeWrapper pkgs.openssl ];
paths = [ _rust ];
pathsToLink = [ "/" "/bin" ];
# XXX: This is needed because cargo and clippy commands need to
# also be aware of other binaries in order to work properly.
# https://github.com/cachix/pre-commit-hooks.nix/issues/126
postBuild = ''
for i in $out/bin/*; do
wrapProgram "$i" --prefix PATH : "$out/bin"
done
'';
};
rust-stable = mkRust { channel = "stable"; };
rust-nightly = mkRust { channel = "nightly"; };
naersk-lib = naersk.lib."${system}".override {
cargo = rust-stable;
rustc = rust-stable;
};
mkPackage =
let
pkgCargo = readTOML ./Cargo.toml;
in
naersk-lib.buildPackage {
inherit (pkgCargo.package) name version;
root = gitignore.lib.gitignoreSource self;
nativeBuildInputs = with pkgs; [
pkg-config
postgresql
];
};
in
rec {
packages =
{
default = mkPackage;
};
devShells.default = pkgs.mkShell {
buildInputs =
[ rust-stable ]
++ (with pkgs; [
pkg-config
postgresql
diesel-cli
cargo-insta # snapshot testing lib
]);
};
hydraJobs = packages;
defaultPackage = packages.default;
devShell = devShells.default;
}
);
}