commit 74562f4bb50298368100ad1e75ba6fba4659e055 Author: stubbfelnewpc Date: Wed Oct 7 22:18:32 2020 +0200 init commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c434074 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +_* \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0ac91ba --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +MIT No Attribution Copyright 2020 stubbfel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..feaa05b --- /dev/null +++ b/README.md @@ -0,0 +1,93 @@ +# NOIBW - Nix-Openwrt-ImageBuilder-Wrapper + +provide a nix shell, for creating openwrt images by the image builder in declarative way. + +## buildOpenwrt.nix - Base-Nix-Shell File + +This file setup the nix shell with all necessary dependencies and shell environment. + +### Parameter + +```nix +{ + pkgs ? import {}, # nix packages collection + target, # build target + arch, # target architecture + profile, # build profile + version, # openwrt version + packages ? [], # list of user installed packages + manifestPkgs ? "$(cat manifest_packages)", # manifest packages (fetch command) + workingFolder ? "$PWD/_builder" # working folder +}: +``` + +### Commands + +loadBuilder -> load device specific image builder and manifest ("default") packages list: +```sh +# nix-shell --expr 'with import {}; callPackage ./buildOpenwrt.nix {target=""; arch="];}' --pure --run loadBuilder +nix-shell --expr 'with import {}; callPackage ./buildOpenwrt.nix {target="brcm2708"; arch="bcm2708"; version="19.07.4"; profile="rpi"; packages=["luci-ssl"];}' --pure --run loadBuilder +``` + +makeImage -> create image by image builder +```sh +# nix-shell --expr 'with import {}; callPackage ./buildOpenwrt.nix {target=""; arch="];}' --pure --run makeCmakeImageleanImage +nix-shell --expr 'with import {}; callPackage ./buildOpenwrt.nix {target="brcm2708"; arch="bcm2708"; version="19.07.4"; profile="rpi"; packages=["luci-ssl"];}' --pure --run makeImage +``` + +removeBuilder -> remove image builder +```sh +# nix-shell --expr 'with import {}; callPackage ./buildOpenwrt.nix {target=""; arch="];}' --pure --run removeBuilder +nix-shell --expr 'with import {}; callPackage ./buildOpenwrt.nix {target="brcm2708"; arch="bcm2708"; version="19.07.4"; profile="rpi"; packages=["luci-ssl"];}' --pure --run removeBuilder +``` + +makeCleanImage -> remove old image builder, load new image builder and create image +```sh +# nix-shell --expr 'with import {}; callPackage ./buildOpenwrt.nix {target=""; arch="];}' --pure --run makeCleanImage +nix-shell --expr 'with import {}; callPackage ./buildOpenwrt.nix {target="brcm2708"; arch="bcm2708"; version="19.07.4"; profile="rpi"; packages=["luci-ssl"];}' --pure --run makeCleanImage +``` + +created image can be found: +```sh +${workingFolder}/openwrt-imagebuilder-${version}-${target}-$arch}.Linux-x86_64/bin/targets/${target}/${arch} +``` + +## Device File + +Instead of using the `--expr` option, you can write the build parameter into a "device file", which describe the target device image. + +```nix +{ pkgs ? import {}}: +pkgs.callPackage /buildOpenwrt.nix { + target = ""; + arch = ""; + version= ""; + profile = "]; +} +``` + +pi example +```nix +{ pkgs ? import {}}: +pkgs.callPackage ../buildOpenwrt.nix { + target = "brcm2708"; + arch = "bcm2708"; + version= "19.07.4"; + profile = "rpi"; + packages = [ + "luci-ssl" + "luci-app-adblock" + "luci-app-openvpn" + ]; +} +``` + +build an image with: + +```sh +# nix-shell .nix --run makeCleanImage +nix-shell devices/pi-img.nix --run makeCleanImage +``` + +For more example see `devices` folder. \ No newline at end of file diff --git a/buildOpenwrt.nix b/buildOpenwrt.nix new file mode 100644 index 0000000..e5d2949 --- /dev/null +++ b/buildOpenwrt.nix @@ -0,0 +1,63 @@ +{ + pkgs ? import {}, + target, + arch, + profile, + version, + packages ? [], + manifestPkgs ? "$(cat manifest_packages)", + workingFolder ? "$PWD/_builder" +}: +pkgs.mkShell { + name = "openwrt-build-${target}-${arch}-${profile}"; + buildInputs = with pkgs; [ + perl + quilt + ccache + libxslt + gcc + gengetopt + subversion + git + python3Full + rsync + man_db + gawk + gettext + unzip + file + wget + ncurses5.dev + zlib.static + gnumake + which + bash + coreutils + wget + gnutar + curl + cacert + ]; + shellHook = + '' + export WORKING_FOLDER=$(realpath ${workingFolder}) + function loadBuilder() { + curl -s https://downloads.openwrt.org/releases/${version}/targets/${target}/${arch}/openwrt-imagebuilder-${version}-${target}-${arch}.Linux-x86_64.tar.xz | tar xvJ -C $WORKING_FOLDER + curl -s https://downloads.openwrt.org/releases/${version}/targets/${target}/${arch}/openwrt-${version}-${target}-${arch}.manifest | cut -f 1 -d ' ' | tr '\n' ' ' > $WORKING_FOLDER/openwrt-imagebuilder-${version}-${target}-${arch}.Linux-x86_64/manifest_packages + } + + function removeBuilder() { + rm -rf $WORKING_FOLDER/openwrt-imagebuilder-${version}-${target}-${arch}.Linux-x86_64 + } + + function makeImage() { + cd $WORKING_FOLDER/openwrt-imagebuilder-${version}-${target}-${arch}.Linux-x86_64 + MANIFEST_PKGS=${manifestPkgs} + make image PROFILE=${profile} PACKAGES="$MANIFEST_PKGS ${toString packages}" + } + + function makeCleanImage() { + removeBuilder && loadBuilder && makeImage + } + ''; +} diff --git a/devices/gli-repeater-img.nix b/devices/gli-repeater-img.nix new file mode 100644 index 0000000..9d45a69 --- /dev/null +++ b/devices/gli-repeater-img.nix @@ -0,0 +1,12 @@ +{ pkgs ? import {}}: +pkgs.callPackage ../buildOpenwrt.nix { + target = "ar71xx"; + arch = "generic"; + version= "19.07.4"; + profile = "gl-inet-6416A-v1"; + packages = [ + "luci-ssl" + "luci-proto-wireguard" + "luci-app-wireguard" + ]; +} diff --git a/devices/my-router-img.nix b/devices/my-router-img.nix new file mode 100644 index 0000000..95a325a --- /dev/null +++ b/devices/my-router-img.nix @@ -0,0 +1,17 @@ +{ pkgs ? import {}}: +pkgs.callPackage ../buildOpenwrt.nix { + target = "mvebu"; + arch = "cortexa9"; + version= "19.07.4"; + profile = "linksys_wrt1200ac"; + packages = [ + "adblock" + "luci-ssl" + "luci-proto-wireguard" + "luci-app-wireguard" + "luci-app-adblock" + "luci-app-openvpn" + "openvpn-openssl" + "tcpdump-mini" + ]; +} diff --git a/devices/pi-img.nix b/devices/pi-img.nix new file mode 100644 index 0000000..45ecb7e --- /dev/null +++ b/devices/pi-img.nix @@ -0,0 +1,8 @@ +{ pkgs ? import {}}: +pkgs.callPackage ../buildOpenwrt.nix { + target = "brcm2708"; + arch = "bcm2708"; + version= "19.07.4"; + profile = "rpi"; + packages = ["luci-ssl"]; +} diff --git a/list-user-installed-packages_since_last_flash.sh b/list-user-installed-packages_since_last_flash.sh new file mode 100644 index 0000000..721634e --- /dev/null +++ b/list-user-installed-packages_since_last_flash.sh @@ -0,0 +1,22 @@ +#!/bin/sh +FLASH_TIME="$(awk ' +$1 == "Installed-Time:" && ($2 < OLDEST || OLDEST=="") { + OLDEST=$2 +} +END { + print OLDEST +} +' /usr/lib/opkg/status)" + +awk -v FT="$FLASH_TIME" ' +$1 == "Package:" { + PKG=$2 + USR="" +} +$1 == "Status:" && $3 ~ "user" { + USR=1 +} +$1 == "Installed-Time:" && USR && $2 != FT { + print PKG +} +' /usr/lib/opkg/status | sort \ No newline at end of file