From f9b97b98e5455a8f3116ff81746f86d29b0b3531 Mon Sep 17 00:00:00 2001 From: dusk Date: Thu, 31 Jul 2025 23:46:27 +0300 Subject: [PATCH] nix: modules: knot: add options for configuring motd Change-Id: prrvqyztxwsumzomnorxnxqstlnqzyww Signed-off-by: dusk --- nix/modules/knot.nix | 33 ++++++++++++++++++++++++++++++++- nix/vm.nix | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/nix/modules/knot.nix b/nix/modules/knot.nix index 3dd510d..4797062 100644 --- a/nix/modules/knot.nix +++ b/nix/modules/knot.nix @@ -58,6 +58,28 @@ in }; }; + motd = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Message of the day + + The contents are shown as-is; eg. you will want to add a newline if + setting a non-empty message since the knot won't do this for you. + ''; + }; + + motdFile = mkOption { + type = types.nullOr types.path; + default = null; + description = '' + File containing message of the day + + The contents are shown as-is; eg. you will want to add a newline if + setting a non-empty message since the knot won't do this for you. + ''; + }; + server = { listenAddr = mkOption { type = types.str; @@ -104,7 +126,15 @@ in cfg.package ]; - system.activationScripts.gitConfig = '' + system.activationScripts.gitConfig = let + setMotd = + if cfg.motdFile != null && cfg.motd != null then + throw "motdFile and motd cannot be both set" + else '' + ${optionalString (cfg.motdFile != null) "cat ${cfg.motdFile} > ${cfg.stateDir}/motd"} + ${optionalString (cfg.motd != null) ''printf "${cfg.motd}" > ${cfg.stateDir}/motd''} + ''; + in '' mkdir -p "${cfg.repo.scanPath}" chown -R ${cfg.gitUser}:${cfg.gitUser} "${cfg.repo.scanPath}" @@ -116,6 +146,7 @@ in [receive] advertisePushOptions = true EOF + ${setMotd} chown -R ${cfg.gitUser}:${cfg.gitUser} "${cfg.stateDir}" ''; diff --git a/nix/vm.nix b/nix/vm.nix index 7cee2c0..2f69fa9 100644 --- a/nix/vm.nix +++ b/nix/vm.nix @@ -48,6 +48,7 @@ nixpkgs.lib.nixosSystem { ]; services.tangled-knot = { enable = true; + motd = "Welcome to the development knot!\n"; server = { secretFile = "/var/lib/knot/secret"; hostname = "localhost:6000"; -- 2.43.0