-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathflake.nix
More file actions
156 lines (134 loc) · 4.94 KB
/
flake.nix
File metadata and controls
156 lines (134 loc) · 4.94 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
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs =
{
self,
flake-utils,
naersk,
nixpkgs,
rust-overlay,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = (import nixpkgs) {
inherit system;
overlays = [ (import rust-overlay) ];
};
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
pname = "globalprotect-openconnect";
version = cargoToml.workspace.package.version;
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
naersk' = pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
};
src = pkgs.fetchzip {
url = "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v${version}/globalprotect-openconnect-${version}.tar.gz";
hash = "sha256-4hlWP7yvwk4rTvQWuh60D40DJ20GfHhLTYA5+dkc4Hc=";
};
cpu = pkgs.stdenv.hostPlatform.parsed.cpu.name;
gpgui = pkgs.fetchzip {
url = "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/v${version}/gpgui_${cpu}.bin.tar.xz";
hash = {
x86_64 = "sha256-SayWyWJBDoIgqQG/z7v4FEr0uYHNZDJHokHPYqIgrJ0=";
aarch64 = "sha256-Q8yJW2ecv6zsuzzpfVAjSaDhLHQQJyVGFzZuLl0RV8Q=";
}.${cpu};
};
in
{
# For `nix build`
packages.default = naersk'.buildPackage {
inherit pname version src;
# Must be set to true to avoid issues with the Tauri build process
singleStep = true;
buildInputs =
with pkgs;
[
vpnc-scripts
libxml2
zlib
lz4
gnutls
p11-kit
nettle
gmp
]
++ lib.optionals stdenv.isLinux [
glib
gtk3
libsoup_3
webkitgtk_4_1
];
nativeBuildInputs =
with pkgs;
[
autoconf
automake
libtool
pkg-config
]
++ lib.optionals stdenv.isLinux [
autoPatchelfHook
];
runtimeDependencies =
with pkgs;
[ ]
++ lib.optionals stdenv.isLinux [
libappindicator-gtk3
];
overrideMain =
{ ... }:
{
postPatch = ''
substituteInPlace crates/openconnect/src/vpn_utils.rs \
--replace-fail /etc/vpnc/vpnc-script ${pkgs.vpnc-scripts}/bin/vpnc-script \
--replace-fail /usr/libexec/gpclient/hipreport.sh $out/libexec/gpclient/hipreport.sh \
--replace-fail /usr/lib/openconnect/hipreport.sh ${pkgs.openconnect}/libexec/openconnect/hipreport.sh
substituteInPlace crates/common/src/constants.rs \
--replace-fail /usr/bin/gpclient $out/bin/gpclient \
--replace-fail /usr/bin/gpservice $out/bin/gpservice \
--replace-fail /usr/bin/gpgui-helper $out/bin/gpgui-helper \
--replace-fail /usr/bin/gpgui $out/bin/gpgui \
--replace-fail /usr/bin/gpauth $out/bin/gpauth \
--replace-fail /opt/homebrew/ $out/
'';
};
postInstall = ''
# Copy the prebuilt gpgui binary to the output bin directory
cp ${gpgui}/gpgui $out/bin/gpgui
chmod +x $out/bin/gpgui
cp -r packaging/files/usr/share $out/share
cp -r packaging/files/usr/lib $out/lib
cp -r packaging/files/usr/libexec $out/libexec
# Change the `/usr/bin/gpclient` path in the desktop file
substituteInPlace $out/share/applications/gpgui.desktop \
--replace-fail /usr/bin/gpclient $out/bin/gpclient
substituteInPlace $out/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down \
--replace-fail /usr/bin/gpclient $out/bin/gpclient
substituteInPlace $out/libexec/gpclient/hipreport.sh \
--replace-fail /usr/bin/gpclient $out/bin/gpclient
# Change the `/usr/bin/gpservice` path in the polkit policy file
substituteInPlace $out/share/polkit-1/actions/com.yuezk.gpgui.policy \
--replace-fail /usr/bin/gpservice $out/bin/gpservice
'';
};
apps.default = {
type = "app";
program = "${self.packages.${system}.default}/bin/gpclient";
};
# For `nix develop`: not fully set up yet
devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
rustc
cargo
];
};
}
);
}