-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
149 lines (125 loc) · 4.78 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
# This flake's package is tied to SpMs release binaries. It does not build from source.
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
custom_nixpkgs.url = "github:toasterofbread/nixpkgs/4df73973bda897522847e03e0820067c053bccad";
};
outputs = { self, nixpkgs, custom_nixpkgs, ... }:
let
pname = "spmp-server";
version = "0.4.1";
x86_system = "x86_64-linux";
arm_system = "aarch64-linux";
pkgs = import nixpkgs {
system = x86_system;
};
custom_pkgs = import custom_nixpkgs {
system = x86_system;
};
systems = [
x86_system
arm_system
];
eachSystem = pkgs.lib.genAttrs systems;
getReleaseSourceUrl = system: {
"x86_64-linux" = "https://github.com/toasterofbread/spmp-server/releases/download/v${version}/spms-v${version}-linux-x86_64.kexe";
"aarch64-linux" = "https://github.com/toasterofbread/spmp-server/releases/download/v${version}/spms-v${version}-linux-arm64.kexe";
}.${system};
getReleaseSourceHash = system: {
"x86_64-linux" = "sha256-RVFn3FZWAJ7cstBTrqEVpoVQxPdeVzpB5hYuv26NDfY=";
"aarch64-linux" = "sha256-j+d3C7vqT/i7QRSzHnkZLlxGxtLwHFOpq56hQbv3SZo=";
}.${system};
kotlin_binary_patch_command = "patchkotlinbinary";
build_shell_hook = ''
# Add NIX_LDFLAGS to LD_LIBRARY_PATH
lib_paths=($(echo $NIX_LDFLAGS | grep -oP '(?<=-rpath\s| -L)[^ ]+'))
lib_paths_str=$(IFS=:; echo "''${lib_paths[*]}")
export LD_LIBRARY_PATH="$lib_paths_str:$LD_LIBRARY_PATH"
# Add include paths in NIX_CFLAGS_COMPILE to C_INCLUDE_PATH
IFS=' ' read -r -a flags <<< "$NIX_CFLAGS_COMPILE"
for (( i=0; i<''${#flags[@]}; i++ )); do
if [ "''${flags[$i]}" == "-isystem" ] && [ $((i+1)) -lt ''${#flags[@]} ]; then
export C_INCLUDE_PATH="''${C_INCLUDE_PATH}:''${flags[$((i+1))]}"
fi
done
export KONAN_DATA_DIR=$(pwd)/.konan
mkdir -p $KONAN_DATA_DIR
cp -asfT ${custom_pkgs.kotlin-native-toolchain-env} $KONAN_DATA_DIR
chmod -R u+w $KONAN_DATA_DIR
mkdir $KONAN_DATA_DIR/bin
export PATH="$KONAN_DATA_DIR/bin:$PATH"
PATCH_KOTLIN_BINARY_SCRIPT="patchelf --set-interpreter \$(cat \$NIX_CC/nix-support/dynamic-linker) --set-rpath ${custom_pkgs.kotlin-native-toolchain-env}/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/sysroot/lib64 \$1"
echo '[ "''${NO_PATCH:-0}" -eq 1 ] && exit 1' > $KONAN_DATA_DIR/bin/${kotlin_binary_patch_command}
echo "$PATCH_KOTLIN_BINARY_SCRIPT" >> $KONAN_DATA_DIR/bin/${kotlin_binary_patch_command}
chmod +x $KONAN_DATA_DIR/bin/${kotlin_binary_patch_command}
chmod -R u+w $KONAN_DATA_DIR
'';
build_packages = with pkgs; [
jdk21_headless
jdk22
pkg-config
#cmake
jextract
mpv
gtk3
patchelf
glibc
glibc_multi
libgcc.lib
(custom_pkgs.zeromq-kotlin-native.override { enableDrafts = true; })
(custom_pkgs.kotlin-native-toolchain-env.override { x86_64 = true; aarch64 = true; })
];
runtime_packages = with pkgs; [
curlMinimal
mpv
libayatana-appindicator
libxcrypt-legacy.out
];
packages = eachSystem (system: {
default =
pkgs.stdenv.mkDerivation {
inherit pname version;
src = pkgs.fetchurl {
url = getReleaseSourceUrl system;
hash = getReleaseSourceHash system;
};
dontUnpack = true;
nativeBuildInputs = with pkgs; [
autoPatchelfHook
];
buildInputs = runtime_packages;
installPhase = ''
mkdir -p $out/bin
install -Dm755 $src $out/bin/spms
'';
};
});
in
{
inherit packages;
devShells."${x86_system}".default =
let
pkgs = import nixpkgs {
system = x86_system;
};
arm_pkgs = import nixpkgs {
system = arm_system;
};
custom_pkgs = import custom_nixpkgs {
system = x86_system;
};
in
pkgs.mkShell {
packages = [
# For testing new releases
#packages."${x86_system}".default
] ++ build_packages ++ runtime_packages;
JAVA_21_HOME = "${pkgs.jdk21_headless}/lib/openjdk";
JAVA_22_HOME = "${pkgs.jdk22}/lib/openjdk";
JAVA_HOME = "${pkgs.jdk21_headless}/lib/openjdk";
JEXTRACT_PATH = "${pkgs.jextract}/bin/jextract";
KOTLIN_BINARY_PATCH_COMMAND = kotlin_binary_patch_command;
shellHook = build_shell_hook;
};
};
}