-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathflake.nix
More file actions
220 lines (203 loc) · 6.73 KB
/
flake.nix
File metadata and controls
220 lines (203 loc) · 6.73 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
{
description = "Clipcat - clipboard manager written in Rust Programming Language";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs =
inputs@{
self,
nixpkgs,
flake-parts,
fenix,
crane,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
];
flake = {
overlays.default = final: prev: { };
};
perSystem =
{
config,
self',
inputs',
pkgs,
system,
...
}:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.default
fenix.overlays.default
];
};
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
name = cargoToml.workspace.metadata.crane.name;
version = cargoToml.workspace.package.version;
rustToolchain =
with fenix.packages.${system};
combine [
stable.rustc
stable.cargo
stable.clippy
stable.rust-src
stable.rust-std
targets.x86_64-unknown-linux-musl.stable.rust-std
targets.aarch64-unknown-linux-musl.stable.rust-std
default.rustfmt
];
rustPlatform = pkgs.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
rustPlatformMusl = pkgs.pkgsStatic.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
isCross = system == "x86_64-linux";
isCrossFromAarch64 = system == "aarch64-linux";
crossPkgs =
if isCross then
import nixpkgs {
inherit system;
crossSystem = {
config = "aarch64-unknown-linux-musl";
};
overlays = [
self.overlays.default
fenix.overlays.default
];
}
else if isCrossFromAarch64 then
import nixpkgs {
inherit system;
crossSystem = {
config = "x86_64-unknown-linux-musl";
};
overlays = [
self.overlays.default
fenix.overlays.default
];
}
else
null;
rustPlatformCrossMusl =
if isCross || isCrossFromAarch64 then
crossPkgs.pkgsStatic.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
}
else
null;
cargoArgs = [
"--workspace"
"--bins"
"--examples"
"--tests"
"--benches"
"--all-targets"
];
unitTestArgs = [ "--workspace" ];
in
{
formatter = pkgs.treefmt;
devShells.default = pkgs.callPackage ./devshell {
inherit
rustToolchain
cargoArgs
unitTestArgs
;
};
packages = rec {
default = clipcat;
clipcat = pkgs.callPackage ./devshell/package.nix {
inherit name version rustPlatform;
};
completions = pkgs.callPackage ./devshell/package-completions.nix {
inherit clipcat;
};
clipcat-static = pkgs.pkgsStatic.callPackage ./devshell/package-static.nix {
inherit name version completions;
rustPlatform = rustPlatformMusl;
};
container = pkgs.callPackage ./devshell/container.nix {
inherit name version clipcat;
};
check-format = pkgs.callPackage ./devshell/format.nix { };
deb-x86_64 = pkgs.callPackage ./devshell/package-nfpm.nix {
inherit name version;
clipcat-static = if isCrossFromAarch64 then static-x86_64 else clipcat-static;
packager = "deb";
arch = "amd64";
};
rpm-x86_64 = pkgs.callPackage ./devshell/package-nfpm.nix {
inherit name version;
clipcat-static = if isCrossFromAarch64 then static-x86_64 else clipcat-static;
packager = "rpm";
arch = "x86_64";
};
apk-x86_64 = pkgs.callPackage ./devshell/package-nfpm.nix {
inherit name version;
clipcat-static = if isCrossFromAarch64 then static-x86_64 else clipcat-static;
packager = "apk";
arch = "x86_64";
};
tarball-x86_64 = pkgs.callPackage ./devshell/package-tarball.nix {
inherit name version;
clipcat-static = if isCrossFromAarch64 then static-x86_64 else clipcat-static;
};
static-aarch64 =
if isCross then
crossPkgs.pkgsStatic.callPackage ./devshell/package-static.nix {
inherit name version completions;
rustPlatform = rustPlatformCrossMusl;
}
else
clipcat-static;
static-x86_64 =
if isCrossFromAarch64 then
crossPkgs.pkgsStatic.callPackage ./devshell/package-static.nix {
inherit name version completions;
rustPlatform = rustPlatformCrossMusl;
}
else
clipcat-static;
deb-aarch64 = pkgs.callPackage ./devshell/package-nfpm.nix {
inherit name version;
clipcat-static = static-aarch64;
packager = "deb";
arch = "arm64";
};
rpm-aarch64 = pkgs.callPackage ./devshell/package-nfpm.nix {
inherit name version;
clipcat-static = static-aarch64;
packager = "rpm";
arch = "aarch64";
};
apk-aarch64 = pkgs.callPackage ./devshell/package-nfpm.nix {
inherit name version;
clipcat-static = static-aarch64;
packager = "apk";
arch = "arm64";
};
tarball-aarch64 = pkgs.callPackage ./devshell/package-tarball.nix {
inherit name version;
clipcat-static = static-aarch64;
target = "aarch64-unknown-linux-musl";
};
};
};
};
}