From 10100688c3473235b04574bba5826791ac85c233 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 11 Jan 2022 20:02:34 +0100 Subject: ... --- flake.nix | 116 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 59 insertions(+), 57 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index dbffac2..d273108 100644 --- a/flake.nix +++ b/flake.nix @@ -221,63 +221,65 @@ buildWrtApp = { type = "app"; - program = toString (pkgs.writeShellScript "build-wrapper" (let - buildPy = pkgs.writers.writePython3 "build" {} '' - from tempfile import TemporaryDirectory - import os - import subprocess - import argparse - from pathlib import Path - - parser = argparse.ArgumentParser(prog="build", - formatter_class=argparse.ArgumentDefaultsHelpFormatter # noqa: E501 - ) - parser.add_argument('-C', '--directory', - dest='dir', - metavar='DIRECTORY', - type=Path, - default=Path('./result'), - help='Change to this directory before doing anything' - ) - parser.add_argument('--copy-to', - dest='copyTo', - metavar='FILE', - type=Path, - default='/srv/tftp/' + Path.cwd().name + '.bin', - help='Copy result image here' - ) - parser.add_argument('--copy-to-no-sudo', - dest='copyToSudo', - action='store_false', - help='Use sudo to copy result image' - ) - parser.add_argument('--copy-image', - dest='image', - default='bin/targets/ath79/generic/openwrt-ath79-generic-ubnt_unifiac-pro-initramfs-kernel.bin', # noqa: E501 - help='Which file to copy' - ) - args = parser.parse_args() - - if not args.dir: - args.dir = Path() - if not args.copyTo: - args.copyTo = None - - args.dir.mkdir(parents=True, exist_ok=True) - os.chdir(args.dir) - - with TemporaryDirectory() as tmpdir: - os.environ["TMPDIR"] = f"{tmpdir}" - subprocess.check_call('${unpackWrt}') - subprocess.check_call('${buildWrt}') - - if args.copyTo: - command = ['cp', args.image, args.copyTo] - if args.copyToSudo: - command = ['sudo', '--', *command] - subprocess.check_call(command) - ''; - in "exec -- ${fhs { runScript = toString buildPy; }}/bin/openwrt-env $@")); + program = toString (pkgs.writers.writePython3 "build" {} '' + from tempfile import TemporaryDirectory + import os + import subprocess + import argparse + from pathlib import Path + + parser = argparse.ArgumentParser(prog="build", + formatter_class=argparse.ArgumentDefaultsHelpFormatter # noqa: E501 + ) + parser.add_argument('-C', '--directory', + dest='dir', + metavar='DIRECTORY', + type=Path, + default=Path('./result'), + help='Change to this directory before doing anything' + ) + parser.add_argument('--copy-to', + dest='copyTo', + metavar='FILE', + type=Path, + default='/srv/tftp/' + Path.cwd().name + '.bin', + help='Copy result image here' + ) + parser.add_argument('--copy-to-no-sudo', + dest='copyToSudo', + action='store_false', + help='Use sudo to copy result image' + ) + parser.add_argument('--copy-image', + dest='image', + default='bin/targets/ath79/generic/openwrt-ath79-generic-ubnt_unifiac-pro-initramfs-kernel.bin', # noqa: E501 + help='Which file to copy' + ) + args = parser.parse_args() + + if not args.dir: + args.dir = Path() + if not args.copyTo: + args.copyTo = None + + args.dir.mkdir(parents=True, exist_ok=True) + os.chdir(args.dir) + + with TemporaryDirectory() as tmpdir: + os.environ["TMPDIR"] = f"{tmpdir}" + subprocess.check_call('${fhs { runScript = pkgs.writeShellScript "build" '' + set +x + set -e + ${unpackWrt} + ${buildWrt} + ''; }}/bin/openwrt-env') + + if args.copyTo: + command = ['cp', args.image, args.copyTo] + if args.copyToSudo: + command = ['sudo', '--', *command] + subprocess.check_call(command) + ''); }; in rec { devShell = pkgs.mkShell { -- cgit v1.2.3