-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
88 lines (78 loc) · 2.25 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
crane.url = "github:ipetkov/crane";
fenix.url = "github:nix-community/fenix";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
nixpkgs,
flake-utils,
...
} @ inputs: let
fenix = inputs.fenix.packages;
in
# Iterate over Arm, x86 for MacOs 🍎 and Linux 🐧
(flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
crane = inputs.crane.mkLib pkgs;
# Toolchain
toolchain = fenix.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-yMuSb5eQPO/bHv+Bcf/US8LVMbf/G/0MSfiPwBhiPpk=";
};
craneLib = crane.overrideToolchain toolchain;
buildInputs = with pkgs; [
pkg-config
openssl
] ++ lib.optionals stdenv.isDarwin [
libiconv
darwin.apple_sdk.frameworks.Security
];
src = pkgs.lib.cleanSourceWith {
src = craneLib.path ./.;
filter = path: type:
(pkgs.lib.hasInfix "/.sqlx" path)
|| (pkgs.lib.hasInfix "/migrations" path)
|| (craneLib.filterCargoSources path type);
};
commonArgs = {
doCheck = false;
inherit src buildInputs;
};
libraries = [ ];
# Compile all artifacts
appDeps = craneLib.buildDepsOnly commonArgs;
# Compile
app = craneLib.buildPackage (commonArgs // {
cargoArtifacts = appDeps;
nativeBuildInputs = (commonArgs.nativeBuildInputs or [ ]) ++ [
pkgs.sqlx-cli
];
preBuild = ''
sqlx prepare
'';
});
in {
# nix build
packages.default = app;
# nix run
apps.default = flake-utils.lib.mkApp {
drv = app;
};
# nix develop
devShells.default = craneLib.devShell {
inherit buildInputs;
packages = with pkgs; [
toolchain
pkg-config
openssl
sqlx-cli
];
LITCRYPT_ENCRYPT_KEY = "test-key";
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath libraries}";
};
}
));
}