-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflake.nix
More file actions
175 lines (153 loc) · 4.96 KB
/
Copy pathflake.nix
File metadata and controls
175 lines (153 loc) · 4.96 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
{
description = "A Discord bot made for my discord server";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
};
outputs =
{
nixpkgs,
rust-overlay,
flake-utils,
crane,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
inherit (pkgs) lib;
# Release toolchain comes straight from rust-toolchain.toml (stable),
# using the *default* profile only. We deliberately do NOT pull in
# rust-src / rustc-dev / llvm-tools-preview here: the rust-src extension
# makes rustc bake toolchain store paths into panic-location strings,
# which Nix's reference scanner then treats as runtime references and
# drags the entire ~2.6 GiB toolchain into the closure of a ~15 MiB
# binary. The dev shell below keeps the full kit; it just never ships.
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
# Keep Cargo sources plus the runtime asset dirs the build copies into
# $out. craneLib.filterCargoSources alone would strip web/ & migrations/.
src = lib.cleanSourceWith {
src = ./.;
filter =
path: type:
(craneLib.filterCargoSources path type)
|| (builtins.match ".*/(web|migrations)(/.*)?" path != null);
};
commonArgs = {
inherit src;
strictDeps = true;
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
openssl
ffmpeg
libqalculate
];
};
# Compile (and cache) the dependency graph once; crane reuses this
# across rebuilds of the crate itself.
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
tricked-bot = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
nativeBuildInputs =
commonArgs.nativeBuildInputs
++ (with pkgs; [
makeWrapper
removeReferencesTo
]);
postInstall = ''
mkdir -p $out/share/tricked-bot
cp -r web $out/share/tricked-bot/
wrapProgram $out/bin/tricked-bot \
--prefix PATH : ${
lib.makeBinPath [
pkgs.ffmpeg
pkgs.libqalculate
]
}
'';
# Belt-and-suspenders: scrub any residual toolchain references the
# compiler embedded so the runtime closure stays minimal.
postFixup = ''
find $out -type f -executable -exec \
remove-references-to -t ${rustToolchain} {} +
'';
meta = with lib; {
description = "A simple discord bot made for my discord";
homepage = "https://discord.gg/mY8zTARu4g";
license = licenses.asl20;
maintainers = [ ];
mainProgram = "tricked-bot";
};
}
);
app = {
type = "app";
program = lib.getExe tricked-bot;
};
# Dev shell keeps the full toolchain (rust-src for rust-analyzer, etc.)
# plus nightly tooling. None of this ends up in the release closure.
rustDevToolchain = pkgs.rust-bin.beta.latest.default.override {
extensions = [
"rust-src"
"rust-analyzer"
"clippy"
"rustc-dev"
"llvm-tools-preview"
];
};
rustNightlyToolchain = pkgs.rust-bin.nightly.latest.default;
in
{
packages = {
default = tricked-bot;
inherit tricked-bot;
};
apps = {
default = app;
tricked-bot = app;
};
checks.default = tricked-bot;
devShells.default =
with pkgs;
mkShell {
buildInputs = [
openssl
pkg-config
eza
fd
clang
mold
rustDevToolchain
rustNightlyToolchain
cargo-udeps
ffmpeg
libqalculate
nixfmt-rfc-style
];
LD_LIBRARY_PATH = lib.makeLibraryPath [
openssl
];
shellHook = ''
if [ -f .env ]; then
set -a
source .env
set +a
echo "Loaded environment variables from .env"
fi
'';
};
formatter = pkgs.nixfmt-rfc-style;
}
);
}