aboutsummaryrefslogtreecommitdiff
path: root/server.nix
diff options
context:
space:
mode:
Diffstat (limited to 'server.nix')
-rw-r--r--server.nix59
1 files changed, 45 insertions, 14 deletions
diff --git a/server.nix b/server.nix
index d8f5d2d..fc52410 100644
--- a/server.nix
+++ b/server.nix
@@ -1,7 +1,7 @@
{
fetchurl,
writeText,
- libguestfs-with-appliance,
+ libguestfs-with-appliance-nix,
pkgsCross,
qemu,
runCommand,
@@ -10,15 +10,16 @@
sshPassword,
sshPort,
httpPort,
+ writeScript,
}:
let
- updateName = "remarkable-production-image-3.20.0.92-rm2-public";
+ updateName = "remarkable-production-image-3.27.1.0-rm2-public";
updateArchive = fetchurl {
url =
# TODO: this is not an official source. might be worth authenticating the updates
- "https://storage.googleapis.com/remarkable-versions/${updateName}.swu";
- hash = "sha256-GK3CX/P2MXbX4AZsu8dvu00/id8R1FB9aVvqHOjTJos=";
+ "https://remarkable-software.s3.us-east-2.amazonaws.com/${updateName}.swu";
+ hash = "sha256-QPS2n/S1RqkXe0Tg8bAODnvcG5aUOYsAtPvKYwEYGsI=";
};
xochitlConfig = writeText "xochitl.conf" ''
@@ -51,14 +52,30 @@ let
DHCP=yes
'';
+ usbWaitOnlineService = writeText "usb0-wait-online.service" ''
+ [Unit]
+ Description=Wait for usb0 to be routable
+ Before=network-online.target
+
+ [Service]
+ Type=oneshot
+ ExecStart=/bin/sh -c 'until ip -4 addr show usb0 | grep -q "inet "; do sleep 1; done'
+ RemainAfterExit=yes
+
+ [Install]
+ WantedBy=network-online.target
+ '';
+
xochitlService = writeText "xochitl.service" ''
[Unit]
Description=reMarkable main application
DefaultDependencies=no
Conflicts=shutdown.target
Before=shutdown.target
- Wants=rm-sync.service
- After=var-lib-uboot.mount dbus.socket
+ # add network-online.target to the original dependencies so that xochitl
+ # can bind to the usb0 interface when it starts
+ Wants=rm-sync.service network-online.target
+ After=var-lib-uboot.mount dbus.socket network-online.target
Requires=dbus.socket
[Service]
@@ -72,14 +89,18 @@ let
WantedBy=multi-user.target
'';
- fakefbdev = pkgsCross.armv7l-hf-multiplatform.gcc11Stdenv.mkDerivation {
+ fakefbdev = pkgsCross.armv7l-hf-multiplatform.stdenv.mkDerivation {
name = "fakefbdev";
src = ./fakefbdev;
installFlags = [ "DESTDIR=${placeholder "out"}" ];
};
- kernel = pkgsCross.armv7l-hf-multiplatform.linux_5_4;
+ doNothing = writeScript "do-nothing" ''
+ #!/bin/sh
+ '';
+
+ kernel = pkgsCross.armv7l-hf-multiplatform.linux;
rootfsImage = runCommand "rm-rootfs.ext4" { nativeBuildInputs = [ cpio ]; } ''
cpio -i --file ${updateArchive}
@@ -91,7 +112,7 @@ let
{
nativeBuildInputs = [
qemu
- libguestfs-with-appliance
+ libguestfs-with-appliance-nix
];
}
''
@@ -116,22 +137,34 @@ let
mount /dev/sda2 /
- copy-in ${kernel}/lib/modules /usr/lib
+ download /etc/fstab fstab
+ ! sed -i /unknown/d fstab
+ upload fstab /etc/fstab
+
+ copy-in ${kernel.modules}/lib/modules /usr/lib
upload ${ifnameUdevRule} /etc/udev/rules.d/70-persistent-net.rules
upload ${mmcSymlinkUdevRule} /etc/udev/rules.d/70-mmc-symlinks.rules
upload ${usbNetworkConfig} /etc/systemd/network/10-usb.network
-
upload ${xochitlService} /usr/lib/systemd/system/xochitl.service
+ upload ${usbWaitOnlineService} /etc/systemd/system/usb0-wait-online.service
+ mkdir-p /etc/systemd/system/network-online.target.wants
+ ln-s /etc/systemd/system/usb0-wait-online.service /etc/systemd/system/network-online.target.wants/usb0-wait-online.service
+
# delete any systemd units that hinder or delay startup
rm /usr/lib/systemd/system/wacom_flash.service
rm /usr/lib/systemd/system/memfaultd.service
+ rm /usr/lib/systemd/system/memfault-attributes.service
rm /usr/lib/systemd/system/swupdate.service
rm /usr/lib/systemd/system/swupdate.socket
rm /usr/lib/systemd/system/system-hardening.service
rm /usr/lib/systemd/system/wpa_supplicant.service
+ # stub the usb-ether-once script
+ upload ${doNothing} /usr/sbin/usb-ether-once
+ chmod 0755 /usr/sbin/usb-ether-once
+
upload ${fakefbdev}/lib/libfakefbdev.so /usr/lib/libfakefbdev.so
chmod 0755 /usr/lib/libfakefbdev.so
@@ -157,13 +190,11 @@ writeShellApplication {
qemu-system-aarch64 \
-machine virt \
- -enable-kvm \
- -cpu host,aarch64=off \
-m 2048 \
-kernel ${kernel}/zImage \
-drive if=none,file=./reMder.qcow2,format=qcow2,id=hd \
-device virtio-blk-device,drive=hd \
- -netdev user,hostfwd=tcp::${toString sshPort}-:22,hostfwd=tcp::${toString httpPort}-:80,id=net \
+ -netdev user,net=10.11.99.0/27,host=10.11.99.2,dhcpstart=10.11.99.1,hostfwd=tcp::${toString sshPort}-:22,hostfwd=tcp::${toString httpPort}-:80,id=net \
-device virtio-net-device,netdev=net,mac=${usbMacAddr} \
-append "console=ttyAMA0 rootfstype=ext4 root=/dev/vda2 rw rootwait init=/sbin/init" \
-serial mon:stdio \