{ description = "GKleen's flakey openwrt setup"; inputs = { openwrt = { type = "github"; owner = "openwrt"; repo = "openwrt"; ref = "master"; flake = false; }; flake-utils = { type = "github"; owner = "numtide"; repo = "flake-utils"; ref = "master"; }; nixpkgs = { type = "github"; owner = "NixOS"; repo = "nixpkgs"; ref = "master"; }; openwrt-packages = { url = "git+https://git.openwrt.org/feed/packages.git"; flake = false; }; openwrt-luci = { url = "git+https://git.openwrt.org/project/luci.git"; flake = false; }; openwrt-routing = { url = "git+https://git.openwrt.org/feed/routing.git"; flake = false; }; openwrt-telephony = { url = "git+https://git.openwrt.org/feed/telephony.git"; flake = false; }; }; outputs = { self, openwrt, nixpkgs, flake-utils, ... }@inputs: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; fixWrapper = pkgs.runCommand "fix-wrapper" {} '' mkdir -p $out/bin for i in ${pkgs.gcc.cc}/bin/*-gnu-gcc*; do ln -s ${pkgs.gcc}/bin/gcc $out/bin/$(basename "$i") done for i in ${pkgs.gcc.cc}/bin/*-gnu-{g++,c++}*; do ln -s ${pkgs.gcc}/bin/g++ $out/bin/$(basename "$i") done ''; fhs = extraAttrs: pkgs.buildFHSUserEnvBubblewrap ({ name = "openwrt-env"; multiPkgs = null; inherit targetPkgs; extraOutputsToInstall = [ "dev" ]; profile = '' export NIX_HARDENING_ENABLE= ''; } // extraAttrs); targetPkgs = pkgs: with pkgs; [ binutils file fixWrapper gcc getopt gettext git gnumake openssl patch perl python2 python3 rsync subversion systemd unzip wget which ncurses zlib # zlib.static # glibc.static pkgconfig ]; openwrtWithPackages = pkgs.stdenv.mkDerivation { name = "openwrt-with-packages"; src = openwrt; patchPhase = let feedsConf = pkgs.writeText "feeds.conf" '' src-link packages ${inputs.openwrt-packages} src-link luci ${inputs.openwrt-luci} src-link routing ${inputs.openwrt-routing} src-link telephony ${inputs.openwrt-telephony} ''; in '' rm feeds.conf.default cp ${feedsConf} feeds.conf ''; buildPhase = '' ${let runScript = pkgs.writeShellScript "build" '' ./scripts/feeds update -a ./scripts/feeds install -a ''; in fhs { inherit runScript; }}/bin/openwrt-env ''; installPhase = '' cp -r . $out ''; }; in { devShell = pkgs.mkShell { name = "openwrt"; shellHook = let setup = pkgs.writeText "setup" '' set -ex function unpackPhase() { ${pkgs.rsync}/bin/rsync --chmod=u+wX -rlptD ${openwrtWithPackages}/. ${./files}/. ./. patchDir=$(mktemp -d patches.XXXXXXXXXX) ${pkgs.rsync}/bin/rsync --chmod=u+wX -rlptD ${./patches}/. "$patchDir/." while IFS= read -r -d $'\0' sopsFile; do ${pkgs.sops}/bin/sops --output="''${sopsFile%.sops}" --decrypt "''${sopsFile}" rm "''${sopsFile}" done < <(find ./. "$patchDir" -type f -name '*.sops' -print0) while IFS= read -r -d $'\0' patchFile; do patch -p1 --batch <$patchFile done < <(find "$patchDir" -type f -name '*.patch' -print0) } function buildPhase() { make -j V=sc } set +ex ''; in "exec -- ${fhs { runScript = "bash --init-file ${setup}"; }}/bin/openwrt-env"; }; packages = { inherit openwrtWithPackages; }; }); }