about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMalte Voos <git@mal.tc>2024-12-19 21:57:44 +0100
committerMalte Voos <git@mal.tc>2024-12-19 21:58:25 +0100
commit806dc1ed43be0e638fc1d60881afdae812d0e4e6 (patch)
tree5dc850e823e1ebf111fd7c9600361bdcab88f70e
parentdf4d1f249b631d8dc19db846cdb9deb4e0d01f3b (diff)
downloadreMder-806dc1ed43be0e638fc1d60881afdae812d0e4e6.tar.gz
reMder-806dc1ed43be0e638fc1d60881afdae812d0e4e6.zip
switch to rmpp image
-rw-r--r--README.md2
-rw-r--r--client.nix33
-rw-r--r--flake.lock17
-rw-r--r--flake.nix204
-rw-r--r--server.nix132
5 files changed, 191 insertions, 197 deletions
diff --git a/README.md b/README.md
index 44e6605..45b3933 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ interface's PDF rendering functionality to render your documents. As a result,
 it should be able to render any reMarkable document, in particular those
 created on newer firmware versions.
 
-Currently, reMder uses firmware version v3.10.2.2063.
+Currently, reMder uses firmware version v3.11.2.5.
 
 ## Building
 
diff --git a/client.nix b/client.nix
new file mode 100644
index 0000000..67c083c
--- /dev/null
+++ b/client.nix
@@ -0,0 +1,33 @@
+{ writeShellApplication, curl, openssh, sshpass, rsync, sshPassword, sshPort
+, httpPort }:
+
+writeShellApplication {
+  name = "reMder-client";
+
+  runtimeInputs = [ curl openssh sshpass rsync ];
+
+  text = let
+    ssh =
+      "sshpass -p ${sshPassword} ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p ${
+        toString sshPort
+      }";
+    guest = "root@127.0.0.1";
+    documentDir = "/home/root/.local/share/remarkable/xochitl";
+  in ''
+    in="$1"
+    out="$2"
+
+    in_basename="$(basename "$in")"
+
+    ${ssh} ${guest} rm -rf ${documentDir}
+    ${ssh} ${guest} mkdir ${documentDir}
+
+    rsync --rsh="${ssh}" "$in" ${guest}:${documentDir}
+    ${ssh} ${guest} "unzip '${documentDir}/$in_basename' -d ${documentDir}"
+    doc_id="$(${ssh} ${guest} find ${documentDir} -name '\*.metadata' -exec basename {} .metadata '\;')"
+
+    curl -f -o "$out" "http://127.0.0.1:${
+      toString httpPort
+    }/download/$doc_id/placeholder"
+  '';
+}
diff --git a/flake.lock b/flake.lock
index 814cffa..e1d7304 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,21 +1,5 @@
 {
   "nodes": {
-    "ddvk-stuff": {
-      "flake": false,
-      "locked": {
-        "lastModified": 1607373149,
-        "narHash": "sha256-CrP+/BP821xXz4avuGac1+qbNGhWBi1aUkTbpYxB17c=",
-        "owner": "ddvk",
-        "repo": "stuff",
-        "rev": "69158ac525b97294e1dc0e929bc19e50834741d9",
-        "type": "github"
-      },
-      "original": {
-        "owner": "ddvk",
-        "repo": "stuff",
-        "type": "github"
-      }
-    },
     "flake-utils": {
       "inputs": {
         "systems": "systems"
@@ -52,7 +36,6 @@
     },
     "root": {
       "inputs": {
-        "ddvk-stuff": "ddvk-stuff",
         "flake-utils": "flake-utils",
         "nixpkgs": "nixpkgs"
       }
diff --git a/flake.nix b/flake.nix
index 0f2ca48..97a3723 100644
--- a/flake.nix
+++ b/flake.nix
@@ -2,184 +2,30 @@
   inputs = {
     nixpkgs.url = "github:malte-v/nixpkgs/libguestfs-appliance-fix";
     flake-utils.url = "github:numtide/flake-utils";
-    ddvk-stuff = {
-      url = "github:ddvk/stuff";
-      flake = false;
-    };
   };
-  outputs = { self, nixpkgs, flake-utils, ddvk-stuff }: flake-utils.lib.eachDefaultSystem (system:
-    let
-      pkgs = import nixpkgs { inherit system; };
-
-      updateArchive = pkgs.fetchurl {
-        url = "https://updates-download.cloud.remarkable.engineering/build/reMarkable%20Device/reMarkable2/3.10.2.2063/3.10.2.2063_reMarkable2-zKnOgdh8c5.signed";
-        hash = "sha256-2w2hE4EG1i8B5TORn+n0gAIHNhsey/NHMsv+cCApHVQ=";
-      };
-
-      sshPassword = "1234";
-      sshPort = 43922;
-      httpPort = 43980;
-
-      xochitlConfig = pkgs.writeText "xochitl.conf" ''
-        [General]
-        DeveloperPassword=${sshPassword}
-        wifion=false
-        WebInterfaceEnabled=true
-        IdleSuspendDelay=0
-        SuspendPowerOffDelay=0
-      '';
-
-      usbMacAddr = "52:54:00:12:34:56";
-
-      ifnameUdevRule = pkgs.writeText "70-persistent-net.rules" ''
-        SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", \
-          ATTR{address}=="${usbMacAddr}", \
-          ATTR{type}=="1", KERNEL=="eth*", NAME="usb0"
-      '';
-
-      xochitlService = pkgs.writeText "xochitl.service" ''
-        [Unit]
-        Description=reMarkable main application
-        After=home.mount network.target
-
-        [Service]
-        ExecStart=/usr/bin/xochitl --system
-        Restart=always
-        # required to make xochitl run
-        Environment=LD_PRELOAD=/usr/lib/libfakefbdev.so
-
-        [Install]
-        WantedBy=multi-user.target
-      '';
-
-      fakefbdev = pkgs.pkgsCross.remarkable2.gcc11Stdenv.mkDerivation {
-        name = "fakefbdev";
-        src = ./fakefbdev;
-
-        installFlags = [ "DESTDIR=${placeholder "out"}" ];
-      };
-
-      rootfs = pkgs.runCommand "rm-rootfs.qcow2"
-        {
-          nativeBuildInputs = with pkgs; [
-            (python3.withPackages (pypkgs: [ pypkgs.protobuf ]))
-            qemu
-            libguestfs-with-appliance
-          ];
-        } ''
-        python3 ${ddvk-stuff}/extractor/extractor.py ${updateArchive} rootfs.ext4
-
-        qemu-img create -f qcow2 $out 8G
-
-        guestfish --rw --blocksize=512 --add $out <<EOF
-        run
-
-        part-init /dev/sda mbr
-        part-add /dev/sda p 2048    43007
-        part-add /dev/sda p 43008   595967
-        part-add /dev/sda p 595968  1148927
-        part-add /dev/sda p 1148928 14942207
-
-        mkfs vfat /dev/sda1
-        upload rootfs.ext4 /dev/sda2
-        mkfs ext4 /dev/sda3
-        mkfs ext4 /dev/sda4
-
-        mount /dev/sda2 /
-
-        download /etc/fstab fstab
-        ! sed -i 's/mmcblk2p/vda/' fstab
-        upload fstab /etc/fstab
-
-        upload ${ifnameUdevRule} /etc/udev/rules.d/70-persistent-net.rules
-
-        download /lib/systemd/system/dhcpcd.service dhcpcd.service
-        ! sed -i 's/wlan/usb/' dhcpcd.service
-        upload dhcpcd.service /lib/systemd/system/dhcpcd.service
-
-        rm /lib/systemd/system/remarkable-fail.service
-        rm /lib/systemd/system/rm-sync.service
-        upload ${xochitlService} /lib/systemd/system/xochitl.service
-
-        upload ${fakefbdev}/lib/libfakefbdev.so /usr/lib/libfakefbdev.so
-        chmod 0755 /usr/lib/libfakefbdev.so
-
-        mount /dev/sda4 /home
-        cp-a /etc/skel /home/root
-
-        mkdir-p /home/root/.local/share/remarkable/xochitl
-        mkdir-p /home/root/.config/remarkable
-        upload ${xochitlConfig} /home/root/.config/remarkable/xochitl.conf
-
-        EOF
-      '';
-
-      kernel = pkgs.pkgsCross.armv7l-hf-multiplatform.linux_5_4;
-
-      server = pkgs.writeShellApplication {
-        name = "reMder-server";
-
-        runtimeInputs = [ pkgs.qemu ];
-
-        text = ''
-          qemu-img create -b ${rootfs} -F qcow2 -f qcow2 ./reMder.qcow2
-
-          qemu-system-aarch64 \
-              -enable-kvm \
-              -machine virt \
-              -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 \
-              -device virtio-net-device,netdev=net,mac=${usbMacAddr} \
-              -append "console=ttyAMA0 rootfstype=ext4 root=/dev/vda2 rw rootwait init=/sbin/init" \
-              -serial stdio \
-              -monitor none \
-              -nographic
-        '';
-      };
-
-      client = pkgs.writeShellApplication {
-        name = "reMder-client";
-
-        runtimeInputs = with pkgs; [ curl openssh sshpass rsync ];
-
-        text =
-          let
-            ssh = "sshpass -p ${sshPassword} ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p ${toString sshPort}";
-            guest = "root@127.0.0.1";
-            documentDir = "/home/root/.local/share/remarkable/xochitl";
-          in
-          ''
-            in="$1"
-            out="$2"
-
-            in_basename="$(basename "$in")"
-
-            ${ssh} ${guest} rm -rf ${documentDir}
-            ${ssh} ${guest} mkdir ${documentDir}
-
-            rsync --rsh="${ssh}" "$in" ${guest}:${documentDir}
-            ${ssh} ${guest} "unzip '${documentDir}/$in_basename' -d ${documentDir}"
-            doc_id="$(${ssh} ${guest} find ${documentDir} -name '\*.metadata' -exec basename {} .metadata '\;')"
-
-            curl -f -o "$out" "http://127.0.0.1:${toString httpPort}/download/$doc_id/placeholder"
-          '';
-      };
-
-      reMder = pkgs.symlinkJoin {
-        name = "reMder";
-        paths = [ client server ];
-      };
-    in
-    {
-      packages = {
-        inherit reMder fakefbdev;
-      };
-
-      defaultPackage = reMder;
-    }
-  );
+  outputs = { self, nixpkgs, flake-utils }:
+    flake-utils.lib.eachDefaultSystem (system:
+      let
+        pkgs = import nixpkgs { inherit system; };
+
+        sshPassword = "1234";
+        sshPort = 43922;
+        httpPort = 43980;
+
+        server = pkgs.callPackage ./server.nix {
+          inherit sshPassword sshPort httpPort;
+        };
+        client = pkgs.callPackage ./client.nix {
+          inherit sshPassword sshPort httpPort;
+        };
+
+        # reMder = pkgs.symlinkJoin {
+        #   name = "reMder";
+        #   paths = [ client server ];
+        # };
+      in {
+        packages = { inherit server; };
+
+        # defaultPackage = reMder;
+      });
 }
diff --git a/server.nix b/server.nix
new file mode 100644
index 0000000..31462cd
--- /dev/null
+++ b/server.nix
@@ -0,0 +1,132 @@
+{ fetchurl, writeText, libguestfs-with-appliance, pkgsCross, qemu, runCommand
+, writeShellApplication, sshPassword, sshPort, httpPort }:
+let
+  updateName = "remarkable-ct-prototype-image-3.16.1.0-ferrari-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 = "";
+  };
+
+  xochitlConfig = writeText "xochitl.conf" ''
+    [General]
+    DeveloperPassword=${sshPassword}
+    wifion=false
+    WebInterfaceEnabled=true
+    IdleSuspendDelay=0
+    SuspendPowerOffDelay=0
+  '';
+
+  usbMacAddr = "52:54:00:12:34:56";
+
+  ifnameUdevRule = writeText "70-persistent-net.rules" ''
+    SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", \
+      ATTR{address}=="${usbMacAddr}", \
+      ATTR{type}=="1", KERNEL=="eth*", NAME="usb0"
+  '';
+
+  xochitlService = writeText "xochitl.service" ''
+    [Unit]
+    Description=reMarkable main application
+    After=home.mount network.target
+
+    [Service]
+    ExecStart=/usr/bin/xochitl --system
+    Restart=always
+    # required to make xochitl run
+    # Environment=LD_PRELOAD=/usr/lib/libfakefbdev.so # TODO uncomment?
+
+    [Install]
+    WantedBy=multi-user.target
+  '';
+
+  fakefbdev = pkgsCross.remarkable2.gcc11Stdenv.mkDerivation {
+    name = "fakefbdev";
+    src = ./fakefbdev;
+
+    installFlags = [ "DESTDIR=${placeholder "out"}" ];
+  };
+
+  rootfsImage = runCommand "rm-rootfs.ext4" ''
+    cpio -i --file ${updateArchive}
+    gzip -dc ${updateName}.ext4.verity.gz > $out
+  '';
+
+  diskImage = runCommand "rm-disk.qcow2" {
+    nativeBuildInputs = [ qemu libguestfs-with-appliance ];
+  } ''
+    qemu-img create -f qcow2 $out 8G
+
+    guestfish --rw --blocksize=512 --add $out <<EOF
+    run
+
+    part-init /dev/sda mbr
+    part-add /dev/sda p 2048    43007
+    part-add /dev/sda p 43008   595967
+    part-add /dev/sda p 595968  1148927
+    part-add /dev/sda p 1148928 14942207
+
+    mkfs vfat /dev/sda1
+    upload ${rootfsImage} /dev/sda2
+    mkfs ext4 /dev/sda3
+    mkfs ext4 /dev/sda4
+
+    mount /dev/sda2 /
+
+    download /etc/fstab fstab
+    ! sed -i 's/mmcblk2p/vda/' fstab
+    upload fstab /etc/fstab
+
+    upload ${ifnameUdevRule} /etc/udev/rules.d/70-persistent-net.rules
+
+    download /lib/systemd/system/dhcpcd.service dhcpcd.service
+    ! sed -i 's/wlan/usb/' dhcpcd.service
+    upload dhcpcd.service /lib/systemd/system/dhcpcd.service
+
+    rm /lib/systemd/system/remarkable-fail.service
+    rm /lib/systemd/system/rm-sync.service
+    upload ${xochitlService} /lib/systemd/system/xochitl.service
+
+    upload ${fakefbdev}/lib/libfakefbdev.so /usr/lib/libfakefbdev.so
+    chmod 0755 /usr/lib/libfakefbdev.so
+
+    mount /dev/sda4 /home
+    cp-a /etc/skel /home/root
+
+    mkdir-p /home/root/.local/share/remarkable/xochitl
+    mkdir-p /home/root/.config/remarkable
+    upload ${xochitlConfig} /home/root/.config/remarkable/xochitl.conf
+
+    EOF
+  '';
+
+  kernel = pkgsCross.aarch64-linux.linux_5_4;
+
+in writeShellApplication {
+  name = "reMder-server";
+
+  runtimeInputs = [ qemu ];
+
+  text = ''
+    qemu-img create -b ${diskImage} -F qcow2 -f qcow2 ./reMder.qcow2
+
+    qemu-system-aarch64 \
+        -enable-kvm \
+        -machine virt \
+        -cpu host \
+        -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 \
+        -device virtio-net-device,netdev=net,mac=${usbMacAddr} \
+        -append "console=ttyAMA0 rootfstype=ext4 root=/dev/vda2 rw rootwait init=/sbin/init" \
+        -serial stdio \
+        -monitor none \
+        -nographic
+  '';
+}