1{
2 lib,
3 buildGoModule,
4 fetchFromGitHub,
5 fetchzip,
6 fuse,
7 stdenv,
8 installShellFiles,
9 versionCheckHook,
10 callPackage,
11}:
12buildGoModule rec {
13 pname = "alist";
14 version = "3.45.0";
15 webVersion = "3.45.0";
16
17 src = fetchFromGitHub {
18 owner = "AlistGo";
19 repo = "alist";
20 tag = "v${version}";
21 hash = "sha256-h8oWeTX3z3xye5O4+s7LA7Wm36JOrsU+UdKGZXaDKXk=";
22 # populate values that require us to use git. By doing this in postFetch we
23 # can delete .git afterwards and maintain better reproducibility of the src.
24 leaveDotGit = true;
25 postFetch = ''
26 cd "$out"
27 git rev-parse HEAD > $out/COMMIT
28 # '0000-00-00T00:00:00Z'
29 date -u -d "@$(git log -1 --pretty=%ct)" "+%Y-%m-%dT%H:%M:%SZ" > $out/SOURCE_DATE_EPOCH
30 find "$out" -name .git -print0 | xargs -0 rm -rf
31 '';
32 };
33 web = fetchzip {
34 url = "https://github.com/AlistGo/alist-web/releases/download/${webVersion}/dist.tar.gz";
35 hash = "sha256-rNVa+dr/SX2aYHBzeV8QdD5XYCFyelhbqkTpvhF+S2g=";
36 };
37
38 proxyVendor = true;
39 vendorHash = "sha256-IMoLVAgOaVM1xIFDe8BGOpzyBnDMfD9Q6VogFfOWFzU=";
40
41 buildInputs = [ fuse ];
42
43 tags = [ "jsoniter" ];
44
45 ldflags = [
46 "-s"
47 "-w"
48 "-X \"github.com/alist-org/alist/v3/internal/conf.GitAuthor=Xhofe <i@nn.ci>\""
49 "-X github.com/alist-org/alist/v3/internal/conf.Version=${version}"
50 "-X github.com/alist-org/alist/v3/internal/conf.WebVersion=${webVersion}"
51 ];
52
53 preConfigure = ''
54 rm -rf public/dist
55 cp -r ${web} public/dist
56 '';
57
58 preBuild = ''
59 ldflags+=" -X \"github.com/alist-org/alist/v3/internal/conf.GoVersion=$(go version | sed 's/go version //')\""
60 ldflags+=" -X \"github.com/alist-org/alist/v3/internal/conf.BuiltAt=$(cat SOURCE_DATE_EPOCH)\""
61 ldflags+=" -X github.com/alist-org/alist/v3/internal/conf.GitCommit=$(cat COMMIT)"
62 '';
63
64 checkFlags =
65 let
66 # Skip tests that require network access
67 skippedTests = [
68 "TestHTTPAll"
69 "TestWebsocketAll"
70 "TestWebsocketCaller"
71 "TestDownloadOrder"
72 ];
73 in
74 [ "-skip=^${builtins.concatStringsSep "$|^" skippedTests}$" ];
75
76 nativeBuildInputs = [ installShellFiles ];
77
78 postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
79 installShellCompletion --cmd alist \
80 --bash <($out/bin/alist completion bash) \
81 --fish <($out/bin/alist completion fish) \
82 --zsh <($out/bin/alist completion zsh)
83 '';
84
85 doInstallCheck = true;
86
87 versionCheckProgramArg = "version";
88
89 nativeInstallCheckInputs = [
90 versionCheckHook
91 ];
92
93 passthru = {
94 updateScript = lib.getExe (callPackage ./update.nix { });
95 };
96
97 meta = {
98 description = "File list/WebDAV program that supports multiple storages";
99 homepage = "https://github.com/alist-org/alist";
100 changelog = "https://github.com/alist-org/alist/releases/tag/v${version}";
101 license = with lib.licenses; [
102 agpl3Only
103 # alist-web
104 mit
105 ];
106 knownVulnerabilities = [
107 "Alist was acquired by Bugotech, a company distrusted by the community"
108 "Uses a questionable API server alist.nn.ci for account creation for certain drivers"
109 ];
110 maintainers = with lib.maintainers; [ moraxyc ];
111 sourceProvenance = with lib.sourceTypes; [
112 fromSource
113 # alist-web
114 binaryBytecode
115 ];
116 mainProgram = "alist";
117 };
118}