diff options
author | makefu <github@syntax-fehler.de> | 2022-08-02 14:34:22 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2022-08-02 14:34:22 +0200 |
commit | 739fad41da87d206f76bc3db9861d8b2bd0a5639 (patch) | |
tree | 023f294d5ba55b93905772eec90a3ebbe3667528 /lass | |
parent | bebf0baf031fca08fde11cc7f840fc885737f5b7 (diff) | |
parent | b3694198eaac7ffd13640c64bc3e3af27e40389b (diff) |
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'lass')
-rw-r--r-- | lass/2configs/fysiirc.nix | 9 | ||||
-rw-r--r-- | lass/2configs/radio/default.nix | 2 | ||||
-rw-r--r-- | lass/2configs/radio/weather_for_ips.py | 6 | ||||
-rw-r--r-- | lass/2configs/websites/domsen.nix | 2 | ||||
-rw-r--r-- | lass/3modules/default.nix | 1 | ||||
-rw-r--r-- | lass/3modules/drbd.nix | 118 | ||||
-rw-r--r-- | lass/5pkgs/default.nix | 18 | ||||
-rw-r--r-- | lass/krops.nix | 14 |
8 files changed, 146 insertions, 24 deletions
diff --git a/lass/2configs/fysiirc.nix b/lass/2configs/fysiirc.nix index e12eda42e..809298df4 100644 --- a/lass/2configs/fysiirc.nix +++ b/lass/2configs/fysiirc.nix @@ -10,8 +10,7 @@ ${write_to_irc} "$(echo "$INPUT" | jq -r ' "\(.action): " + "[\(.issue.title // .pull_request.title)] " + - "\(.comment.html_url // .issue.html_url // .pull_request.html_url) " + - "by \(.comment.user.login // .issue.user.login // .pull_request.user.login)" + "\(.comment.html_url // .issue.html_url // .pull_request.html_url) " ')" fi ''; @@ -58,16 +57,16 @@ in { case "$Method $Request_URI" in "POST /") payload=$(head -c "$req_content_length") - echo "$payload" >&2 + raw=$(printf '%s' "$payload" | ${pkgs.curl}/bin/curl --data-binary @- http://p.krebsco.de | tail -1) payload2=$payload - payload2=$(echo "$payload" | tr '\n' ' ' | tr -d '\r') + payload2=$(printf '%s' "$payload" | tr '\n' ' ' | tr -d '\r') if [ "$payload" != "$payload2" ]; then echo "payload has been mangled" >&2 else echo "payload not mangled" >&2 fi - echo "$payload2" > /tmp/last_fysi_payload echo "$payload2" | ${format-github-message}/bin/format-github-message + ${write_to_irc} "$raw" printf 'HTTP/1.1 200 OK\r\n' printf 'Connection: close\r\n' printf '\r\n' diff --git a/lass/2configs/radio/default.nix b/lass/2configs/radio/default.nix index b8d958865..2f503eae9 100644 --- a/lass/2configs/radio/default.nix +++ b/lass/2configs/radio/default.nix @@ -168,7 +168,7 @@ in { output.icecast(mount = '/music.mp3', password = 'hackme', %mp3.vbr(), source) output.icecast(mount = '/music.opus', password = 'hackme', %opus(bitrate = 96), source) - extra_input = audio_to_stereo(input.harbor("live", port=1338)) + extra_input = amplify(1.4, audio_to_stereo(input.harbor("live", port=1338))) o = smooth_add(normal = source, special = extra_input) output.icecast(mount = '/radio.ogg', password = 'hackme', %vorbis(quality = 1), o) diff --git a/lass/2configs/radio/weather_for_ips.py b/lass/2configs/radio/weather_for_ips.py index f7cc2dace..587cc1f28 100644 --- a/lass/2configs/radio/weather_for_ips.py +++ b/lass/2configs/radio/weather_for_ips.py @@ -25,9 +25,9 @@ for ip in fileinput.input(): output.append( f'Weather report for {location.city.name}, {location.country.name}. ' f'Currently it is {weather["current"]["weather"][0]["description"]} outside ' - f'with a temperature of {weather["current"]["temp"]} degrees, ' - f'and a wind speed of {weather["current"]["wind_speed"]} meters per second. ' - f'The probability of precipitation is {weather["hourly"][0]["pop"] * 100} percent. ' + f'with a temperature of {weather["current"]["temp"]:.1f} degrees, ' + f'and a wind speed of {weather["current"]["wind_speed"]:.1f} meters per second. ' + f'The probability of precipitation is {weather["hourly"][0]["pop"] * 100:.0f} percent. ' ) print('\n'.join(output)) diff --git a/lass/2configs/websites/domsen.nix b/lass/2configs/websites/domsen.nix index fe4d78a3b..90a0a5a72 100644 --- a/lass/2configs/websites/domsen.nix +++ b/lass/2configs/websites/domsen.nix @@ -104,7 +104,7 @@ in { services.nextcloud = { enable = true; hostName = "o.xanf.org"; - package = pkgs.nextcloud23; + package = pkgs.nextcloud24; config = { adminpassFile = "/run/nextcloud.pw"; overwriteProtocol = "https"; diff --git a/lass/3modules/default.nix b/lass/3modules/default.nix index 570bb45be..3a0b1306c 100644 --- a/lass/3modules/default.nix +++ b/lass/3modules/default.nix @@ -2,6 +2,7 @@ _: { imports = [ ./dnsmasq.nix + ./drbd.nix ./folderPerms.nix ./hosts.nix ./klem.nix diff --git a/lass/3modules/drbd.nix b/lass/3modules/drbd.nix new file mode 100644 index 000000000..816e58f0a --- /dev/null +++ b/lass/3modules/drbd.nix @@ -0,0 +1,118 @@ +{ config, lib, pkgs, ... }: let + cfg = config.lass.drbd; + slib = import <stockholm/lib>; +in { + options = { + lass.drbd = lib.mkOption { + default = {}; + type = lib.types.attrsOf (lib.types.submodule ({ config, ... }: { + options = { + name = lib.mkOption { + type = lib.types.str; + default = config._module.args.name; + }; + blockMinor = lib.mkOption { + type = lib.types.int; + default = lib.mod (slib.genid config.name) 16000; # TODO get max_id fron drbd + }; + port = lib.mkOption { + type = lib.types.int; + default = 20000 + config.blockMinor; + }; + peers = lib.mkOption { + type = lib.types.listOf slib.types.host; + }; + disk = lib.mkOption { + type = lib.types.str; + default = "/dev/loop${toString config.blockMinor}"; + }; + drbdConfig = lib.mkOption { + type = lib.types.path; + internal = true; + default = pkgs.writeText "drbd-${config.name}.conf" '' + resource ${config.name} { + net { + protocol a; + ping-int 10; + } + device minor ${toString config.blockMinor}; + disk ${config.disk}; + meta-disk internal; + ${slib.indent (lib.concatStrings (lib.imap1 (i: peer: /* shell */ '' + on ${peer.name} { + address ${peer.nets.retiolum.ip4.addr}:${toString config.port}; + node-id ${toString i}; + } + '') config.peers))} + connection-mesh { + hosts ${lib.concatMapStringsSep " " (peer: peer.name) config.peers}; + } + } + ''; + }; + }; + })); + }; + }; + config = lib.mkIf (cfg != {}) { + boot.extraModulePackages = [ + (pkgs.linuxPackages.callPackage ../5pkgs/drbd9/default.nix {}) + ]; + boot.extraModprobeConfig = '' + options drbd usermode_helper=/run/current-system/sw/bin/drbdadm + ''; + services.udev.packages = [ pkgs.drbd ]; + boot.kernelModules = [ "drbd" ]; + + environment.systemPackages = [ pkgs.drbd ]; + + + networking.firewall.allowedTCPPorts = map (device: device.port) (lib.attrValues cfg); + systemd.services = lib.mapAttrs' (_: device: + lib.nameValuePair "drbd-${device.name}" { + after = [ "systemd-udev.settle.service" "network.target" ]; + wants = [ "systemd-udev.settle.service" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + RemainAfterExit = true; + ExecStart = pkgs.writers.writeDash "start-drbd-${device.name}" '' + set -efux + mkdir -p /var/lib/sync-containers2 + ${lib.optionalString (device.disk == "/dev/loop${toString device.blockMinor}") '' + if ! test -e /var/lib/sync-containers2/${device.name}.disk; then + truncate -s 10G /var/lib/sync-containers2/${device.name}.disk + fi + if ! ${pkgs.util-linux}/bin/losetup /dev/loop${toString device.blockMinor}; then + ${pkgs.util-linux}/bin/losetup /dev/loop${toString device.blockMinor} /var/lib/sync-containers2/${device.name}.disk + fi + ''} + if ! ${pkgs.drbd}/bin/drbdadm adjust ${device.name}; then + ${pkgs.drbd}/bin/drbdadm down ${device.name} + ${pkgs.drbd}/bin/drbdadm create-md ${device.name} + ${pkgs.drbd}/bin/drbdadm up ${device.name} + fi + ''; + ExecStop = pkgs.writers.writeDash "stop-drbd-${device.name}" '' + set -efux + ${pkgs.drbd}/bin/drbdadm -c ${device.drbdConfig} down ${device.name} + ${lib.optionalString (device.disk == "/dev/loop${toString device.blockMinor}") '' + ${pkgs.util-linux}/bin/losetup -d /dev/loop${toString device.blockMinor} + ''} + ''; + }; + } + ) cfg; + + + environment.etc."drbd.conf".text = '' + global { + usage-count yes; + } + + ${lib.concatMapStrings (device: /* shell */ '' + include ${device.drbdConfig}; + '') (lib.attrValues cfg)} + ''; + }; +} + diff --git a/lass/5pkgs/default.nix b/lass/5pkgs/default.nix index e4208f1c1..6fa93e146 100644 --- a/lass/5pkgs/default.nix +++ b/lass/5pkgs/default.nix @@ -1,24 +1,24 @@ -with import <stockholm/lib>; self: super: let + lib = super.lib; # This callPackage will try to detect obsolete overrides. callPackage = path: args: let override = super.callPackage path args; - upstream = optionalAttrs (override ? "name") - (super.${(parseDrvName override.name).name} or {}); + upstream = lib.optionalAttrs (override ? "name") + (super.${(builtins.parseDrvName override.name).name} or {}); in if upstream ? "name" && override ? "name" && - compareVersions upstream.name override.name != -1 + builtins.compareVersions upstream.name override.name != -1 then - trace + builtins.trace "Upstream `${upstream.name}' gets overridden by `${override.name}'." override else override; subdirsOf = path: - mapAttrs (name: _: path + "/${name}") - (filterAttrs (_: eq "directory") (readDir path)); + lib.mapAttrs (name: _: path + "/${name}") + (lib.filterAttrs (_: x: x == "directory") (builtins.readDir path)); -in mapAttrs (_: flip callPackage {}) - (filterAttrs (_: dir: pathExists (dir + "/default.nix")) +in lib.mapAttrs (_: lib.flip callPackage {}) + (lib.filterAttrs (_: dir: lib.pathExists (dir + "/default.nix")) (subdirsOf ./.)) diff --git a/lass/krops.nix b/lass/krops.nix index ace37888f..c8a5b94b7 100644 --- a/lass/krops.nix +++ b/lass/krops.nix @@ -37,18 +37,22 @@ in { - deploy = { target ? "root@${name}/var/src" }: pkgs.krops.writeCommand "deploy" { + deploy = { target ? "root@${name}/var/src", offline ? false }: pkgs.krops.writeCommand "deploy" { command = targetPath: '' - set -fu + set -xfu outDir=$(mktemp -d) trap "rm -rf $outDir;" INT TERM EXIT - nix build \ + build=$(command -v nom-build || echo "nix-build") + + $build \ -I "${targetPath}" \ - -f '<nixpkgs/nixos>' config.system.build.toplevel \ - -o "$outDir/out" + '<nixpkgs/nixos>' -A config.system.build.toplevel \ + -o "$outDir/out" \ + ${lib.optionalString offline "--option substitute false"} \ + # -vvvvv --show-trace nix-env -p /nix/var/nix/profiles/system --set "$outDir/out" |