From 1b1f9415287c3afdf8e3f7c4f2212a8a1b2be6e3 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Fri, 15 Nov 2024 21:54:02 +0100 Subject: [PATCH] contact info --- modules/initrd-contact-info.nix | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/modules/initrd-contact-info.nix b/modules/initrd-contact-info.nix index 3d1eba5..6a5ac26 100644 --- a/modules/initrd-contact-info.nix +++ b/modules/initrd-contact-info.nix @@ -2,11 +2,47 @@ { config, pkgs, lib, ... }: let + # TODO: Once `lib.string.trim` is available in stable nix, remove the below. + # Copied from https://github.com/NixOS/nixpkgs/blob/5633bcff0c6162b9e4b5f1264264611e950c8ec7/lib/strings.nix#L362-L434 + trim = trimWith { + start = true; + end = true; + }; + trimWith = + { + start ? false, + end ? false, + }: + let + # Define our own whitespace character class instead of using + # `[:space:]`, which is not well-defined. + chars = " \t\r\n"; + + # To match up until trailing whitespace, we need to capture a + # group that ends with a non-whitespace character. + regex = + if start && end then + "[${chars}]*(.*[^${chars}])[${chars}]*" + else if start then + "[${chars}]*(.*)" + else if end then + "(.*[^${chars}])[${chars}]*" + else + "(.*)"; + in + s: + let + # If the string was empty or entirely whitespace, + # then the regex may not match and `res` will be `null`. + res = lib.match regex s; + in + lib.optionalString (res != null) (lib.head res); + contact_name = "Daniel Langbein"; # The file `phone-number` contains only one line with our phone number, e.g. +49 0173 ... # Be aware that the phone number will be written to the nix store in plaintext! # TODO: strip the read string (no tailing newlines) - contact_phone = (builtins.readFile ../secrets/phone-number); + contact_phone = trim (builtins.readFile ../secrets/phone-number); contact_mail = "daniel@systemli.org"; # https://wiki.nixos.org/wiki/Shell_Scripts