diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2022-01-11 20:02:34 +0100 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2022-01-11 20:02:34 +0100 |
| commit | 10100688c3473235b04574bba5826791ac85c233 (patch) | |
| tree | 5cf48f9be3632adc4f718716afff709f18589560 | |
| parent | 122285b4047a29c3ab86da01a9e0498e89f04d7d (diff) | |
| download | ap01-10100688c3473235b04574bba5826791ac85c233.tar ap01-10100688c3473235b04574bba5826791ac85c233.tar.gz ap01-10100688c3473235b04574bba5826791ac85c233.tar.bz2 ap01-10100688c3473235b04574bba5826791ac85c233.tar.xz ap01-10100688c3473235b04574bba5826791ac85c233.zip | |
...
| -rw-r--r-- | flake.nix | 116 |
1 files changed, 59 insertions, 57 deletions
| @@ -221,63 +221,65 @@ | |||
| 221 | 221 | ||
| 222 | buildWrtApp = { | 222 | buildWrtApp = { |
| 223 | type = "app"; | 223 | type = "app"; |
| 224 | program = toString (pkgs.writeShellScript "build-wrapper" (let | 224 | program = toString (pkgs.writers.writePython3 "build" {} '' |
| 225 | buildPy = pkgs.writers.writePython3 "build" {} '' | 225 | from tempfile import TemporaryDirectory |
| 226 | from tempfile import TemporaryDirectory | 226 | import os |
| 227 | import os | 227 | import subprocess |
| 228 | import subprocess | 228 | import argparse |
| 229 | import argparse | 229 | from pathlib import Path |
| 230 | from pathlib import Path | 230 | |
| 231 | 231 | parser = argparse.ArgumentParser(prog="build", | |
| 232 | parser = argparse.ArgumentParser(prog="build", | 232 | formatter_class=argparse.ArgumentDefaultsHelpFormatter # noqa: E501 |
| 233 | formatter_class=argparse.ArgumentDefaultsHelpFormatter # noqa: E501 | 233 | ) |
| 234 | ) | 234 | parser.add_argument('-C', '--directory', |
| 235 | parser.add_argument('-C', '--directory', | 235 | dest='dir', |
| 236 | dest='dir', | 236 | metavar='DIRECTORY', |
| 237 | metavar='DIRECTORY', | 237 | type=Path, |
| 238 | type=Path, | 238 | default=Path('./result'), |
| 239 | default=Path('./result'), | 239 | help='Change to this directory before doing anything' |
| 240 | help='Change to this directory before doing anything' | 240 | ) |
| 241 | ) | 241 | parser.add_argument('--copy-to', |
| 242 | parser.add_argument('--copy-to', | 242 | dest='copyTo', |
| 243 | dest='copyTo', | 243 | metavar='FILE', |
| 244 | metavar='FILE', | 244 | type=Path, |
| 245 | type=Path, | 245 | default='/srv/tftp/' + Path.cwd().name + '.bin', |
| 246 | default='/srv/tftp/' + Path.cwd().name + '.bin', | 246 | help='Copy result image here' |
| 247 | help='Copy result image here' | 247 | ) |
| 248 | ) | 248 | parser.add_argument('--copy-to-no-sudo', |
| 249 | parser.add_argument('--copy-to-no-sudo', | 249 | dest='copyToSudo', |
| 250 | dest='copyToSudo', | 250 | action='store_false', |
| 251 | action='store_false', | 251 | help='Use sudo to copy result image' |
| 252 | help='Use sudo to copy result image' | 252 | ) |
| 253 | ) | 253 | parser.add_argument('--copy-image', |
| 254 | parser.add_argument('--copy-image', | 254 | dest='image', |
| 255 | dest='image', | 255 | default='bin/targets/ath79/generic/openwrt-ath79-generic-ubnt_unifiac-pro-initramfs-kernel.bin', # noqa: E501 |
| 256 | default='bin/targets/ath79/generic/openwrt-ath79-generic-ubnt_unifiac-pro-initramfs-kernel.bin', # noqa: E501 | 256 | help='Which file to copy' |
| 257 | help='Which file to copy' | 257 | ) |
| 258 | ) | 258 | args = parser.parse_args() |
| 259 | args = parser.parse_args() | 259 | |
| 260 | 260 | if not args.dir: | |
| 261 | if not args.dir: | 261 | args.dir = Path() |
| 262 | args.dir = Path() | 262 | if not args.copyTo: |
| 263 | if not args.copyTo: | 263 | args.copyTo = None |
| 264 | args.copyTo = None | 264 | |
| 265 | 265 | args.dir.mkdir(parents=True, exist_ok=True) | |
| 266 | args.dir.mkdir(parents=True, exist_ok=True) | 266 | os.chdir(args.dir) |
| 267 | os.chdir(args.dir) | 267 | |
| 268 | 268 | with TemporaryDirectory() as tmpdir: | |
| 269 | with TemporaryDirectory() as tmpdir: | 269 | os.environ["TMPDIR"] = f"{tmpdir}" |
| 270 | os.environ["TMPDIR"] = f"{tmpdir}" | 270 | subprocess.check_call('${fhs { runScript = pkgs.writeShellScript "build" '' |
| 271 | subprocess.check_call('${unpackWrt}') | 271 | set +x |
| 272 | subprocess.check_call('${buildWrt}') | 272 | set -e |
| 273 | 273 | ${unpackWrt} | |
| 274 | if args.copyTo: | 274 | ${buildWrt} |
| 275 | command = ['cp', args.image, args.copyTo] | 275 | ''; }}/bin/openwrt-env') |
| 276 | if args.copyToSudo: | 276 | |
| 277 | command = ['sudo', '--', *command] | 277 | if args.copyTo: |
| 278 | subprocess.check_call(command) | 278 | command = ['cp', args.image, args.copyTo] |
| 279 | ''; | 279 | if args.copyToSudo: |
| 280 | in "exec -- ${fhs { runScript = toString buildPy; }}/bin/openwrt-env $@")); | 280 | command = ['sudo', '--', *command] |
| 281 | subprocess.check_call(command) | ||
| 282 | ''); | ||
| 281 | }; | 283 | }; |
| 282 | in rec { | 284 | in rec { |
| 283 | devShell = pkgs.mkShell { | 285 | devShell = pkgs.mkShell { |
