Use black

This commit is contained in:
Simon Bruder 2021-06-01 00:02:27 +02:00
parent b0d6861825
commit e94d0227fe
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
2 changed files with 134 additions and 76 deletions

View file

@ -62,6 +62,7 @@
pre-commit-check = nix-pre-commit-hooks.lib.${system}.run { pre-commit-check = nix-pre-commit-hooks.lib.${system}.run {
src = ./.; src = ./.;
hooks = { hooks = {
black.enable = true;
nixpkgs-fmt.enable = true; nixpkgs-fmt.enable = true;
shellcheck.enable = true; shellcheck.enable = true;
}; };
@ -138,6 +139,7 @@
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
buildInputs = (with pkgs; [ buildInputs = (with pkgs; [
black
nixpkgs-fmt nixpkgs-fmt
shellcheck shellcheck
sops sops

View file

@ -15,7 +15,9 @@ def add_switch(name: str, default=False):
if default: if default:
parser.add_argument(f"--no-{name}", dest=name, action="store_false") parser.add_argument(f"--no-{name}", dest=name, action="store_false")
else: else:
parser.add_argument(f"--{name}", dest=name, action="store_true", default=default) parser.add_argument(
f"--{name}", dest=name, action="store_true", default=default
)
def tmp_file(name: str): def tmp_file(name: str):
@ -76,42 +78,72 @@ path_entries = [
] ]
argument_groups = { argument_groups = {
"base": (True, [ "base": (
"--tmpfs", "/tmp", True,
"--proc", "/proc", [
"--dev", "/dev", "--tmpfs",
"--dir", home, "/tmp",
"--dir", f"/run/user/{uid}", "--proc",
"/proc",
"--dev",
"/dev",
"--dir",
home,
"--dir",
f"/run/user/{uid}",
*ro_bind("/etc/localtime"), *ro_bind("/etc/localtime"),
"--unshare-all", "--unshare-all",
"--die-with-parent", "--die-with-parent",
]), ],
"nix-store": (True, [ ),
*flat_map(ro_bind, [ "nix-store": (
True,
[
*flat_map(
ro_bind,
[
"/nix/store", "/nix/store",
"/etc/static", "/etc/static",
]), ],
]), ),
"path": (True, [ ],
),
"path": (
True,
[
*flat_map(ro_bind_try, path_entries), *flat_map(ro_bind_try, path_entries),
*setenv("PATH", ":".join(path_entries)), *setenv("PATH", ":".join(path_entries)),
*ro_bind_try("/run/current-system/sw") # not really path, but also libraries etc. *ro_bind_try(
]), "/run/current-system/sw"
"gui": (False, [ ), # not really path, but also libraries etc.
],
),
"gui": (
False,
[
*dev_bind("/dev/dri"), *dev_bind("/dev/dri"),
*flat_map(ro_bind, [ *flat_map(
ro_bind,
[
"/sys/dev/char", "/sys/dev/char",
"/sys/devices/pci0000:00", "/sys/devices/pci0000:00",
f"/run/user/{uid}/{os.getenv('WAYLAND_DISPLAY')}", f"/run/user/{uid}/{os.getenv('WAYLAND_DISPLAY')}",
"/run/opengl-driver", "/run/opengl-driver",
"/etc/fonts", "/etc/fonts",
]), ],
),
*ro_bind_try("/run/opengl-driver-32"), *ro_bind_try("/run/opengl-driver-32"),
]), ],
"x11": (False, [ ),
"x11": (
False,
[
*ro_bind("/tmp/.X11-unix"), *ro_bind("/tmp/.X11-unix"),
]), ],
"audio": (False, [ ),
"audio": (
False,
[
*ro_bind(f"/run/user/{uid}/pulse"), *ro_bind(f"/run/user/{uid}/pulse"),
# should in theory autodetect, but sometimes it does not work # should in theory autodetect, but sometimes it does not work
*setenv("PULSE_SERVER", f"/run/user/{uid}/pulse/native"), *setenv("PULSE_SERVER", f"/run/user/{uid}/pulse/native"),
@ -120,38 +152,62 @@ argument_groups = {
*setenv("PULSE_COOKIE", f"{home}/.config/pulse/cookie"), *setenv("PULSE_COOKIE", f"{home}/.config/pulse/cookie"),
# ALSA compat # ALSA compat
*ro_bind("/etc/asound.conf"), *ro_bind("/etc/asound.conf"),
]), ],
"passwd": (False, [ ),
"passwd": (
False,
[
*ro_bind( *ro_bind(
generate_tmp_file( generate_tmp_file(
"passwd", "passwd",
f"{username}:x:{uid}:{gid}::{home}:/run/current-system/sw/bin/bash\n" f"{username}:x:{uid}:{gid}::{home}:/run/current-system/sw/bin/bash\n",
), ),
"/etc/passwd" "/etc/passwd",
) )
]), ],
"network": (False, [ ),
"network": (
False,
[
"--share-net", "--share-net",
*flat_map(ro_bind, [ *flat_map(
ro_bind,
[
"/etc/resolv.conf", "/etc/resolv.conf",
"/etc/ssl/certs", "/etc/ssl/certs",
]), ],
]), ),
"dbus": (False, [ ],
),
"dbus": (
False,
[
*ro_bind("/run/dbus/system_bus_socket"), *ro_bind("/run/dbus/system_bus_socket"),
*ro_bind(generate_tmp_file("machine-id", "0" * 32), "/etc/machine-id"), *ro_bind(generate_tmp_file("machine-id", "0" * 32), "/etc/machine-id"),
]), ],
"new-session": (True, [ ),
"new-session": (
True,
[
"--new-session", "--new-session",
]), ],
"pwd": (False, [ ),
"pwd": (
False,
[
*ro_bind(os.getcwd()), *ro_bind(os.getcwd()),
"--chdir", os.getcwd(), "--chdir",
]), os.getcwd(),
"pwd-rw": (False, [ ],
),
"pwd-rw": (
False,
[
*bind(os.getcwd()), *bind(os.getcwd()),
"--chdir", os.getcwd(), "--chdir",
]), os.getcwd(),
],
),
} }
passthrough_args = [ passthrough_args = [