liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

tplink-safeloader.nix (2036B)


      1 {
      2   config
      3 , pkgs
      4 , lib
      5 , ...
      6 }:
      7 let
      8   inherit (lib) mkOption types concatStringsSep;
      9   o = config.system.outputs;
     10   cfg = config.tplink-safeloader;
     11 in {
     12   options.tplink-safeloader = {
     13     board = mkOption {
     14       type = types.str;
     15     };
     16   };
     17   options.system.outputs = {
     18     tplink-safeloader = mkOption {
     19       type = types.package;
     20       description = ''
     21         tplink-safeloader
     22         *****************
     23 
     24         For creating 'safeloader' images for tp-link devices.
     25 
     26         These can be flashed to the device using the firmware update feature
     27         in the TP-link web UI or the OEM bootloader recovery: Use something
     28         sharp to hold the 'reset' button while turning on the router until
     29         only the orange LED remains lit. The router will assume IP address
     30         192.168.0.1 and expect you to take 192.168.0.5 on one of the LAN ports.
     31         On NixOS, use something like::
     32 
     33             networking.interfaces.enp0s20f0u1c2 = {
     34               ipv4.addresses = [ {
     35                 address = "192.168.0.5";
     36                 prefixLength = 24;
     37               } ];
     38             };
     39             networking.networkmanager = {
     40                 unmanaged = [ "enp0s20f0u1c2" ];
     41             };
     42 
     43         This connection is rather somewhat temperamental, it may take a couple
     44         of attempts, possibly re-attaching the USB dongle and running
     45         ``systemctl restart network-start.service``. The web interface does not
     46         give accurate feedback (the progress bar is a lie), so you may want
     47         to upload the firmware using ``curl -F firmware=@result http://192.168.0.1/f2.htm``.
     48         After this shows a 'success' JSON, the image still needs to be
     49         transferred from memory to flash, so be patient.
     50       '';
     51     };
     52   };
     53   config = {
     54     system.outputs = rec {
     55       tplink-safeloader =
     56         pkgs.runCommand "tplink" { nativeBuildInputs = with pkgs.pkgsBuildBuild; [ firmware-utils ];  } ''
     57         tplink-safeloader -B "${cfg.board}" -k "${o.uimage}" -r "${o.rootfs}" -o $out
     58         '';
     59     };
     60   };
     61 }