From 05ae73b740eb6c54bf78132c0ddbd4c8b4ed69e8 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 31 Jan 2023 21:30:20 +0100 Subject: nix-writers: 3.6.2 -> 3.6.3 --- submodules/nix-writers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/nix-writers b/submodules/nix-writers index 0c8de1504..d1424777b 160000 --- a/submodules/nix-writers +++ b/submodules/nix-writers @@ -1 +1 @@ -Subproject commit 0c8de150426476b5287cf2787bbd85263691a802 +Subproject commit d1424777b5f2e12cbd80efd1b55335dcba7c32bd -- cgit v1.2.3 From 8f28d0cb51f74f0401705c608f29d6aa3e15c425 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 31 Jan 2023 21:32:29 +0100 Subject: nixos-format-error: init --- krebs/5pkgs/simple/nixos-format-error.nix | 105 ++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 krebs/5pkgs/simple/nixos-format-error.nix diff --git a/krebs/5pkgs/simple/nixos-format-error.nix b/krebs/5pkgs/simple/nixos-format-error.nix new file mode 100644 index 000000000..14066efb1 --- /dev/null +++ b/krebs/5pkgs/simple/nixos-format-error.nix @@ -0,0 +1,105 @@ +{ pkgs }: + +pkgs.writeGawk "nixos-format-error" '' + # usage: nixos-rebuild ... 2>&1 | nixos-format-error + + function out() { + print + next + } + + BEGIN { + IDLE = 0 + ACTIVE = 1 + PASSIVE = 2 + ERROR = 3 + + start_state = IDLE + + state = start_state + } + + END { + if (trace_count) + for (i = trace_count - 1; i >= 0; i--) + print trace[i] + } + + state == PASSIVE { + out() + } + + state == IDLE { + if ($0 == "building the system configuration...") { + state = ACTIVE + } + out() + } + + state == ACTIVE { + if ($1 == "error:") { + state = ERROR + sub(/^/,"\x1b[31;1m"); sub(/$/,"\x1b[m") + trace[trace_count++] = $0 + + "stty -F /dev/tty size" |& getline + COLUMNS = gensub(/.* ([0-9]+)$/, "\\1", "1") + + next + } + if ($0 ~ /^these [0-9]+ derivations will be built:/) { + state = PASSIVE + } + if ($0 == "activating the configuration...") { + state = PASSIVE + } + out() + } + + state == ERROR { + + if ($0 ~ /^\s*at /) { + location = gensub(/^\s*at (.*):$/,"\\1","1") + content = "" + lnumcol = gensub(/^.*:([0-9]+:[0-9]+)$/,"\\1","1",location) + lnum = gensub(/:.*/,"","1",lnumcol) + col = gensub(/.*:/,"","1",lnumcol) + next + } + + if ($1 == lnum "|") { + content = gensub(/^\s*[0-9]+\|(.*)/,"\\1","1") + + location = sprintf("%50s", location) + + preview_size = COLUMNS - length(location " ") + + prefix = gensub(/^\s*/,"","1",substr(content, 1, col)) + infix = gensub(/^([0-9a-zA-Z]+|.).*$/, "\\1", "1", substr(content, col + 1)) + suffix = substr(content, col + length(infix) + 1) + + if (length(prefix infix suffix) > preview_size) { + n = (preview_size - length(infix)) / 2 - length(" ") + prefix = substr(prefix, length(prefix) - n + 1) + if (prefix != "") { prefix = "…" prefix } + suffix = substr(suffix, 1, n) + if (suffix != "") { suffix = suffix "…" } + } + + preview = \ + "\x1b[38;5;244m" prefix "\x1b[m" \ + "\x1b[38;5;230m" infix "\x1b[m" \ + "\x1b[38;5;244m" suffix "\x1b[m" + + trace[trace_count++] = location " " preview + next + } + + if ($0 == "") next + if ($0 ~ /^\s*… (from|while)/) next + if ($0 ~ /^\s*([0-9]*)\|/) next + + trace[trace_count++] = $0 + next + } +'' -- cgit v1.2.3 From 7f45ab5b685cf2769bb07077568d5bdabab22824 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 2 Feb 2023 14:46:47 +0100 Subject: nixos-format-error: use writeGawkBin --- krebs/5pkgs/simple/nixos-format-error.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/krebs/5pkgs/simple/nixos-format-error.nix b/krebs/5pkgs/simple/nixos-format-error.nix index 14066efb1..9ba410bbe 100644 --- a/krebs/5pkgs/simple/nixos-format-error.nix +++ b/krebs/5pkgs/simple/nixos-format-error.nix @@ -1,6 +1,6 @@ { pkgs }: -pkgs.writeGawk "nixos-format-error" '' +pkgs.writeGawkBin "nixos-format-error" '' # usage: nixos-rebuild ... 2>&1 | nixos-format-error function out() { -- cgit v1.2.3 From 9316f445b62fbe9f92f8bf41c8c3780cd323839b Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 2 Feb 2023 14:47:10 +0100 Subject: nixos-format-error: grok SGR and \r --- krebs/5pkgs/simple/nixos-format-error.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/krebs/5pkgs/simple/nixos-format-error.nix b/krebs/5pkgs/simple/nixos-format-error.nix index 9ba410bbe..a28f7245f 100644 --- a/krebs/5pkgs/simple/nixos-format-error.nix +++ b/krebs/5pkgs/simple/nixos-format-error.nix @@ -30,14 +30,14 @@ pkgs.writeGawkBin "nixos-format-error" '' } state == IDLE { - if ($0 == "building the system configuration...") { + if ($0 ~ /^building the system configuration\.\.\. ?$/) { state = ACTIVE } out() } state == ACTIVE { - if ($1 == "error:") { + if ($1 ~ /(\[[0-9;]+m)?error:(\[[0-9;]m)?/) { state = ERROR sub(/^/,"\x1b[31;1m"); sub(/$/,"\x1b[m") trace[trace_count++] = $0 @@ -57,6 +57,8 @@ pkgs.writeGawkBin "nixos-format-error" '' } state == ERROR { + sub(/ $/, "") + gsub(/\[[0-9;]*m/, "") if ($0 ~ /^\s*at /) { location = gensub(/^\s*at (.*):$/,"\\1","1") -- cgit v1.2.3 From 38062bf06659e3ad9b2427c2049aa3ccce47c24c Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 2 Feb 2023 15:21:52 +0100 Subject: urlwatch: admit dict-based filter lists --- krebs/3modules/urlwatch.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/krebs/3modules/urlwatch.nix b/krebs/3modules/urlwatch.nix index 2e336de21..e08289bbc 100644 --- a/krebs/3modules/urlwatch.nix +++ b/krebs/3modules/urlwatch.nix @@ -71,7 +71,7 @@ let description = "URL to watch."; example = [ https://nixos.org/channels/nixos-unstable/git-revision - { url = http://localhost ; filter = "grep:important.*stuff"; } + { url = http://localhost ; filter = [ (grep "important.*stuff") ]; } ]; apply = map (x: getAttr (typeOf x) { set = x; @@ -211,7 +211,9 @@ let }; filter = mkOption { default = null; - type = with types; nullOr str; # TODO nullOr subtypes.filter + type = + with types; + nullOr (either str (listOf (pkgs.formats.json {}).type)); }; ignore_cached = mkOption { default = null; -- cgit v1.2.3 From beab66db651b3f5d0c6f033221a8acda4531c4d1 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 2 Feb 2023 15:24:04 +0100 Subject: tv urlwatch exec: use dict-based filter list Because string-based filter definitions are deprecated since 2.19 Refs https://urlwatch.readthedocs.io/en/latest/deprecated.html --- tv/2configs/urlwatch.nix | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tv/2configs/urlwatch.nix b/tv/2configs/urlwatch.nix index 7ba364ff3..e2cd19902 100644 --- a/tv/2configs/urlwatch.nix +++ b/tv/2configs/urlwatch.nix @@ -2,9 +2,10 @@ with import ./lib; { config, pkgs, ... }: let exec = filename: args: url: { inherit url; - filter = "system:${ - concatMapStringsSep " " shell.escape ([filename] ++ toList args) - }"; + filter = singleton { + system = + concatMapStringsSep " " shell.escape ([filename] ++ toList args); + }; }; json = json' ["."]; json' = exec "${pkgs.jq}/bin/jq"; @@ -73,17 +74,23 @@ in { import subprocess import urlwatch - class CaseFilter(urlwatch.filters.FilterBase): + class SystemFilter(urlwatch.filters.FilterBase): """Filter for piping data through an external process""" __kind__ = 'system' + __supported_subfilters__ = { + 'command': 'shell command line to tranform data', + } + + __default_subfilter__ = 'command' + def filter(self, data, subfilter=None): - if subfilter is None: - raise ValueError('The system filter needs a command') + if 'command' not in subfilter: + raise ValueError('{} filter needs a command'.format(self.__kind__)) proc = subprocess.Popen( - subfilter, + subfilter['command'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, -- cgit v1.2.3 From 7a2b6a72fa75706dce069f9ec68c39f883dcba18 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 2 Feb 2023 14:28:13 +0100 Subject: tv urlwatch: add samsung consumer-storage tools --- tv/2configs/urlwatch.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tv/2configs/urlwatch.nix b/tv/2configs/urlwatch.nix index e2cd19902..f5260ee05 100644 --- a/tv/2configs/urlwatch.nix +++ b/tv/2configs/urlwatch.nix @@ -9,6 +9,9 @@ with import ./lib; }; json = json' ["."]; json' = exec "${pkgs.jq}/bin/jq"; + urigrep' = exec (pkgs.writeDash "urigrep" '' + ${pkgs.urix}/bin/urix | ${pkgs.gnugrep}/bin/grep -E "$1" + ''); xml = xml' ["--format" "-"]; xml' = exec "${pkgs.libxml2}/bin/xmllint"; in { @@ -69,6 +72,8 @@ in { https://raw.githubusercontent.com/NixOS/nixpkgs/master/nixos/modules/services/x11/xserver.nix https://www.rabbitmq.com/changelog.html + + (urigrep' ["software-resources"] https://semiconductor.samsung.com/consumer-storage/support/tools/) ]; hooksFile = toFile "hooks.py" '' import subprocess -- cgit v1.2.3 From c2b601d123714f29474a0434555bf90c2ebedbbd Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 2 Feb 2023 16:02:01 +0100 Subject: urlwatch subject: put each url on its own line --- krebs/3modules/urlwatch.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/krebs/3modules/urlwatch.nix b/krebs/3modules/urlwatch.nix index e08289bbc..8ebbdd1f8 100644 --- a/krebs/3modules/urlwatch.nix +++ b/krebs/3modules/urlwatch.nix @@ -177,8 +177,8 @@ let echo Date: $(date -R) echo From: ${shell.escape cfg.from} echo Subject: $( - sed -n 's/^\(CHANGED\|ERROR\|NEW\): //p' changes \ - | tr '\n' ' ' + sed -nr 's/^(CHANGED|ERROR|NEW): //p' changes | + sed '1!s/^ //' ) echo To: ${shell.escape cfg.mailto} echo -- cgit v1.2.3 From 38d0a0a5be8e472c60c3745df9f34aadc51514dd Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 2 Feb 2023 16:02:31 +0100 Subject: urlwatch content-transfer-encoding: base64 --- krebs/3modules/urlwatch.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/krebs/3modules/urlwatch.nix b/krebs/3modules/urlwatch.nix index 8ebbdd1f8..113f6e65d 100644 --- a/krebs/3modules/urlwatch.nix +++ b/krebs/3modules/urlwatch.nix @@ -181,8 +181,11 @@ let sed '1!s/^ //' ) echo To: ${shell.escape cfg.mailto} + echo Mime-Version: 1.0 + echo Content-Type: text/plain\; charset=UTF-8 + echo Content-Transfer-Encoding: base64 echo - cat changes + base64 changes } | /run/wrappers/bin/sendmail -t fi ''} -- cgit v1.2.3 From eb39234ba8375d7274d70af678175ffe88109cb3 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 2 Feb 2023 16:29:23 +0100 Subject: tv wiregrill: init --- tv/2configs/wiregrill.nix | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tv/2configs/wiregrill.nix diff --git a/tv/2configs/wiregrill.nix b/tv/2configs/wiregrill.nix new file mode 100644 index 000000000..d28a1ec29 --- /dev/null +++ b/tv/2configs/wiregrill.nix @@ -0,0 +1,37 @@ +with import ./lib; +{ config, pkgs, ... }: let + cfg = { + enable = cfg.net != null; + net = config.krebs.build.host.nets.wiregrill or null; + }; + toCidrNotation = ip: "${ip.addr}/${toString ip.prefixLength}"; +in + mkIf cfg.enable { + networking.wireguard.interfaces.wiregrill = { + ips = + optional (cfg.net.ip4 != null) cfg.net.ip4.addr ++ + optional (cfg.net.ip6 != null) cfg.net.ip6.addr; + listenPort = 51820; + privateKeyFile = (toString ) + "/wiregrill.key"; + allowedIPsAsRoutes = true; + peers = mapAttrsToList + (_: host: { + allowedIPs = host.nets.wiregrill.wireguard.subnets; + endpoint = + mkIf (host.nets.wiregrill.via != null) (host.nets.wiregrill.via.ip4.addr + ":${toString host.nets.wiregrill.wireguard.port}"); + persistentKeepalive = mkIf (host.nets.wiregrill.via != null) 61; + publicKey = + replaceStrings ["\n"] [""] host.nets.wiregrill.wireguard.pubkey; + }) + (filterAttrs (_: h: hasAttr "wiregrill" h.nets) config.krebs.hosts); + }; + systemd.network.networks.wiregrill = { + matchConfig.Name = "wiregrill"; + address = + optional (!isNull cfg.net.ip4) (toCidrNotation cfg.net.ip4) ++ + optional (!isNull cfg.net.ip6) (toCidrNotation cfg.net.ip6); + }; + tv.iptables.extra.filter.INPUT = [ + "-p udp --dport ${toString cfg.net.wireguard.port} -j ACCEPT" + ]; + } -- cgit v1.2.3 From fc00990f712663688e5aea85624cb9317e9f4128 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 2 Feb 2023 16:50:29 +0100 Subject: tv: add default networking.hostId --- tv/1systems/bu/config.nix | 2 -- tv/2configs/default.nix | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tv/1systems/bu/config.nix b/tv/1systems/bu/config.nix index c7f7da24d..a3959cd84 100644 --- a/tv/1systems/bu/config.nix +++ b/tv/1systems/bu/config.nix @@ -13,8 +13,6 @@ with import ./lib; krebs.build.host = config.krebs.hosts.bu; - networking.hostId = lib.mkDefault "00000000"; - networking.wireless.enable = true; networking.useDHCP = false; networking.interfaces.enp0s25.useDHCP = true; diff --git a/tv/2configs/default.nix b/tv/2configs/default.nix index d1384845a..53b11c620 100644 --- a/tv/2configs/default.nix +++ b/tv/2configs/default.nix @@ -6,6 +6,7 @@ with import ./lib; krebs.build.user = config.krebs.users.tv; + networking.hostId = mkDefault (hashToLength 8 config.networking.hostName); networking.hostName = config.krebs.build.host.name; imports = [ -- cgit v1.2.3