-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
124 lines (105 loc) · 4.34 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
{
nixConfig = {
extra-trusted-substituters = [ "https://nix-community.cachix.org" ];
extra-trusted-public-keys = [ "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" ];
};
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = inputs@{ self, fenix, crane, flake-parts, advisory-db, ... }:
flake-parts.lib.mkFlake { inherit self inputs; } ({ withSystem, ... }: {
systems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
perSystem = { lib, config, self', inputs', pkgs, system, ... }:
let
rustToolchain = fenix.packages.${system}.stable.toolchain;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
# include .md and .json files for the build
markdownFilter = path: _type: builtins.match ".*md$" path != null;
jsonFilter = path: _type: builtins.match ".*json$" path != null;
markdownOrJSONOrCargo = path: type:
(markdownFilter path type) ||
(jsonFilter path type) ||
(craneLib.filterCargoSources path type);
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
commonArgs = {
src = lib.cleanSourceWith {
src = ./.;
filter = markdownOrJSONOrCargo;
name = "source";
};
pname = "rs1090";
version = version;
nativeBuildInputs = with pkgs; [ pkg-config openssl python3 bzip2 soapysdr ] ++
lib.optionals pkgs.stdenv.isLinux [ clang mold ]
;
buildInputs = [ ] ++ lib.optionals pkgs.stdenv.isDarwin
[
pkgs.libiconv
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
{
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self.checks;
buildInputs = [ rustToolchain pkgs.pkg-config pkgs.openssl ];
shellHook = if pkgs.stdenv.isDarwin then ''
export NIX_LDFLAGS="-L${lib.makeLibraryPath [pkgs.libiconv]} $NIX_LDFLAGS"
export NIX_LDFLAGS="-F${pkgs.darwin.apple_sdk.frameworks.SystemConfiguration}/Library/Frameworks -framework SystemConfiguration $NIX_LDFLAGS"
export NIX_LDFLAGS="-F${pkgs.darwin.apple_sdk.frameworks.Security}/Library/Frameworks -framework Security $NIX_LDFLAGS"
'' else if pkgs.stdenv.isLinux then ''
export RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=${pkgs.mold}/bin/mold"
''
else "";
};
packages =
{
default = craneLib.buildPackage (commonArgs // {
pname = "jet1090";
cargoExtraFlags = "--all-features -p jet1090";
meta.mainProgram = "jet1090";
inherit cargoArtifacts;
});
# docs = pkgs.callPackage ./docs {};
};
checks =
{
fmt = craneLib.cargoFmt (commonArgs);
audit = craneLib.cargoAudit (commonArgs // { inherit advisory-db; });
rustdoc = craneLib.cargoDoc (commonArgs // { inherit cargoArtifacts; });
clippy-check = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-features -- --deny warnings";
});
test-check = craneLib.cargoNextest (commonArgs // {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
});
}
# build packages as part of the checks
// (lib.mapAttrs' (key: value: lib.nameValuePair (key + "-package") value) self'.packages);
formatter = pkgs.nixpkgs-fmt;
};
});
}