No description
  • Nix 53.4%
  • Shell 33.5%
  • jq 13.1%
Find a file
sinavir b2f3b9dce5
Some checks failed
Build / Build example.nix (push) Has been cancelled
Build / Build example-19.07.nix (push) Has been cancelled
Build / Build example-x86-64.nix (push) Has been cancelled
Publish every Git push to main to FlakeHub / flakehub-publish (push) Has been cancelled
Publish a flake to flakestry / publish-flake (push) Has been cancelled
init lixcon ap
2026-04-01 01:08:33 +02:00
.github Drop 19.07 from CI (#75) 2026-03-13 15:03:22 +01:00
cache upgrade snapshot 2026-03-31 18:37:41 +02:00
.gitattributes Add .gitignore and .gitattributes 2026-01-19 01:59:21 +01:00
.gitignore Add .gitignore and .gitattributes 2026-01-19 01:59:21 +01:00
builder.nix builder: Remove cachePath from derivation attrs 2026-03-13 19:50:48 +08:00
cached-packages.nix Bring back IFD, don't cache package databases by default 2026-01-19 02:01:45 +01:00
call-packages2nix.nix Fix builder 2026-01-26 18:06:22 +01:00
example-snapshot.nix Add support for apk builds in snapshot release 2026-01-19 01:59:16 +01:00
example-x86-64.nix Use flake-parts 2024-11-28 01:34:56 +01:00
example.nix example.nix: remove accidental hardcoded version 2026-01-20 19:03:32 +01:00
files.nix Fix OpenWrt 25 not installing some virtual packages 2026-03-19 21:13:57 +01:00
flake.lock Use nixpkgs apk-tools 2026-03-07 04:38:20 +01:00
flake.nix Remove alias usage 2026-03-07 04:38:20 +01:00
generate-all-hashes.nix generate-all-hashes: revert fetch all versions in parallel 2026-01-19 03:11:00 +01:00
latest-release.nix latest-release: update 2025-12-19 08:37:25 +00:00
lib.jq lib.jq: Exclude legacy releases in filter_releases 2026-03-11 22:48:51 +01:00
LICENSE LICENSE: add MIT 2022-04-27 22:40:54 +02:00
list-versions.nix Add support for apk builds in snapshot release 2026-01-19 01:59:16 +01:00
list-versions.sh list-versions.sh: Improve filtering functionality 2026-01-19 01:59:21 +01:00
lixcon.nix init lixcon ap 2026-04-01 01:08:33 +02:00
lon.lock init lixcon ap 2026-04-01 01:08:33 +02:00
lon.nix init lixcon ap 2026-04-01 01:08:33 +02:00
openwrt-lib.nix Bring back IFD, don't cache package databases by default 2026-01-19 02:01:45 +01:00
packages2nix.nix Fix builder 2026-01-26 18:06:22 +01:00
packages2nix.sh Bring back IFD, don't cache package databases by default 2026-01-19 02:01:45 +01:00
profiles-list.nix Add support for apk builds in snapshot release 2026-01-19 01:59:16 +01:00
profiles.nix Fix builder 2026-01-26 18:06:22 +01:00
README.md Add support for apk builds in snapshot release 2026-01-19 01:59:16 +01:00
release2nix.nix Remove alias usage 2026-03-07 04:38:20 +01:00
release2nix.sh Use new .targets.json file 2026-03-07 04:38:20 +01:00
releases.nix Add support for apk builds in snapshot release 2026-01-19 01:59:16 +01:00
uci-config init lixcon ap 2026-04-01 01:08:33 +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.

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.runCommand "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.runCommand "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

downloads.openwrt.org appears to be never at rest. That's why we update the cache subdirectory daily with a Github action.

If you still encounter hash mismatch in fixed-output derivation in between these updates, update them yourself:

nix run .#release2nix -- $(nix run .#list-versions -- -l)

If your flake.nix has this project in its inputs, then you can build with your local working copy using nix build --override-input openwrt-imagebuilder git+file:///... .#...