init commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
_*
|
||||||
15
LICENSE
Normal file
15
LICENSE
Normal file
@@ -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.
|
||||||
93
README.md
Normal file
93
README.md
Normal file
@@ -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 <nixpkgs> {}, # 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 <nixpkgs> {}; callPackage ./buildOpenwrt.nix {target="<target_name>"; arch="<arch_name"; version="<openwrt_release_version>"; profile="<profile_name>"; packages=[<list_of_user_packages>];}' --pure --run loadBuilder
|
||||||
|
nix-shell --expr 'with import <nixpkgs> {}; 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 <nixpkgs> {}; callPackage ./buildOpenwrt.nix {target="<target_name>"; arch="<arch_name"; version="<openwrt_release_version>"; profile="<profile_name>"; packages=[<list_of_user_packages>];}' --pure --run makeCmakeImageleanImage
|
||||||
|
nix-shell --expr 'with import <nixpkgs> {}; 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 <nixpkgs> {}; callPackage ./buildOpenwrt.nix {target="<target_name>"; arch="<arch_name"; version="<openwrt_release_version>"; profile="<profile_name>"; packages=[<list_of_user_packages>];}' --pure --run removeBuilder
|
||||||
|
nix-shell --expr 'with import <nixpkgs> {}; 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 <nixpkgs> {}; callPackage ./buildOpenwrt.nix {target="<target_name>"; arch="<arch_name"; version="<openwrt_release_version>"; profile="<profile_name>"; packages=[<list_of_user_packages>];}' --pure --run makeCleanImage
|
||||||
|
nix-shell --expr 'with import <nixpkgs> {}; 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 <nixpkgs> {}}:
|
||||||
|
pkgs.callPackage <path_to_repo>/buildOpenwrt.nix {
|
||||||
|
target = "<target_name>";
|
||||||
|
arch = "<arch_name>";
|
||||||
|
version= "<version_number_string>";
|
||||||
|
profile = "<profile_name";
|
||||||
|
packages = [ <list_of_user_packages>];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
pi example
|
||||||
|
```nix
|
||||||
|
{ pkgs ? import <nixpkgs> {}}:
|
||||||
|
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 <path_to_device_file>.nix --run makeCleanImage
|
||||||
|
nix-shell devices/pi-img.nix --run makeCleanImage
|
||||||
|
```
|
||||||
|
|
||||||
|
For more example see `devices` folder.
|
||||||
63
buildOpenwrt.nix
Normal file
63
buildOpenwrt.nix
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
{
|
||||||
|
pkgs ? import <nixpkgs> {},
|
||||||
|
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
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
}
|
||||||
12
devices/gli-repeater-img.nix
Normal file
12
devices/gli-repeater-img.nix
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{ pkgs ? import <nixpkgs> {}}:
|
||||||
|
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"
|
||||||
|
];
|
||||||
|
}
|
||||||
17
devices/my-router-img.nix
Normal file
17
devices/my-router-img.nix
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{ pkgs ? import <nixpkgs> {}}:
|
||||||
|
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"
|
||||||
|
];
|
||||||
|
}
|
||||||
8
devices/pi-img.nix
Normal file
8
devices/pi-img.nix
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{ pkgs ? import <nixpkgs> {}}:
|
||||||
|
pkgs.callPackage ../buildOpenwrt.nix {
|
||||||
|
target = "brcm2708";
|
||||||
|
arch = "bcm2708";
|
||||||
|
version= "19.07.4";
|
||||||
|
profile = "rpi";
|
||||||
|
packages = ["luci-ssl"];
|
||||||
|
}
|
||||||
22
list-user-installed-packages_since_last_flash.sh
Normal file
22
list-user-installed-packages_since_last_flash.sh
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user