diff options
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..4d18a89 --- /dev/null +++ b/flake.nix | |||
@@ -0,0 +1,89 @@ | |||
1 | { | ||
2 | description = "GKleen's flakey openwrt setup"; | ||
3 | |||
4 | inputs = { | ||
5 | openwrt = { | ||
6 | type = "github"; | ||
7 | owner = "openwrt"; | ||
8 | repo = "openwrt"; | ||
9 | ref = "openwrt-21.02"; | ||
10 | flake = false; | ||
11 | }; | ||
12 | flake-utils = { | ||
13 | type = "github"; | ||
14 | owner = "numtide"; | ||
15 | repo = "flake-utils"; | ||
16 | ref = "master"; | ||
17 | }; | ||
18 | nixpkgs = { | ||
19 | type = "github"; | ||
20 | owner = "NixOS"; | ||
21 | repo = "nixpkgs"; | ||
22 | ref = "master"; | ||
23 | }; | ||
24 | }; | ||
25 | |||
26 | outputs = { self, openwrt, nixpkgs, flake-utils, ... }@inputs: flake-utils.lib.eachDefaultSystem (system: | ||
27 | let | ||
28 | pkgs = nixpkgs.legacyPackages.${system}; | ||
29 | |||
30 | fixWrapper = pkgs.runCommand "fix-wrapper" {} '' | ||
31 | mkdir -p $out/bin | ||
32 | for i in ${pkgs.gcc.cc}/bin/*-gnu-gcc*; do | ||
33 | ln -s ${pkgs.gcc}/bin/gcc $out/bin/$(basename "$i") | ||
34 | done | ||
35 | for i in ${pkgs.gcc.cc}/bin/*-gnu-{g++,c++}*; do | ||
36 | ln -s ${pkgs.gcc}/bin/g++ $out/bin/$(basename "$i") | ||
37 | done | ||
38 | ''; | ||
39 | |||
40 | fhs = extraAttrs: pkgs.buildFHSUserEnvBubblewrap ({ | ||
41 | name = "openwrt-env"; | ||
42 | multiPkgs = null; | ||
43 | inherit targetPkgs; | ||
44 | extraOutputsToInstall = [ "dev" ]; | ||
45 | profile = '' | ||
46 | export hardeningDisable=all | ||
47 | ''; | ||
48 | } // extraAttrs); | ||
49 | targetPkgs = pkgs: with pkgs; [ | ||
50 | binutils | ||
51 | file | ||
52 | fixWrapper | ||
53 | gcc | ||
54 | getopt | ||
55 | gettext | ||
56 | git | ||
57 | gnumake | ||
58 | openssl | ||
59 | patch | ||
60 | perl | ||
61 | python2 | ||
62 | python3 | ||
63 | rsync | ||
64 | subversion | ||
65 | systemd | ||
66 | unzip | ||
67 | wget | ||
68 | which | ||
69 | |||
70 | ncurses | ||
71 | zlib | ||
72 | # zlib.static | ||
73 | # glibc.static | ||
74 | |||
75 | pkgconfig | ||
76 | ]; | ||
77 | in { | ||
78 | devShell = pkgs.mkShell { | ||
79 | name = "openwrt"; | ||
80 | shellHook = let | ||
81 | setup = pkgs.writeText "setup" '' | ||
82 | cd $TMPDIR | ||
83 | ${pkgs.rsync}/bin/rsync --chmod D+x,+r,u+w --exclude .keep -rlptD ${openwrt}/. ${./files}/. . | ||
84 | find ${./patches} -type f -name '*.patch' -exec patch '{}' ';'; | ||
85 | ''; | ||
86 | in "exec -- ${fhs { runScript = "bash --init-file ${setup}"; }}/bin/openwrt-env"; | ||
87 | }; | ||
88 | }); | ||
89 | } | ||