You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generic.nix 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. { stdenv, lib, makeDesktopItem
  2. , unzip, libsecret, libXScrnSaver, wrapGAppsHook
  3. , gtk2, atomEnv, at-spi2-atk, autoPatchelfHook
  4. , systemd, fontconfig
  5. # Attributes inherit from specific versions
  6. , version, src, meta, sourceRoot
  7. , executableName, longName, shortName, pname
  8. }:
  9. let
  10. inherit (stdenv.hostPlatform) system;
  11. in
  12. stdenv.mkDerivation {
  13. inherit pname version src sourceRoot;
  14. passthru = {
  15. inherit executableName;
  16. };
  17. desktopItem = makeDesktopItem {
  18. name = executableName;
  19. desktopName = longName;
  20. comment = "Code Editing. Redefined.";
  21. genericName = "Text Editor";
  22. exec = executableName;
  23. icon = "@out@/share/pixmaps/code.png";
  24. startupNotify = "true";
  25. categories = "Utility;TextEditor;Development;IDE;";
  26. mimeType = "text/plain;inode/directory;";
  27. extraEntries = ''
  28. StartupWMClass=${shortName}
  29. Actions=new-empty-window;
  30. Keywords=vscode;
  31. [Desktop Action new-empty-window]
  32. Name=New Empty Window
  33. Exec=${executableName} --new-window %F
  34. Icon=@out@/share/pixmaps/code.png
  35. '';
  36. };
  37. urlHandlerDesktopItem = makeDesktopItem {
  38. name = executableName + "-url-handler";
  39. desktopName = longName + " - URL Handler";
  40. comment = "Code Editing. Redefined.";
  41. genericName = "Text Editor";
  42. exec = executableName + " --open-url %U";
  43. icon = "@out@/share/pixmaps/code.png";
  44. startupNotify = "true";
  45. categories = "Utility;TextEditor;Development;IDE;";
  46. mimeType = "x-scheme-handler/vscode;";
  47. extraEntries = ''
  48. NoDisplay=true
  49. Keywords=vscode;
  50. '';
  51. };
  52. buildInputs = (if stdenv.isDarwin
  53. then [ unzip ]
  54. else [ gtk2 at-spi2-atk wrapGAppsHook ] ++ atomEnv.packages)
  55. ++ [ libsecret libXScrnSaver ];
  56. nativeBuildInputs = lib.optional (!stdenv.isDarwin) autoPatchelfHook;
  57. dontBuild = true;
  58. dontConfigure = true;
  59. installPhase =
  60. if system == "x86_64-darwin" then ''
  61. mkdir -p "$out/Applications/${longName}.app" $out/bin
  62. cp -r ./* "$out/Applications/${longName}.app"
  63. ln -s "$out/Applications/${longName}.app/Contents/Resources/app/bin/code" $out/bin/${executableName}
  64. '' else ''
  65. mkdir -p $out/lib/vscode $out/bin
  66. cp -r ./* $out/lib/vscode
  67. substituteInPlace $out/lib/vscode/bin/${executableName} --replace '"$CLI" "$@"' '"$CLI" "--skip-getting-started" "$@"'
  68. ln -s $out/lib/vscode/bin/${executableName} $out/bin
  69. mkdir -p $out/share/applications
  70. substitute $desktopItem/share/applications/${executableName}.desktop $out/share/applications/${executableName}.desktop \
  71. --subst-var out
  72. substitute $urlHandlerDesktopItem/share/applications/${executableName}-url-handler.desktop $out/share/applications/${executableName}-url-handler.desktop \
  73. --subst-var out
  74. mkdir -p $out/share/pixmaps
  75. cp $out/lib/vscode/resources/app/resources/linux/code.png $out/share/pixmaps/code.png
  76. # Override the previously determined VSCODE_PATH with the one we know to be correct
  77. sed -i "/ELECTRON=/iVSCODE_PATH='$out/lib/vscode'" $out/bin/${executableName}
  78. grep -q "VSCODE_PATH='$out/lib/vscode'" $out/bin/${executableName} # check if sed succeeded
  79. '';
  80. preFixup = lib.optionalString (system == "i686-linux" || system == "x86_64-linux") ''
  81. gappsWrapperArgs+=(--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ systemd fontconfig ]})
  82. '';
  83. inherit meta;
  84. }