apply treefmt to codebase

This commit is contained in:
Jörg Thalheim 2022-12-31 07:24:17 +01:00
parent fea7e110c2
commit ee8f7e82b8
30 changed files with 232 additions and 202 deletions

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { ... }:
# Boot recovery: # Boot recovery:
# Activate 64-bit Rescue system in https://robot.your-server.de/server # Activate 64-bit Rescue system in https://robot.your-server.de/server
# ssh root@build01.nix-community.org "mount /dev/md[0-9]* /mnt && /mnt/kexec_bundle" # ssh root@build01.nix-community.org "mount /dev/md[0-9]* /mnt && /mnt/kexec_bundle"

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { ... }:
{ {
imports = [ imports = [

View file

@ -64,7 +64,7 @@ in
let let
allPackagesWithUpdateScript = packagesWithUpdateScriptMatchingPredicate (path: package: true) pkgs; allPackagesWithUpdateScript = packagesWithUpdateScriptMatchingPredicate (_path: _package: true) pkgs;
in in

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { ... }:
{ {
# Boot recovery: # Boot recovery:
# Activate 64-bit Rescue system in https://robot.your-server.de/server # Activate 64-bit Rescue system in https://robot.your-server.de/server

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { ... }:
{ {
imports = [ imports = [
./hardware-configuration.nix ./hardware-configuration.nix

View file

@ -1,12 +1,8 @@
# Do not modify this file! It was generated by nixos-generate-config # Do not modify this file! It was generated by nixos-generate-config
# and may be overwritten by future invocations. Please make changes # and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead. # to /etc/nixos/configuration.nix instead.
{ { modulesPath
config, , ...
lib,
pkgs,
modulesPath,
...
}: { }: {
imports = [ imports = [
(modulesPath + "/profiles/qemu-guest.nix") (modulesPath + "/profiles/qemu-guest.nix")

View file

@ -45,18 +45,19 @@
./treefmt.nix ./treefmt.nix
]; ];
perSystem = { perSystem =
inputs', { inputs'
pkgs, , pkgs
self', , self'
... , ...
}: { }: {
devShells.default = pkgs.callPackage ./shell.nix { devShells.default = pkgs.callPackage ./shell.nix {
inherit (inputs'.sops-nix.packages) sops-import-keys-hook; inherit (inputs'.sops-nix.packages) sops-import-keys-hook;
inherit (self'.packages) treefmt; inherit (self'.packages) treefmt;
}; };
}; };
flake.nixosConfigurations = let flake.nixosConfigurations =
let
inherit (inputs.nixpkgs.lib) nixosSystem; inherit (inputs.nixpkgs.lib) nixosSystem;
common = [ common = [
{ _module.args.inputs = inputs; } { _module.args.inputs = inputs; }
@ -66,7 +67,8 @@
inputs.srvos.nixosModules.telegraf inputs.srvos.nixosModules.telegraf
{ networking.firewall.allowedTCPPorts = [ 9273 ]; } { networking.firewall.allowedTCPPorts = [ 9273 ]; }
]; ];
in { in
{
"build01.nix-community.org" = nixosSystem { "build01.nix-community.org" = nixosSystem {
system = "x86_64-linux"; system = "x86_64-linux";
modules = modules =

13
pyproject.toml Normal file
View file

@ -0,0 +1,13 @@
[tool.ruff]
line-length = 88
select = ["E", "F", "I"]
ignore = [ "E501" ]
[tool.mypy]
python_version = "3.10"
warn_redundant_casts = true
disallow_untyped_calls = true
disallow_untyped_defs = true
no_implicit_optional = true

View file

@ -1,4 +1,4 @@
{ pkgs, lib, config, ... }: { lib, config, ... }:
{ {
imports = [ imports = [

View file

@ -1,4 +1,4 @@
{ config, pkgs, ... }: { config, ... }:
let let
herculesSecret = { herculesSecret = {
owner = "hercules-ci-agent"; owner = "hercules-ci-agent";

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, modulesPath, ... }: { modulesPath, ... }:
{ {
imports = [ imports = [

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { config, lib, ... }:
with lib; with lib;
let let
cfg = config.networking.nix-community; cfg = config.networking.nix-community;

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { config, ... }:
{ {
networking.firewall.allowedTCPPorts = [ 443 80 ]; networking.firewall.allowedTCPPorts = [ 443 80 ];

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, inputs, ... }: { lib, pkgs, inputs, ... }:
let let
asGB = size: toString (size * 1024 * 1024); asGB = size: toString (size * 1024 * 1024);
@ -37,14 +37,16 @@ in
}; };
# inputs == flake inputs in configurations.nix # inputs == flake inputs in configurations.nix
environment.etc = let environment.etc =
let
inputsWithDate = lib.filterAttrs (_: input: input ? lastModified) inputs; inputsWithDate = lib.filterAttrs (_: input: input ? lastModified) inputs;
flakeAttrs = input: (lib.mapAttrsToList (n: v: ''${n}="${v}"'') flakeAttrs = input: (lib.mapAttrsToList (n: v: ''${n}="${v}"'')
(lib.filterAttrs (n: v: (builtins.typeOf v) == "string") input)); (lib.filterAttrs (_n: v: (builtins.typeOf v) == "string") input));
lastModified = name: input: '' lastModified = name: input: ''
flake_input_last_modified{input="${name}",${lib.concatStringsSep "," (flakeAttrs input)}} ${toString input.lastModified} flake_input_last_modified{input="${name}",${lib.concatStringsSep "," (flakeAttrs input)}} ${toString input.lastModified}
''; '';
in { in
{
"flake-inputs.prom" = { "flake-inputs.prom" = {
mode = "0555"; mode = "0555";
text = '' text = ''

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { ... }:
{ {
# Make sure that the firewall is enabled, even if it's the default. # Make sure that the firewall is enabled, even if it's the default.
networking.firewall.enable = true; networking.firewall.enable = true;

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { config, lib, ... }:
let let
defaultSopsPath = ../. + "/${config.networking.hostName}/secrets.yaml"; defaultSopsPath = ../. + "/${config.networking.hostName}/secrets.yaml";
in in

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }: { config, lib, ... }:
let let
userImports = userImports =

View file

@ -13,7 +13,7 @@
enable = true; enable = true;
listen = "127.0.0.1:6080"; listen = "127.0.0.1:6080";
config = builtins.readFile ./hound.json; config = builtins.readFile ./hound.json;
package = pkgs.hound.overrideAttrs (x: { package = pkgs.hound.overrideAttrs (_x: {
patches = [ patches = [
./0001-Fail-to-start-if-any-repos-fail-to-index.patch ./0001-Fail-to-start-if-any-repos-fail-to-index.patch
]; ];

View file

@ -1,63 +1,67 @@
#!/usr/bin/env nix-shell #!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python3Packages.python -p python3Packages.requests #!nix-shell -i python3 -p python3Packages.python -p python3Packages.requests
import requests
import json import json
from pprint import pprint
import requests
disallowed_repos = [ disallowed_repos = [
'NixOS/nixops-dashboard', # empty repo causes an error "NixOS/nixops-dashboard", # empty repo causes an error
]; ]
allowed_forks = [ allowed_forks = [
'nix-community/acpi_call', "nix-community/acpi_call",
'nix-community/bundix', "nix-community/bundix",
'nix-community/luarocks-nix', "nix-community/luarocks-nix",
'nix-community/nix-doom-emacs', "nix-community/nix-doom-emacs",
'nix-community/nix-straight.el', "nix-community/nix-straight.el",
'nix-community/travis-build', "nix-community/travis-build",
'nix-community/vagrant-nixos-plugin', "nix-community/vagrant-nixos-plugin",
'NixOS/calamares-nixos-extensions', "NixOS/calamares-nixos-extensions",
]; ]
def all_for_org(org): def all_for_org(org):
resp = {} resp = {}
next_url = 'https://api.github.com/orgs/{}/repos'.format(org) next_url = "https://api.github.com/orgs/{}/repos".format(org)
while next_url is not None: while next_url is not None:
repo_resp = requests.get(next_url) repo_resp = requests.get(next_url)
if 'next' in repo_resp.links: if "next" in repo_resp.links:
next_url = repo_resp.links['next']['url'] next_url = repo_resp.links["next"]["url"]
else: else:
next_url = None next_url = None
repos = repo_resp.json() repos = repo_resp.json()
resp.update({ resp.update(
"{}-{}".format(org, repo['name']): { {
'url': repo['clone_url'], "{}-{}".format(org, repo["name"]): {
"url": repo["clone_url"],
} }
for repo in repos for repo in repos
if repo['full_name'] not in disallowed_repos if repo["full_name"] not in disallowed_repos
if repo['archived'] == False if repo["archived"] is False
if repo['fork'] == False or repo['full_name'] in allowed_forks if repo["fork"] is False or repo["full_name"] in allowed_forks
}) }
)
return resp return resp
repos = {**all_for_org('NixOS'), **all_for_org('nix-community')}
print(json.dumps( repos = {**all_for_org("NixOS"), **all_for_org("nix-community")}
print(
json.dumps(
{ {
"max-concurrent-indexers": 1, "max-concurrent-indexers": 1,
"dbpath": "/var/lib/hound/data", "dbpath": "/var/lib/hound/data",
"repos": repos, "repos": repos,
"vcs-config" : { "vcs-config": {"git": {"detect-ref": True}},
"git": { "detect-ref" : True }
},
}, },
indent=4, indent=4,
sort_keys=True sort_keys=True,
)) )
)

View file

@ -18,7 +18,8 @@ with lib; let
export HOME=/root export HOME=/root
exec ${pkgs.cachix}/bin/cachix -c ${config.sops.secrets.nix-community-cachix.path} push nix-community $OUT_PATHS > /tmp/hydra_cachix 2>&1 exec ${pkgs.cachix}/bin/cachix -c ${config.sops.secrets.nix-community-cachix.path} push nix-community $OUT_PATHS > /tmp/hydra_cachix 2>&1
''; '';
in { in
{
options.services.hydra = { options.services.hydra = {
adminPasswordFile = mkOption { adminPasswordFile = mkOption {
type = types.str; type = types.str;

View file

@ -1,4 +1,4 @@
{ nur-update }: { config, lib, pkgs, ... }: { nur-update }: { config, pkgs, ... }:
{ {
services.nginx.virtualHosts."nur-update.nix-community.org" = { services.nginx.virtualHosts."nur-update.nix-community.org" = {
@ -9,13 +9,15 @@
sops.secrets.nur-update-github-token = { }; sops.secrets.nur-update-github-token = { };
systemd.services.nur-update = let systemd.services.nur-update =
let
python = pkgs.python3.withPackages python = pkgs.python3.withPackages
(ps: with ps; [ (ps: with ps; [
(ps.toPythonModule nur-update.packages.${pkgs.system}.default) (ps.toPythonModule nur-update.packages.${pkgs.system}.default)
gunicorn gunicorn
]); ]);
in { in
{
description = "nur-update"; description = "nur-update";
script = '' script = ''
GITHUB_TOKEN="$(<$CREDENTIALS_DIRECTORY/github-token)" \ GITHUB_TOKEN="$(<$CREDENTIALS_DIRECTORY/github-token)" \

View file

@ -1,12 +1,12 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from invoke import task
import sys
from typing import List, Any
from deploykit import DeployHost, DeployGroup
import subprocess
import json import json
import subprocess
import sys
from typing import Any, List
from deploykit import DeployGroup, DeployHost
from invoke import task
RSYNC_EXCLUDES = [".terraform", ".direnv", ".mypy-cache", ".git"] RSYNC_EXCLUDES = [".terraform", ".direnv", ".mypy-cache", ".git"]
@ -23,7 +23,7 @@ def deploy_nixos(hosts: List[DeployHost]) -> None:
f"rsync {' --exclude '.join([''] + RSYNC_EXCLUDES)} -vaF --delete -e ssh . {target}:/etc/nixos" f"rsync {' --exclude '.join([''] + RSYNC_EXCLUDES)} -vaF --delete -e ssh . {target}:/etc/nixos"
) )
h.run(f"nixos-rebuild switch --option accept-flake-config true") h.run("nixos-rebuild switch --option accept-flake-config true")
g.run_function(deploy) g.run_function(deploy)
@ -73,19 +73,19 @@ def _format_disks(host: DeployHost, devices: List[str]) -> None:
f"zpool create zroot -O acltype=posixacl -O xattr=sa -O compression=lz4 -O atime=off {root_part}" f"zpool create zroot -O acltype=posixacl -O xattr=sa -O compression=lz4 -O atime=off {root_part}"
) )
host.run(f"partprobe") host.run("partprobe")
host.run(f"mkfs.ext4 -F {boot}") host.run(f"mkfs.ext4 -F {boot}")
# setup zfs dataset # setup zfs dataset
host.run(f"zfs create -o mountpoint=none zroot/root") host.run("zfs create -o mountpoint=none zroot/root")
host.run(f"zfs create -o mountpoint=legacy zroot/root/nixos") host.run("zfs create -o mountpoint=legacy zroot/root/nixos")
host.run(f"zfs create -o mountpoint=legacy zroot/root/home") host.run("zfs create -o mountpoint=legacy zroot/root/home")
## and finally mount ## and finally mount
host.run(f"mount -t zfs zroot/root/nixos /mnt") host.run("mount -t zfs zroot/root/nixos /mnt")
host.run(f"mkdir /mnt/home /mnt/boot") host.run("mkdir /mnt/home /mnt/boot")
host.run(f"mount -t zfs zroot/root/home /mnt/home") host.run("mount -t zfs zroot/root/home /mnt/home")
host.run(f"mount -t ext4 /dev/md127 /mnt/boot") host.run("mount -t ext4 /dev/md127 /mnt/boot")
@task @task
@ -103,15 +103,24 @@ find . \
""" """
) )
@task @task
def scan_age_keys(c, host): def scan_age_keys(c, host):
""" """
Scans for the host key via ssh an converts it to age Scans for the host key via ssh an converts it to age
""" """
import subprocess import subprocess
proc = subprocess.run(["ssh-keyscan", host], stdout=subprocess.PIPE, text=True, check=True)
proc = subprocess.run(
["ssh-keyscan", host], stdout=subprocess.PIPE, text=True, check=True
)
print("###### Age keys ######") print("###### Age keys ######")
subprocess.run(["nix", "run", "--inputs-from", ".#", "nixpkgs#ssh-to-age"], input=proc.stdout, check=True, text=True) subprocess.run(
["nix", "run", "--inputs-from", ".#", "nixpkgs#ssh-to-age"],
input=proc.stdout,
check=True,
text=True,
)
@task @task
@ -198,7 +207,8 @@ def build_local(c, hosts=""):
def wait_for_port(host: str, port: int, shutdown: bool = False) -> None: def wait_for_port(host: str, port: int, shutdown: bool = False) -> None:
import socket, time import socket
import time
while True: while True:
try: try:
@ -209,7 +219,7 @@ def wait_for_port(host: str, port: int, shutdown: bool = False) -> None:
sys.stdout.flush() sys.stdout.flush()
else: else:
break break
except OSError as ex: except OSError:
if shutdown: if shutdown:
break break
else: else:

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { lib, ... }:
let let
userLib = import ./lib.nix { inherit lib; }; userLib = import ./lib.nix { inherit lib; };
keys = [ keys = [

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { lib, ... }:
let let
userLib = import ./lib.nix { inherit lib; }; userLib = import ./lib.nix { inherit lib; };
keys = [ keys = [

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { lib, ... }:
let let
userLib = import ./lib.nix { inherit lib; }; userLib = import ./lib.nix { inherit lib; };
keys = [ keys = [

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { lib, ... }:
let let
userLib = import ./lib.nix { inherit lib; }; userLib = import ./lib.nix { inherit lib; };
keys = [ keys = [

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { lib, ... }:
let let
userLib = import ./lib.nix { inherit lib; }; userLib = import ./lib.nix { inherit lib; };
keys = [ keys = [

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { lib, ... }:
let let
userLib = import ./lib.nix { inherit lib; }; userLib = import ./lib.nix { inherit lib; };
keys = [ keys = [

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { lib, ... }:
let let
userLib = import ./lib.nix { inherit lib; }; userLib = import ./lib.nix { inherit lib; };
keys = [ keys = [