-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
231 lines (192 loc) · 6.42 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
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
221
222
223
224
225
226
227
228
229
230
231
{
description = "Melodink, A self hosted Streaming Music Streaming App";
inputs = {
# Nixpkgs
nixpkgs.url = "github:nixos/nixpkgs";
air-nixpkgs.url = "github:nixos/nixpkgs?rev=c1ce56e9c606b4cd31f0950768911b1171b8db51";
flutter-nixpkgs.url = "github:nixos/nixpkgs?rev=c09c37319f1c931e17de74fc67aecfd1a6e95092";
flake-utils.url = "github:numtide/flake-utils";
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
android-nixpkgs = {
url = "github:tadfisher/android-nixpkgs?rev=5a052c62cdb51b210bc0717177d5bd014cba3df1";
};
};
outputs = {
nixpkgs,
air-nixpkgs,
flutter-nixpkgs,
gitignore,
flake-utils,
android-nixpkgs,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
};
};
flutter-pkgs = import flutter-nixpkgs {
inherit system;
config = {
android_sdk.accept_license = true;
allowUnfree = true;
};
};
air-pkgs = import air-nixpkgs {
inherit system;
};
ffmpeg = pkgs.ffmpeg.overrideAttrs (oldAttrs: {
patches =
(oldAttrs.patches or [])
++ [
./nix/ffmpeg/0001-hls-seek-patch-1.patch
./nix/ffmpeg/0002-hls-seek-patch-2.patch
./nix/ffmpeg/0003-return-eio-for-prematurely-broken-connection.patch
];
});
flutter-sdk = (import ./nix/flutter) flutter-pkgs;
sdk = android-nixpkgs.sdk.${system} (sdkPkgs:
with sdkPkgs; [
build-tools-33-0-1
build-tools-34-0-0
cmdline-tools-latest
emulator
platform-tools
platforms-android-34
platforms-android-33
platforms-android-31
platforms-android-28
system-images-android-34-google-apis-playstore-x86-64
ndk-23-1-7779620
]);
pinnedJDK = flutter-pkgs.jdk17;
in {
packages = rec {
melodink-server = pkgs.buildGo122Module rec {
name = "melodink-server";
src = gitignore.lib.gitignoreSource ./.;
subPackages = ["cmd/api"];
vendorHash = "sha256-YPVOIgBswQRnLJ1PfgtnQR8S3veWZ0IHX48v00c6gi4=";
CGO_ENABLED = 1;
buildInputs = with pkgs; [
pkg-config
gcc
chromaprint
fftw
vips
];
nativeBuildInputs = buildInputs;
flags = [
"-trimpath"
];
ldflags = [
"-s"
"-w"
];
preBuild = ''
cd server
make prebuild
cp -r ../vendor ./
'';
postInstall = ''
mkdir -p public
cp -r ./public/ $out/bin/
mv $out/bin/api $out/bin/melodink_server
'';
};
melodink-server-docker = pkgs.dockerTools.buildLayeredImage {
name = "melodink-server";
contents = [
melodink-server
pkgs.cacert
pkgs.ffmpeg-full
];
config.Cmd = ["${melodink-server}/bin/melodink_server"];
fakeRootCommands = ''
mkdir -p data
mkdir -m 0777 tmp
'';
};
melodink-client = flutter-pkgs.flutter.buildFlutterApplication rec {
pname = "melodink-client";
version = "1.0.0";
buildInputs = [
pkgs.which
pkgs.wrapGAppsHook
ffmpeg.dev
pkgs.pulseaudio.dev
pkgs.zenity
];
nativeBuildInputs = buildInputs;
src = gitignore.lib.gitignoreSource ./client;
patchPhase = ''
mkdir -p /build/source/build/linux/x64/release/
cp ${pkgs.fetchurl {
url = "https://github.com/microsoft/mimalloc/archive/refs/tags/v2.1.2.tar.gz";
hash = "sha256-Kxv/b3F/lyXHC/jXnkeG2hPeiicAWeS6C90mKue+Rus=";
}} /build/source/build/linux/x64/release/mimalloc-2.1.2.tar.gz
'';
NIX = "true";
preBuild = ''
packageRun build_runner build --delete-conflicting-outputs
make prebuild
'';
postFixup = ''
rm $out/bin/melodink_client
# Move Melodink App data to sub directory to prevent issue with Home manager
# https://github.com/nix-community/home-manager/issues/5173
mkdir -p $out/melodink
mv $out/app/* $out/melodink/
mv $out/melodink $out/app/melodink
makeWrapper $out/app/melodink/melodink-client/melodink_client $out/bin/melodink_client \
"''${gappsWrapperArgs[@]}" \
--prefix LD_LIBRARY_PATH : $out/app/lib:${pkgs.lib.makeLibraryPath [pkgs.sqlite pkgs.ffmpeg pkgs.pulseaudio]}
'';
autoPubspecLock = ./client/pubspec.lock;
gitHashes = {
adwaita_icons = "sha256-M2QMkxDc1qEnm344H2mdrUNqxO/sVHCY8ETc2rBtrXo=";
color_thief_flutter = "sha256-1I9OufoE03J7CNfJpE0A6GnwNtLtIwaAVxrKpfl77f0=";
quantize_dart = "sha256-BQeankAcKuCr77+8Dwhg+iVjEMt9cnmHOuPROFiIIGc=";
flutter_rating_bar = "sha256-BejegYGpBtAkpL9cPxg1+iLoPO1VuFVzIto+HMZRymg=";
};
};
};
devShell = pkgs.mkShell {
ANDROID_SDK_ROOT = "${sdk}/share/android-sdk";
ANDROID_HOME = "${sdk}/share/android-sdk";
CHROME_EXECUTABLE = "chromium";
FLUTTER_SDK = "${flutter-sdk}";
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${sdk}/share/android-sdk/build-tools/34.0.0/aapt2";
GOROOT = "${pkgs.go_1_22}/share/go";
shellHook = ''
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath [pkgs.sqlite pkgs.chromaprint]}
'';
buildInputs = [
(pkgs.golangci-lint.override {buildGoModule = pkgs.buildGo122Module;})
pkgs.go_1_22
air-pkgs.air
flutter-sdk
pinnedJDK
sdk
(pkgs.go-migrate.overrideAttrs (finalAttrs: previousAttrs: {
tags = ["sqlite3" "sqlite"];
}))
pkgs.sqlite
pkgs.pkg-config
pkgs.gtk3
ffmpeg.dev
pkgs.pulseaudio.dev
pkgs.chromaprint
pkgs.fftw
pkgs.vips
pkgs.zenity
pkgs.cmake
];
};
});
}