-
Notifications
You must be signed in to change notification settings - Fork 44
/
firmware.nix
136 lines (107 loc) · 3.42 KB
/
firmware.nix
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
{ lib
, stdenv
, callPackage
, autoPatchelfHook
, makeWrapper
, writeShellScript
, python3
, util-linuxMinimal
# jupiter-biosupdate
, libkrb5
, zlib
, coreutils
, gawk
, dmidecode
, jq
, efiSysMountPoint ? "/boot"
}:
let
src = callPackage ./src.nix { };
pythonEnv = python3.withPackages (py: with py; [
crcmod
click
progressbar2
hid
]);
# Very ugly wrapper to work around the hardcoded ESP path
h2offtWrapper = writeShellScript "h2offt-wrapper" ''
@h2offt@ "$@"
ret=$?
set -e
esp="${efiSysMountPoint}"
if [[ $ret = 194 && "$esp" != "/boot/efi" ]]; then
targetDir="$esp/EFI/Insyde"
source="/boot/efi/EFI/Insyde/isflash.bin"
>&2 echo "NixOS: Moving isflash.bin to $targetDir"
if [[ ! -e "$source" ]]; then
>&2 echo "NixOS: isflash.bin doesn't exist!"
exit 1
fi
${util-linuxMinimal}/bin/mountpoint "$esp" >/dev/null
mkdir -p "$targetDir"
mv "$source" "$targetDir"
>&2 echo "NixOS: Successfully moved"
fi
exit $ret
'';
in
stdenv.mkDerivation {
pname = "steamdeck-firmware";
inherit src;
inherit (src) version;
nativeBuildInputs = [
autoPatchelfHook
makeWrapper
];
buildInputs = [
# auto patchelf
libkrb5
zlib
stdenv.cc.cc # libstdc++.so.6
pythonEnv
];
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out/{bin,share}
cp -r usr/share/jupiter_bios $out/share
cp -r usr/share/jupiter_bios_updater $out/share
cp -r usr/share/jupiter_controller_fw_updater $out/share
h2offt_nixos="$out/share/jupiter_bios_updater/h2offt-nixos"
h2offt="$out/share/jupiter_bios_updater/h2offt" \
substituteAll ${h2offtWrapper} "$h2offt_nixos"
chmod +x "$h2offt_nixos"
cp usr/bin/jupiter-biosupdate $out/bin
sed -i "s|/usr/share/jupiter_bios_updater/h2offt|$h2offt_nixos|g" $out/bin/jupiter-biosupdate
sed -i "s|/usr/|$out/|g" $out/bin/jupiter-biosupdate
wrapProgram $out/bin/jupiter-biosupdate \
--prefix PATH : ${lib.makeBinPath [ coreutils dmidecode gawk jq ]}
cp usr/bin/jupiter-initial-firmware-update $out/bin
sed -i "s|/usr/|$out/|g" $out/bin/jupiter-initial-firmware-update
chmod +x $out/bin/jupiter-initial-firmware-update
cp usr/bin/jupiter-controller-update $out/bin
sed -i "s|/usr/|$out/|g" $out/bin/jupiter-controller-update
wrapProgram $out/bin/jupiter-controller-update \
--prefix PATH : ${lib.makeBinPath [ jq pythonEnv ]}
mkdir -p $out/libexec
makeShellWrapper \
$out/share/jupiter_controller_fw_updater/d20bootloader.py \
$out/libexec/d20bootloader \
--prefix PATH : ${lib.makeBinPath [ jq pythonEnv ]}
pushd $out/share/jupiter_bios_updater
# Upstream comment:
# > Remove gtk2 binary and respective build/start script - unused
# > Attempts to use gtk2 libraries which are not on the device.
rm h2offt-g H2OFFTx64-G.sh
popd
substituteInPlace usr/lib/systemd/system/*.service --replace "/usr" "$out"
install -D -m 644 usr/lib/systemd/system/jupiter-biosupdate.service $out/lib/systemd/system/jupiter-biosupdate.service
install -D -m 644 usr/lib/systemd/system/jupiter-controller-update.service $out/lib/systemd/system/jupiter-controller-update.service
runHook postInstall
'';
meta = with lib; {
description = "Steam Deck BIOS and controller firmware";
license = licenses.unfreeRedistributableFirmware;
};
}