GithubHelp home page GithubHelp logo

sebtm / nix-openwrt-imagebuilder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from astro/nix-openwrt-imagebuilder

0.0 1.0 0.0 23.78 MB

Build OpenWRT images in Nix derivations

License: MIT License

Nix 100.00%

nix-openwrt-imagebuilder's Introduction

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 hashes 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 .#generate-hashes $(sed -e 's/"//g' latest-release.nix)

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:///... .#...

nix-openwrt-imagebuilder's People

Contributors

astro avatar ehmry avatar github-actions[bot] avatar jfly avatar megheaiulian avatar supersandro2000 avatar tomjnixon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.