forked from arximus88/figma-linux-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
166 lines (144 loc) · 5.41 KB
/
Copy pathflake.nix
File metadata and controls
166 lines (144 loc) · 5.41 KB
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
{
description = "Unofficial Electron-based Figma desktop client for Linux";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }:
let
pkg = builtins.fromJSON (builtins.readFile ./package.json);
# The release this flake installs. Rewritten as a unit by
# scripts/update_flake_release.py, which the `flake` job in
# .github/workflows/release.yml runs after every tagged release.
#
# The version is pinned here rather than read from package.json on
# purpose: the hashes only exist once the release binaries are built, so a
# version bump would otherwise leave the flake pointing at a tarball whose
# hash it cannot know, and every `nix build` would fail until someone
# recomputed them by hand. Kept together, the two can never drift.
#
# Between a version bump and the release finishing, this block still names
# the previous release — that window is the build itself, not a release
# cycle: CI writes the new pair to dev as soon as the binaries exist.
release = {
version = "0.20.1";
hashes = {
x86_64-linux = "sha256-vjOcC2mv+//ZKJ4yE3hfbK5M7hun3jRekylYZiqO5C4=";
aarch64-linux = "sha256-TrQlpuwNvsW7eYSRuQ/GIPxbDIdQ/pS3FVEwKrrmHYw=";
};
};
mkFigmaLinuxNext = pkgs:
let
arch = {
x86_64-linux = "x64";
aarch64-linux = "arm64";
}.${pkgs.stdenv.hostPlatform.system};
hash = release.hashes.${pkgs.stdenv.hostPlatform.system};
nativeLibs = with pkgs; [
alsa-lib
at-spi2-atk
at-spi2-core
cairo
cups
dbus
expat
fontconfig
freetype
gdk-pixbuf
glib
gtk3
libdrm
libGL
libnotify
libxkbcommon
mesa
nss
nspr
pango
stdenv.cc.cc.lib
systemd
wayland
libx11
libxcomposite
libxcursor
libxdamage
libxext
libxfixes
libxi
libxrandr
libxrender
libxscrnsaver
libxtst
libxcb
libxshmfence
zlib
];
in
pkgs.stdenv.mkDerivation {
pname = pkg.name;
version = release.version;
src = pkgs.fetchurl {
url = "${pkg.homepage}/releases/download/v${release.version}/${pkg.name}_${release.version}_linux_${arch}.zip";
inherit hash;
};
nativeBuildInputs = with pkgs; [ unzip autoPatchelfHook makeWrapper ];
buildInputs = nativeLibs;
dontBuild = true;
dontStrip = true;
unpackPhase = ''
unzip "$src" -d unpacked
'';
installPhase = ''
runHook preInstall
appDir="$out/opt/figma-linux-next"
install -d "$appDir"
cp -r unpacked/. "$appDir/"
install -Dm644 ${./figma-linux-next.desktop} \
"$out/share/applications/figma-linux-next.desktop"
for size in 24 36 48 64 72 96 128 192 256 384 512; do
icon="$appDir/icons/$size"x"$size.png"
if [ -f "$icon" ]; then
install -Dm644 "$icon" \
"$out/share/icons/hicolor/$size"x"$size/apps/figma-linux-next.png"
fi
done
runHook postInstall
'';
postInstall = ''
addAutoPatchelfSearchPath "$out/opt/figma-linux-next"
# xdg-open shim: clears LD_LIBRARY_PATH before delegating so that
# the subprocess chain (gio → gio-launch-desktop → browser) loads
# its own libraries rather than Electron's nativeLibs set.
# (Thanks Claude!)
mkdir -p "$out/libexec"
cat > "$out/libexec/xdg-open" <<'EOF'
#!/bin/sh
unset LD_LIBRARY_PATH
exec ${pkgs.xdg-utils}/bin/xdg-open "$@"
EOF
chmod +x "$out/libexec/xdg-open"
install -d "$out/bin"
makeWrapper "$out/opt/figma-linux-next/figma-linux-next" "$out/bin/figma-linux-next" \
--prefix PATH : "$out/libexec" \
--prefix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath nativeLibs}
'';
meta = with pkgs.lib; {
description = pkg.description;
homepage = pkg.homepage;
license = licenses.gpl2Only;
platforms = [ "x86_64-linux" "aarch64-linux" ];
mainProgram = "figma-linux-next";
sourceProvenance = [ sourceTypes.binaryNativeCode ];
};
};
in
{
packages.x86_64-linux.default = mkFigmaLinuxNext nixpkgs.legacyPackages.x86_64-linux;
packages.aarch64-linux.default = mkFigmaLinuxNext nixpkgs.legacyPackages.aarch64-linux;
nixosModules.default = { config, pkgs, lib, ... }: {
options.programs.figma-linux-next.enable = lib.mkEnableOption "figma-linux-next";
config = lib.mkIf config.programs.figma-linux-next.enable {
environment.systemPackages = [ self.packages.${pkgs.stdenv.hostPlatform.system}.default ];
# figma:// scheme handling is necessary for login redirects
xdg.mime.defaultApplications."x-scheme-handler/figma" = "figma-linux-next.desktop";
};
};
};
}