diff options
Diffstat (limited to 'flake.nix')
-rw-r--r-- | flake.nix | 78 |
1 files changed, 73 insertions, 5 deletions
@@ -6,7 +6,7 @@ | |||
6 | type = "github"; | 6 | type = "github"; |
7 | owner = "openwrt"; | 7 | owner = "openwrt"; |
8 | repo = "openwrt"; | 8 | repo = "openwrt"; |
9 | ref = "openwrt-21.02"; | 9 | ref = "master"; |
10 | flake = false; | 10 | flake = false; |
11 | }; | 11 | }; |
12 | flake-utils = { | 12 | flake-utils = { |
@@ -21,6 +21,23 @@ | |||
21 | repo = "nixpkgs"; | 21 | repo = "nixpkgs"; |
22 | ref = "master"; | 22 | ref = "master"; |
23 | }; | 23 | }; |
24 | |||
25 | openwrt-packages = { | ||
26 | url = "git+https://git.openwrt.org/feed/packages.git"; | ||
27 | flake = false; | ||
28 | }; | ||
29 | openwrt-luci = { | ||
30 | url = "git+https://git.openwrt.org/project/luci.git"; | ||
31 | flake = false; | ||
32 | }; | ||
33 | openwrt-routing = { | ||
34 | url = "git+https://git.openwrt.org/feed/routing.git"; | ||
35 | flake = false; | ||
36 | }; | ||
37 | openwrt-telephony = { | ||
38 | url = "git+https://git.openwrt.org/feed/telephony.git"; | ||
39 | flake = false; | ||
40 | }; | ||
24 | }; | 41 | }; |
25 | 42 | ||
26 | outputs = { self, openwrt, nixpkgs, flake-utils, ... }@inputs: flake-utils.lib.eachDefaultSystem (system: | 43 | outputs = { self, openwrt, nixpkgs, flake-utils, ... }@inputs: flake-utils.lib.eachDefaultSystem (system: |
@@ -43,7 +60,7 @@ | |||
43 | inherit targetPkgs; | 60 | inherit targetPkgs; |
44 | extraOutputsToInstall = [ "dev" ]; | 61 | extraOutputsToInstall = [ "dev" ]; |
45 | profile = '' | 62 | profile = '' |
46 | export hardeningDisable=all | 63 | export NIX_HARDENING_ENABLE= |
47 | ''; | 64 | ''; |
48 | } // extraAttrs); | 65 | } // extraAttrs); |
49 | targetPkgs = pkgs: with pkgs; [ | 66 | targetPkgs = pkgs: with pkgs; [ |
@@ -74,16 +91,67 @@ | |||
74 | 91 | ||
75 | pkgconfig | 92 | pkgconfig |
76 | ]; | 93 | ]; |
94 | |||
95 | openwrtWithPackages = pkgs.stdenv.mkDerivation { | ||
96 | name = "openwrt-with-packages"; | ||
97 | src = openwrt; | ||
98 | patchPhase = let | ||
99 | feedsConf = pkgs.writeText "feeds.conf" '' | ||
100 | src-link packages ${inputs.openwrt-packages} | ||
101 | src-link luci ${inputs.openwrt-luci} | ||
102 | src-link routing ${inputs.openwrt-routing} | ||
103 | src-link telephony ${inputs.openwrt-telephony} | ||
104 | ''; | ||
105 | in '' | ||
106 | rm feeds.conf.default | ||
107 | cp ${feedsConf} feeds.conf | ||
108 | ''; | ||
109 | buildPhase = '' | ||
110 | ${let | ||
111 | runScript = pkgs.writeShellScript "build" '' | ||
112 | ./scripts/feeds update -a | ||
113 | ./scripts/feeds install -a | ||
114 | ''; | ||
115 | in fhs { inherit runScript; }}/bin/openwrt-env | ||
116 | ''; | ||
117 | installPhase = '' | ||
118 | cp -r . $out | ||
119 | ''; | ||
120 | }; | ||
77 | in { | 121 | in { |
78 | devShell = pkgs.mkShell { | 122 | devShell = pkgs.mkShell { |
79 | name = "openwrt"; | 123 | name = "openwrt"; |
80 | shellHook = let | 124 | shellHook = let |
81 | setup = pkgs.writeText "setup" '' | 125 | setup = pkgs.writeText "setup" '' |
82 | cd $TMPDIR | 126 | set -ex |
83 | ${pkgs.rsync}/bin/rsync --chmod D+x,+r,u+w --exclude .keep -rlptD ${openwrt}/. ${./files}/. . | 127 | |
84 | find ${./patches} -type f -name '*.patch' -exec patch '{}' ';'; | 128 | function unpackPhase() { |
129 | ${pkgs.rsync}/bin/rsync --chmod=u+wX -rlptD ${openwrtWithPackages}/. ${./files}/. ./. | ||
130 | |||
131 | patchDir=$(mktemp -d patches.XXXXXXXXXX) | ||
132 | ${pkgs.rsync}/bin/rsync --chmod=u+wX -rlptD ${./patches}/. "$patchDir/." | ||
133 | |||
134 | while IFS= read -r -d $'\0' sopsFile; do | ||
135 | ${pkgs.sops}/bin/sops --output="''${sopsFile%.sops}" --decrypt "''${sopsFile}" | ||
136 | rm "''${sopsFile}" | ||
137 | done < <(find ./. "$patchDir" -type f -name '*.sops' -print0) | ||
138 | |||
139 | while IFS= read -r -d $'\0' patchFile; do | ||
140 | patch -p1 --batch <$patchFile | ||
141 | done < <(find "$patchDir" -type f -name '*.patch' -print0) | ||
142 | } | ||
143 | |||
144 | function buildPhase() { | ||
145 | make -j V=sc | ||
146 | } | ||
147 | |||
148 | set +ex | ||
85 | ''; | 149 | ''; |
86 | in "exec -- ${fhs { runScript = "bash --init-file ${setup}"; }}/bin/openwrt-env"; | 150 | in "exec -- ${fhs { runScript = "bash --init-file ${setup}"; }}/bin/openwrt-env"; |
87 | }; | 151 | }; |
152 | |||
153 | packages = { | ||
154 | inherit openwrtWithPackages; | ||
155 | }; | ||
88 | }); | 156 | }); |
89 | } | 157 | } |