Go to file
Thomas Nixon b4379cf745 only download packages which might be required
Package files are parsed to determine the dependency package
dependencies, and these are used to find the packages to download which
might be required.

This doesn't implement every detail of the opkg dependency resolution,
but instead tries to find all packages which might be required.
In particular, no attempt is made to resolve dependencies on virtual
packages (which may be provided by multiple packages) to a single
package (all providing packages are downloaded).
2022-06-05 22:28:50 +01:00
hashes Update hashes 2022-06-01 18:47:04 +02:00
builder.nix only download packages which might be required 2022-06-05 22:28:50 +01:00
example.nix example.nix: use flake interface when building from flake 2022-04-29 00:03:47 +02:00
files.nix only download packages which might be required 2022-06-05 22:28:50 +01:00
flake.lock generate-hashes, flakify 2022-04-27 22:25:39 +02:00
flake.nix example.nix: use flake interface when building from flake 2022-04-29 00:03:47 +02:00
generate-hashes.nix generate-hashes: log fetch or parse errors 2022-05-28 09:41:07 -05:00
LICENSE LICENSE: add MIT 2022-04-27 22:40:54 +02:00
profiles-list.nix profiles-list: generate for all known releases 2022-04-28 03:12:41 +02:00
profiles.nix profiles: split identifyProfiles into identifyProfile 2022-04-28 23:59:17 +02:00
README.md README: fix example syntax 2022-05-09 15:49:23 +02:00

nix-openwrt-imagebuilder

Generate OpenWRT images from Nix derivations using the official ImageBuilders that are provided upstream.

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

let
  pkgs = import <nixpkgs> {};

  # use fetchurl, Hydra inputs, or something else to refer to this project
  openwrt-imagebuilder = ../nix-openwrt-imagebuilder;

  profiles = import (openwrt-imagebuilder + "/profiles.nix") { inherit pkgs; };

  # example: find target/variant for an old Fritzbox
  config = profiles.identifyProfile "avm_fritz7412" // {
    # add package to include in the image, ie. packages that you don't
    # want to install manually later
    packages = [ "tcpdump" ];

    disabledServices = [ "dnsmasq" ];

    # include files in the images.
    # to set UCI configuration, create a uci-defauts scripts as per
    # official OpenWRT ImageBuilder recommendation.
    files = pkgs.runCommandNoCC "image-files" {} ''
      mkdir -p $out/etc/uci-defaults
      cat > $out/etc/uci-defaults/99-custom <<EOF
      uci -q batch << EOI
      set system.@system[0].hostname='testap'
      commit
      EOI
      EOF
    '';
  };

in
  # actually build the image
  import (openwrt-imagebuilder + "/builder.nix") config

Usage with Nix Flakes

{
  inputs = {
    openwrt-imagebuilder.url = "github:astro/nix-openwrt-imagebuilder";
  };
  outputs = { self, nixpkgs, openwrt-imagebuilder }: {
    packages.x86_64-linux.my-router =
      let
        pkgs = nixpkgs.legacyPackages.x86_64-linux;

        profiles = openwrt-imagebuilder.lib.profiles { inherit pkgs; };

        config = profiles.identifyProfile "avm_fritz7412" // {
          # add package to include in the image, ie. packages that you don't
          # want to install manually later
          packages = [ "tcpdump" ];

          disabledServices = [ "dnsmasq" ];

          # include files in the images.
          # to set UCI configuration, create a uci-defauts scripts as per
          # official OpenWRT ImageBuilder recommendation.
          files = pkgs.runCommandNoCC "image-files" {} ''
            mkdir -p $out/etc/uci-defaults
            cat > $out/etc/uci-defaults/99-custom <<EOF
            uci -q batch << EOI
            set system.@system[0].hostname='testap'
            commit
            EOI
            EOF
          '';
        };

      in
        openwrt-imagebuilder.lib.build config;
  };
}

Refreshing hashes

Checksums of the sha256sums files on downloads.openwrt.org are add to this repository for a few recent releases. For updating, modify release in generate-hashes.nix, then run:

nix-shell -p nixFlakes
nix run .#generate-hashes
git add hashes/*.nix