diff --git a/modules/outputs.nix b/modules/outputs.nix index fb7c20b..f60e146 100644 --- a/modules/outputs.nix +++ b/modules/outputs.nix @@ -60,6 +60,9 @@ in Combined kernel and FDT in uImage (U-Boot compatible) format ''; }; + tplink-safeloader = mkOption { + type = types.package; + }; u-boot = mkOption { type = types.package; }; diff --git a/modules/outputs/tplink-safeloader.nix b/modules/outputs/tplink-safeloader.nix new file mode 100644 index 0000000..67ab969 --- /dev/null +++ b/modules/outputs/tplink-safeloader.nix @@ -0,0 +1,61 @@ +{ + config +, pkgs +, lib +, ... +}: +let + inherit (lib) mkOption types concatStringsSep; + o = config.system.outputs; + cfg = config.tplink-safeloader; +in { + options.tplink-safeloader = { + board = mkOption { + type = types.str; + }; + }; + options.system.outputs = { + tplink-safeloader = mkOption { + type = types.package; + description = '' + tplink-safeloader + ***************** + + For creating 'safeloader' images for tp-link devices. + + These can be flashed to the device using the firmware update feature + in the TP-link web UI or the OEM bootloader recovery: Use something + sharp to hold the 'reset' button while turning on the router until + only the orange LED remains lit. The router will assume IP address + 192.168.0.1 and expect you to take 192.168.0.5 on one of the LAN ports. + On NixOS, use something like:: + + networking.interfaces.enp0s20f0u1c2 = { + ipv4.addresses = [ { + address = "192.168.0.5"; + prefixLength = 24; + } ]; + }; + networking.networkmanager = { + unmanaged = [ "enp0s20f0u1c2" ]; + }; + + This connection is rather somewhat temperamental, it may take a couple + of attempts, possibly re-attaching the USB dongle and running + ``systemctl restart network-start.service``. The web interface does not + give accurate feedback (the progress bar is a lie), so you may want + to upload the firmware using ``curl -F firmware=@result http://192.168.0.1/f2.htm``. + After this shows a 'success' JSON, the image still needs to be + transferred from memory to flash, so be patient. + ''; + }; + }; + config = { + system.outputs = rec { + tplink-safeloader = + pkgs.runCommand "tplink" { nativeBuildInputs = with pkgs.pkgsBuildBuild; [ firmware-utils ]; } '' + tplink-safeloader -B "${cfg.board}" -k "${o.uimage}" -r "${o.rootfs}" -o $out + ''; + }; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index 823d560..97d15b9 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -58,7 +58,8 @@ in { anoia = callPackage ./anoia {}; fennel = callPackage ./fennel {}; fennelrepl = callPackage ./fennelrepl {}; - firewallgen = callPackage ./firewallgen {}; + firewallgen = callPackage ./firewallgen {}; + firmware-utils = callPackage ./firmware-utils {}; gen_init_cpio = callPackage ./gen_init_cpio {}; go-l2tp = callPackage ./go-l2tp {}; hi = callPackage ./hi {}; diff --git a/pkgs/firmware-utils/default.nix b/pkgs/firmware-utils/default.nix new file mode 100644 index 0000000..5c8e1f3 --- /dev/null +++ b/pkgs/firmware-utils/default.nix @@ -0,0 +1,24 @@ +{ stdenv +, fetchFromGitHub +, cmake +, zlib +, openssl +}: + +stdenv.mkDerivation { + pname = "firmware-utils"; + version = "snapshot"; + + src = fetchFromGitHub { + owner = "openwrt"; + repo = "firmware-utils"; + rev = "e87f23849790a7c77b4cd0e8ef0384da188174e5"; + hash = "sha256-285Isf9sRuUt5S56SozgqpnS0+LOfnvpxpnWLwuWYUk="; + }; + + nativeBuildInputs = [ + cmake + zlib + openssl + ]; +}