liminix

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

tplink-safeloader.nix (2037B)


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