-
Notifications
You must be signed in to change notification settings - Fork 19
/
flake.nix
78 lines (67 loc) · 2.54 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
{
description = "r/unixporn discord bot";
inputs = {
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, utils, crane, rust-overlay, ... }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default ];
};
# Common Args
commonArgs = {
pname = "robbb";
# Will Require `--impure` to be passed to it can read that ENV VAR
version = if builtins.getEnv "VERSION" != "" then
builtins.getEnv "VERSION"
else
"0.0.1";
src = builtins.path { path = pkgs.lib.cleanSource ./.; name = "robbb"; };
nativeBuildInputs = with pkgs; [ rust-toolchain pkg-config ];
buildInputs = with pkgs; [ openssl sqlx-cli rust-analyzer sqlite ];
};
# Use the toolchain from the `rust-toolchain` file
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain;
craneLib = (crane.mkLib pkgs).overrideToolchain rust-toolchain;
# Build Deps so We don't have to build them everytime
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Run Cargo Fmt
robbbFmt = craneLib.cargoFmt (commonArgs // { inherit cargoArtifacts; });
# Run Clippy (only if cargo fmt passes)
robbbClippy = craneLib.cargoClippy (commonArgs // {
cargoArtifacts = robbbFmt;
cargoClippyExtraArgs = "-- -D warnings";
});
# Build Robb (only if all above tests pass)
robbb = craneLib.buildPackage
(commonArgs // { cargoArtifacts = robbbClippy; });
in {
# `nix flake check` (build, fmt and clippy)
checks = { inherit robbb; };
# `nix build`
packages.default = robbb;
# `nix run`
apps.default = utils.lib.mkApp { drv = robbb; };
# `nix develop`
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self.checks;
shellHook = ''
export $(cat .env)
'';
# Extra inputs can be added here
packages = [ pkgs.darwin.apple_sdk.frameworks.Security ] ++ commonArgs.nativeBuildInputs ++ commonArgs.buildInputs;
};
});
}