From 25c2a4130147f175071acbdade3face6932e5303 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 5 Jan 2022 18:32:57 +0100 Subject: Initial experimentation --- flake.nix | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 flake.nix (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..4d18a89 --- /dev/null +++ b/flake.nix @@ -0,0 +1,89 @@ +{ + description = "GKleen's flakey openwrt setup"; + + inputs = { + openwrt = { + type = "github"; + owner = "openwrt"; + repo = "openwrt"; + ref = "openwrt-21.02"; + flake = false; + }; + flake-utils = { + type = "github"; + owner = "numtide"; + repo = "flake-utils"; + ref = "master"; + }; + nixpkgs = { + type = "github"; + owner = "NixOS"; + repo = "nixpkgs"; + ref = "master"; + }; + }; + + 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 hardeningDisable=all + ''; + } // 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 + ]; + in { + devShell = pkgs.mkShell { + name = "openwrt"; + shellHook = let + setup = pkgs.writeText "setup" '' + cd $TMPDIR + ${pkgs.rsync}/bin/rsync --chmod D+x,+r,u+w --exclude .keep -rlptD ${openwrt}/. ${./files}/. . + find ${./patches} -type f -name '*.patch' -exec patch '{}' ';'; + ''; + in "exec -- ${fhs { runScript = "bash --init-file ${setup}"; }}/bin/openwrt-env"; + }; + }); +} -- cgit v1.2.3