-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
153 lines (123 loc) · 5.09 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
{
description = "sadmadbotlad flake";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, flake-utils, rust-overlay, crane, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ rust-overlay.overlays.default ]; };
libPath = with pkgs; lib.makeLibraryPath [
openssl
libiconv
pkg-config
rocksdb
dbus
mpv
];
craneLib = (crane.mkLib nixpkgs.legacyPackages.${system});
nativeBuildInputs = with pkgs; [
dbus
alsa-lib
llvmPackages.libclang
llvmPackages.libcxxClang
makeWrapper
playerctl
];
buildInputs = with pkgs; [
mold
clang
dbus
mpv
];
sadmadbotladArtifacts = craneLib.buildDepsOnly ({
BINDGEN_EXTRA_CLANG_ARGS = "-isystem ${pkgs.llvmPackages.libclang.lib}/lib/clang/${pkgs.lib.getVersion pkgs.clang}/include";
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib/";
ROCKSDB_STATIC = "true";
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
pname = "sadmadbotlad";
src = craneLib.cleanCargoSource (craneLib.path ./sadmadbotlad);
inherit buildInputs nativeBuildInputs;
});
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
targets = [ "wasm32-unknown-unknown" ];
};
frontendCraneLib = (craneLib.overrideToolchain rustToolchain).overrideScope' (final: prev: {
# inherit (import nixpkgs-for-wasm-bindgen { inherit system; }) wasm-bindgen-cli;
});
frontendArtifacts = frontendCraneLib.buildDepsOnly ({
pname = "frontend";
src = frontendCraneLib.cleanCargoSource (frontendCraneLib.path ./frontend);
inherit buildInputs nativeBuildInputs;
doCheck = false;
});
frontendPackage = with pkgs; frontendCraneLib.buildTrunkPackage {
src = lib.cleanSourceWith {
src = ./frontend;
filter = path: type:
(lib.hasSuffix "\.html" path) ||
(lib.hasSuffix "\.css" path) ||
(lib.hasInfix "assets/" path) ||
# Default filter from crane (allow .rs files)
(frontendCraneLib.filterCargoSources path type)
;
};
inherit buildInputs nativeBuildInputs;
cargoArtifacts = frontendArtifacts;
};
serverArtifacts = craneLib.buildDepsOnly ({
pname = "server";
src = craneLib.cleanCargoSource (craneLib.path ./frontend/server);
inherit buildInputs nativeBuildInputs;
});
in
{
packages = rec {
sadmadbotlad = craneLib.buildPackage {
BINDGEN_EXTRA_CLANG_ARGS = "-isystem ${pkgs.llvmPackages.libclang.lib}/lib/clang/${pkgs.lib.getVersion pkgs.clang}/include";
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib/";
ROCKSDB_STATIC = "true";
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
LD_LIBRARY_PATH = "${libPath}";
src = craneLib.path ./sadmadbotlad;
inherit buildInputs nativeBuildInputs;
cargoArtifacts = sadmadbotladArtifacts;
postInstall = ''
patchelf --set-rpath ${libPath} $out/bin/sadmadbotlad
wrapProgram $out/bin/sadmadbotlad \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.playerctl pkgs.yt-dlp ]}
mkdir -p $out/share
cp -r commands $out/share
'';
};
frontend = frontendPackage;
server = craneLib.buildPackage {
src = craneLib.path ./frontend/server;
inherit buildInputs nativeBuildInputs ;
cargoArtifacts = serverArtifacts;
};
default = sadmadbotlad;
};
devShell = pkgs.mkShell.override { stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv; } {
inherit buildInputs nativeBuildInputs;
NIX_CFLAGS_LINK = "-fuse-ld=mold";
packages = with pkgs; [
(rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" ];
targets = [ "wasm32-unknown-unknown" ];
})
];
BINDGEN_EXTRA_CLANG_ARGS = "-isystem ${pkgs.llvmPackages.libclang.lib}/lib/clang/${pkgs.lib.getVersion pkgs.clang}/include";
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
ROCKSDB_LIB_DIR = "${pkgs.rocksdb}/lib/";
ROCKSDB_STATIC = "true";
LD_LIBRARY_PATH = "${libPath}";
};
});
}