base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / pkgs / by-name / al / alist / package.nix
blobb89eb1387968c49507f158628227bca46e369980
2   lib,
3   buildGoModule,
4   fetchFromGitHub,
5   fetchurl,
6   fuse,
7   stdenv,
8   installShellFiles,
9   versionCheckHook,
11 buildGoModule rec {
12   pname = "alist";
13   version = "3.38.0";
15   src = fetchFromGitHub {
16     owner = "AlistGo";
17     repo = "alist";
18     rev = "refs/tags/v${version}";
19     hash = "sha256-HF5T/TZXiyT186qZyzz+m0K9ajF1wk8YAZljcq5ccWM=";
20     # populate values that require us to use git. By doing this in postFetch we
21     # can delete .git afterwards and maintain better reproducibility of the src.
22     leaveDotGit = true;
23     postFetch = ''
24       cd "$out"
25       git rev-parse HEAD > $out/COMMIT
26       # '0000-00-00T00:00:00Z'
27       date -u -d "@$(git log -1 --pretty=%ct)" "+%Y-%m-%dT%H:%M:%SZ" > $out/SOURCE_DATE_EPOCH
28       find "$out" -name .git -print0 | xargs -0 rm -rf
29     '';
30   };
31   web = fetchurl {
32     url = "https://github.com/AlistGo/alist-web/releases/download/${version}/dist.tar.gz";
33     hash = "sha256-jHbWhjvHfgtdocuuELbOwrMzL8tOQfBVdH9MxasEwGo=";
34   };
36   proxyVendor = true;
37   vendorHash = "sha256-Q5E86bNedXOqMKS3WrXicWg27vnjyGao0nE34Ws2l9E=";
39   buildInputs = [ fuse ];
41   tags = [ "jsoniter" ];
43   ldflags = [
44     "-s"
45     "-w"
46     "-X \"github.com/alist-org/alist/v3/internal/conf.GitAuthor=Xhofe <i@nn.ci>\""
47     "-X github.com/alist-org/alist/v3/internal/conf.Version=${version}"
48     "-X github.com/alist-org/alist/v3/internal/conf.WebVersion=${version}"
49   ];
51   preConfigure = ''
52     # use matched web files
53     rm -rf public/dist
54     tar -xzf ${web}
55     mv -f dist public
56   '';
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   '';
64   checkFlags =
65     let
66       # Skip tests that require network access
67       skippedTests = [
68         "TestHTTPAll"
69         "TestWebsocketAll"
70         "TestWebsocketCaller"
71       ];
72     in
73     [ "-skip=^${builtins.concatStringsSep "$|^" skippedTests}$" ];
75   nativeBuildInputs = [ installShellFiles ];
77   postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
78     installShellCompletion --cmd alist \
79       --bash <($out/bin/alist completion bash) \
80       --fish <($out/bin/alist completion fish) \
81       --zsh <($out/bin/alist completion zsh)
82   '';
84   doInstallCheck = true;
86   versionCheckProgramArg = "version";
88   nativeInstallCheckInputs = [
89     versionCheckHook
90   ];
92   meta = {
93     description = "File list/WebDAV program that supports multiple storages";
94     homepage = "https://github.com/alist-org/alist";
95     changelog = "https://github.com/alist-org/alist/releases/tag/v${version}";
96     license = with lib.licenses; [
97       agpl3Only
98       # alist-web
99       mit
100     ];
101     maintainers = with lib.maintainers; [ moraxyc ];
102     sourceProvenance = with lib.sourceTypes; [
103       fromSource
104       # alist-web
105       binaryBytecode
106     ];
107     mainProgram = "alist";
108   };