forked from nextcloud/notify_push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
134 lines (121 loc) · 4.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
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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.inputs.flake-utils.follows = "utils";
cross-naersk.url = "github:icewind1991/cross-naersk";
cross-naersk.inputs.nixpkgs.follows = "nixpkgs";
cross-naersk.inputs.naersk.follows = "naersk";
};
outputs = {
self,
nixpkgs,
utils,
naersk,
rust-overlay,
cross-naersk,
}:
utils.lib.eachDefaultSystem (system: let
overlays = [(import rust-overlay)];
pkgs = import nixpkgs {
inherit system overlays;
};
lib = pkgs.lib;
hostTarget = pkgs.hostPlatform.config;
targets = [
"x86_64-unknown-linux-musl"
"i686-unknown-linux-musl"
"armv7-unknown-linux-musleabihf"
"aarch64-unknown-linux-musl"
"x86_64-unknown-freebsd"
];
clientTargets = [
"x86_64-unknown-linux-musl"
"i686-unknown-linux-musl"
"armv7-unknown-linux-musleabihf"
"aarch64-unknown-linux-musl"
"x86_64-unknown-freebsd"
"x86_64-pc-windows-gnu"
];
inherit (builtins) listToAttrs fromTOML readFile;
inherit (lib.attrsets) genAttrs nameValuePair;
inherit (lib.lists) map;
inherit (cross-naersk') execSufficForTarget;
artifactForTarget = target: "notify_push";
assetNameForTarget = target: "notify_push-${target}";
cross-naersk' = pkgs.callPackage cross-naersk {
inherit naersk;
};
src = lib.sources.sourceByRegex (lib.cleanSource ./.) ["Cargo.*" "(src|tests|test_client|build.rs|appinfo)(/.*)?"];
nearskOpt = {
pname = "notify_push";
inherit src;
};
testClientOpts = nearskOpt // {
cargoBuildOptions = x: x ++ ["-p" "test_client"];
};
buildServer = target: (cross-naersk'.buildPackage target) nearskOpt;
buildTestClient = target: (cross-naersk'.buildPackage target) testClientOpts;
hostNaersk = cross-naersk'.hostNaersk;
checks = ["check" "clippy" "test"];
msrv = (fromTOML (readFile ./Cargo.toml)).package.rust-version;
msrvToolchain = pkgs.rust-bin.stable."${msrv}".default;
naerskMsrv = let
toolchain = msrvToolchain;
in
pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
};
testClientArtifactForTarget = target: "test_client${execSufficForTarget target}";
in rec {
# `nix build`
packages =
# cross compile notify_push for all targets
(genAttrs targets buildServer) //
# cross compile build test_client for all test_client-targets
(listToAttrs (map (target: nameValuePair "test_client-${target}" (buildTestClient target)) clientTargets)) //
# check,test,clippy for notify_push
(genAttrs checks (mode: hostNaersk.buildPackage (nearskOpt // { inherit mode;}))) //
# check,test,clippy for test_client
(listToAttrs (map (mode: nameValuePair "test_client-${mode}" (hostNaersk.buildPackage (testClientOpts // { inherit mode;}))) checks))
// rec {
notify_push = hostNaersk.buildPackage nearskOpt;
test_client = hostNaersk.buildPackage testClientOpts;
checkMsrv = naerskMsrv.buildPackage (nearskOpt
// {
mode = "check";
});
default = notify_push;
};
inherit targets clientTargets;
testClientMatrix = {
include = map (target: {
inherit target;
extension = execSufficForTarget target;
}) clientTargets;
};
devShells = {
default = cross-naersk'.mkShell targets {
nativeBuildInputs = with pkgs; [
(rust-bin.beta.latest.default.override {targets = targets ++ [hostTarget];})
krankerl
cargo-edit
cargo-outdated
bacon
php
phpPackages.composer
];
};
msrv = cross-naersk'.mkShell targets {
nativeBuildInputs = with pkgs; [
msrvToolchain
];
};
};
});
}