anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / tools / misc / sharedown / default.nix
blobb23ca21694619806e2d2cc05173d2f6e9d79d6e4
1 { stdenvNoCC
2 , lib
3 , fetchFromGitHub
4 , ffmpeg
5 , yt-dlp
6 , libsecret
7 , python3
8 , pkg-config
9 , nodejs
10 , electron
11 , makeWrapper
12 , makeDesktopItem
13 , copyDesktopItems
14 , yarn2nix-moretea
15 , fetchYarnDeps
16 , chromium
19 stdenvNoCC.mkDerivation rec {
20   pname = "Sharedown";
21   version = "5.3.1";
23   src = fetchFromGitHub {
24     owner = "kylon";
25     repo = "Sharedown";
26     rev = version;
27     sha256 = "sha256-llQt3m/qu7v5uQIfA1yxl2JZiFafk6sPgcvrIpQy/DI=";
28   };
30   nativeBuildInputs = [
31     copyDesktopItems
32     makeWrapper
33   ];
35   desktopItems = [
36     (makeDesktopItem {
37       name = "Sharedown";
38       exec = "Sharedown";
39       icon = "Sharedown";
40       comment = "An Application to save your Sharepoint videos for offline usage.";
41       desktopName = "Sharedown";
42       categories = [ "Network" "Archiving" ];
43     })
44   ];
46   dontBuild = true;
48   installPhase =
49     let
50       binPath = lib.makeBinPath ([
51         ffmpeg
52         yt-dlp
53       ]);
55       modules = yarn2nix-moretea.mkYarnModules rec {
56         name = "Sharedown-modules-${version}";
57         inherit pname version;
59         yarnFlags = [ "--production" ];
61         pkgConfig = {
62           keytar = {
63             nativeBuildInputs = [
64               python3
65               pkg-config
66             ];
67             buildInputs = [
68               libsecret
69             ];
70             postInstall = ''
71               yarn --offline run build
72               # Remove unnecessary store path references.
73               rm build/config.gypi
74             '';
75           };
76         };
78         # needed for node-gyp, copied from https://nixos.org/manual/nixpkgs/unstable/#javascript-yarn2nix-pitfalls
79         # permalink: https://github.com/NixOS/nixpkgs/blob/d176767c02cb2a048e766215078c3d231e666091/doc/languages-frameworks/javascript.section.md#pitfalls-javascript-yarn2nix-pitfalls
80         preBuild = ''
81           mkdir -p $HOME/.node-gyp/${nodejs.version}
82           echo 9 > $HOME/.node-gyp/${nodejs.version}/installVersion
83           ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version}
84           export npm_config_nodedir=${nodejs}
85         '';
87         packageJSON = "${src}/package.json";
88         yarnLock = ./yarn.lock;
90         offlineCache = fetchYarnDeps {
91           inherit yarnLock;
92           hash = "sha256-NzWzkZbf5R1R72K7KVJbZUCzso1UZ0p3+lRYZE2M/dI=";
93         };
94       };
95     in
96     ''
97       runHook preInstall
99       mkdir -p "$out/bin" "$out/share/Sharedown" "$out/share/applications" "$out/share/icons/hicolor/512x512/apps"
101       # Electron app
102       cp -r *.js *.json sharedownlogo.png sharedown "${modules}/node_modules" "$out/share/Sharedown"
104       # Desktop Launcher
105       cp build/icon.png "$out/share/icons/hicolor/512x512/apps/Sharedown.png"
107       # Install electron wrapper script
108       makeWrapper "${electron}/bin/electron" "$out/bin/Sharedown" \
109         --add-flags "$out/share/Sharedown" \
110         --prefix PATH : "${binPath}" \
111         --set PUPPETEER_EXECUTABLE_PATH "${chromium}/bin/chromium"
113       runHook postInstall
114     '';
116   passthru.updateScript = ./update.sh;
118   meta = with lib; {
119     description = "Application to save your Sharepoint videos for offline usage";
120     homepage = "https://github.com/kylon/Sharedown";
121     license = licenses.gpl3Plus;
122     maintainers = with maintainers; [
123     ];
124     platforms = platforms.unix;
125     mainProgram = "Sharedown";
126   };