blob: 0fbd81c9c92704267b7c4f0527c2fcc76f8780b3 (
plain)
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
|
{
description = "teawie moment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-compat.follows = "flake-compat";
inputs.flake-utils.follows = "flake-utils";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs-stable.follows = "nixpkgs";
inputs.flake-compat.follows = "flake-compat";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = {
self,
nixpkgs,
flake-utils,
crane,
fenix,
pre-commit-hooks,
...
}: let
supportedSystems = with flake-utils.lib.system; [
x86_64-linux
x86_64-darwin
aarch64-linux
aarch64-darwin
];
packageFn = craneLib: cargoArtifacts: pkgs: let
inherit (pkgs.lib) licenses maintainers platforms;
inherit (craneLib) buildPackage;
in {
teawiebot = buildPackage {
src = ./.;
inherit cargoArtifacts;
meta = {
description = "funni bot";
homepage = "https://github.com/getchoo/teawiebot";
license = licenses.mit;
platforms = platforms.unix;
maintainers = with maintainers; [getchoo];
};
};
};
in
flake-utils.lib.eachSystem supportedSystems (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [fenix.overlays.default];
};
toolchain = with pkgs.fenix;
with stable;
combine [
cargo
rustc
rustfmt
clippy
targets."x86_64-unknown-linux-musl".stable.rust-std
];
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
cargoArtifacts = craneLib.buildDepsOnly {
src = ./.;
};
in {
packages = let
inherit (packageFn craneLib cargoArtifacts pkgs) teawiebot;
teawiebot-smol =
teawiebot.overrideAttrs (_: {
# statically link musl, optimize for size
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
CARGO_BUILD_RUSTFLAGS = "-C lto=fat -C embed-bitcode=yes \
-C target-feature=+crt-static -C opt-level=z -C strip=symbols -C codegen-units=1";
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = let
inherit (pkgs.pkgsStatic.stdenv) cc;
in "${cc}/bin/${cc.targetPrefix}cc";
});
cmd = "${teawiebot-smol}/bin/teawiebot";
in
{
inherit teawiebot;
container = let
inherit (pkgs.dockerTools) buildLayeredImage caCertificates;
in
buildLayeredImage {
name = "teawiebot";
tag = "latest";
contents = [caCertificates];
config.Cmd = ["${cmd}"];
};
service = let
inherit (pkgs) cacert portableService;
service = pkgs.writeTextFile {
name = "teawiebot.service";
text = ''
[Unit]
Description=portable service for teawiebot
[Service]
DynamicUser=yes
ExecStart="${cmd}"
[Install]
WantedBy=multi-user.target
'';
};
in
portableService {
inherit (teawiebot) pname;
inherit (teawiebot-smol) version;
description = "portable service for teawiebot!";
units = [service];
symlinks = [
{
object = "${cacert}/etc/ssl";
symlink = "/etc/ssl";
}
];
};
}
// {default = self.packages.${system}.teawiebot;};
checks = let
commonArgs = {
src = ./.;
};
inherit (craneLib) cargoClippy cargoFmt;
in {
inherit (self.packages.${system}) teawiebot;
clippy = cargoClippy (commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets";
});
fmt = cargoFmt commonArgs;
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
actionlint.enable = true;
alejandra.enable = true;
deadnix.enable = true;
statix.enable = true;
};
};
};
devShells = let
inherit (pkgs) mkShell;
inherit (self.checks.${system}.pre-commit-check) shellHook;
in {
default = mkShell {
inherit shellHook;
packages = with pkgs; [
actionlint
alejandra
deadnix
statix
toolchain
];
};
};
formatter = pkgs.alejandra;
});
}
|