2022-04-27 22:39:18 +02:00
|
|
|
# nix-openwrt-imagebuilder
|
|
|
|
|
|
|
|
Generate OpenWRT images from Nix derivations using the official
|
|
|
|
ImageBuilders that are provided upstream.
|
2022-05-09 15:44:33 +02:00
|
|
|
|
|
|
|
For OpenWRT releases since 19.07 there is profile helper functionality
|
|
|
|
that helps you find the proper image specification (target, variant)
|
|
|
|
according to your hardware's profile name.
|
|
|
|
|
|
|
|
## Background
|
|
|
|
|
|
|
|
In an ideal world, OpenWRT would be built from source in many
|
|
|
|
fine-grained Nix derivations. Until someone implements that (please
|
|
|
|
do!), this project exists to reuse the binary ImageBuilders that are
|
|
|
|
included in every OpenWRT release. They are only available for
|
|
|
|
x86_64-linux hosts.
|
|
|
|
|
|
|
|
The ImageBuilder can generate new *sysupgrade* images with a
|
|
|
|
customized set of packages and included files. **Caveat:** It cannot
|
|
|
|
build *factory* images for a first-time installation on the vendor
|
|
|
|
firmware.
|
|
|
|
|
|
|
|
## Usage with vanilla Nix
|
|
|
|
|
|
|
|
```nix
|
|
|
|
let
|
|
|
|
openwrt-imagebuilder = ../nix-openwrt-imagebuilder;
|
|
|
|
|
2022-06-23 03:32:09 +02:00
|
|
|
openwrtSystem = import (openwrt-imagebuilder + "/lib/openwrt-system.nix");
|
|
|
|
|
|
|
|
sys = openwrtSystem {
|
|
|
|
pkgs = import <nixpkgs> { };
|
|
|
|
modules = [
|
|
|
|
({ pkgs, ... }: {
|
|
|
|
|
|
|
|
# find target/variant for an old Fritzbox
|
2022-06-23 23:20:00 +02:00
|
|
|
build.profile = "avm_fritz7412";
|
|
|
|
|
|
|
|
system.settings = {
|
|
|
|
hostname = "testrouter";
|
|
|
|
description = "nix-openwrt-imagebuilder example";
|
|
|
|
};
|
2022-06-23 03:32:09 +02:00
|
|
|
|
|
|
|
# add package to include in the image, ie. packages that you don't
|
|
|
|
# want to install manually later
|
2022-06-23 16:40:29 +02:00
|
|
|
packages.include = [ "tcpdump" ];
|
2022-06-23 03:32:09 +02:00
|
|
|
|
|
|
|
services.disabled = [ "dnsmasq" ];
|
|
|
|
|
2022-06-24 00:27:14 +02:00
|
|
|
wireless.interfaces.ap0 = {
|
|
|
|
device = "radio0";
|
|
|
|
network = "lan";
|
|
|
|
mode = "ap";
|
|
|
|
ssid = "Test AP";
|
|
|
|
};
|
2022-06-23 03:32:09 +02:00
|
|
|
|
|
|
|
})
|
|
|
|
];
|
2022-05-09 15:44:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
# actually build the image
|
2022-06-23 03:32:09 +02:00
|
|
|
in sys.config.system.build.image
|
2022-05-09 15:44:33 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage with Nix Flakes
|
|
|
|
|
|
|
|
```nix
|
|
|
|
{
|
|
|
|
inputs = {
|
|
|
|
openwrt-imagebuilder.url = "github:astro/nix-openwrt-imagebuilder";
|
|
|
|
};
|
|
|
|
outputs = { self, nixpkgs, openwrt-imagebuilder }: {
|
2022-06-23 03:32:09 +02:00
|
|
|
packages.x86_64-linux.my-router = let
|
|
|
|
sys = openwrt-imagebuilder.lib.openwrtSystem {
|
2022-05-09 15:44:33 +02:00
|
|
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
2022-06-23 03:32:09 +02:00
|
|
|
modules = [
|
|
|
|
({ pkgs, ... }: {
|
2022-06-23 23:20:00 +02:00
|
|
|
build.profile = "avm_fritz7412";
|
|
|
|
|
|
|
|
system.settings = {
|
|
|
|
hostname = "testrouter";
|
|
|
|
description = "nix-openwrt-imagebuilder example";
|
|
|
|
};
|
2022-06-23 03:32:09 +02:00
|
|
|
|
|
|
|
# add package to include in the image, ie. packages that you don't
|
|
|
|
# want to install manually later
|
2022-06-23 16:40:29 +02:00
|
|
|
packages.include = [ "tcpdump" ];
|
2022-06-23 03:32:09 +02:00
|
|
|
|
|
|
|
services.disabled = [ "dnsmasq" ];
|
|
|
|
|
2022-06-24 00:27:14 +02:00
|
|
|
wireless.interfaces.ap0 = {
|
|
|
|
device = "radio0";
|
|
|
|
network = "lan";
|
|
|
|
mode = "ap";
|
|
|
|
ssid = "Test AP";
|
|
|
|
};
|
2022-06-23 03:32:09 +02:00
|
|
|
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
|
|
|
in sys.config.system.build.image;
|
2022-05-09 15:44:33 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Refreshing hashes
|
|
|
|
|
2022-06-08 01:21:53 +02:00
|
|
|
Checksums of the `sha256sums` files on downloads.openwrt.org are added
|
|
|
|
to this repository for a few recent releases. To update them, run:
|
2022-05-09 15:44:33 +02:00
|
|
|
|
|
|
|
```bash
|
|
|
|
nix-shell -p nixFlakes
|
2022-06-08 01:21:53 +02:00
|
|
|
nix run .#generate-hashes 21.02.3 # for example
|
2022-05-09 15:44:33 +02:00
|
|
|
git add hashes/*.nix
|
|
|
|
```
|