From fd29c877186dbb06d5593d734952baec199a5261 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Tue, 17 Dec 2024 22:23:36 +0100 Subject: [PATCH 1/2] Add Radicale service --- examples/default.nix | 1 + examples/radicale/default.nix | 40 +++++++++++++++++++ modules/ids.nix | 2 + modules/list.nix | 1 + modules/services/radicale.nix | 75 +++++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 examples/radicale/default.nix create mode 100644 modules/services/radicale.nix diff --git a/examples/default.nix b/examples/default.nix index 0a065b9..9f5814d 100644 --- a/examples/default.nix +++ b/examples/default.nix @@ -31,6 +31,7 @@ let "dnsmasq" = ./dnsmasq; "attic" = ./attic; "ntfy-sh" = ./ntfy-sh; + "radicale" = ./radicale; }; in nixpkgs.lib.mapAttrs (_: v: import v { inherit nixpkgs nglib nixng; }) examples diff --git a/examples/radicale/default.nix b/examples/radicale/default.nix new file mode 100644 index 0000000..e7ccf8d --- /dev/null +++ b/examples/radicale/default.nix @@ -0,0 +1,40 @@ +{ nglib, nixpkgs, ...}: +nglib.makeSystem { + inherit nixpkgs; + system = "x86_64-linux"; + name = "nixng-radicale"; + + config = {...}: { + dinit.enable = true; + init.services.radicale = { + shutdownOnExit = true; + + ensureSomething.create."stateDir" = { + type = "directory"; + mode = "755"; + owner = "radicale:radicale"; + persistent = true; + dst = "/var/lib/radicale"; + }; + }; + + services.radicale = { + enable = true; + + settings = { + server = { + hosts = "0.0.0.0:5232, [::]:5232"; + ssl = false; + }; + + auth = { + type = "none"; + }; + + storage = { + filesystem_folder = "/var/lib/radicale/collections"; + }; + }; + }; + }; +} diff --git a/modules/ids.nix b/modules/ids.nix index 46b568c..61eebfa 100644 --- a/modules/ids.nix +++ b/modules/ids.nix @@ -43,6 +43,7 @@ dnsmasq = 405; attic = 406; ntfy-sh = 407; + radicale = 408; vmail = 5000; nobody = 65534; }; @@ -70,6 +71,7 @@ dnsmasq = 405; attic = 406; ntfy-sh = 407; + radicale = 408; vmail = 5000; nogroup = 65534; }; diff --git a/modules/list.nix b/modules/list.nix index 9c60b6a..36576d8 100644 --- a/modules/list.nix +++ b/modules/list.nix @@ -50,4 +50,5 @@ ./services/dnsmasq.nix ./services/attic.nix ./services/ntfy-sh.nix + ./services/radicale.nix ] diff --git a/modules/services/radicale.nix b/modules/services/radicale.nix new file mode 100644 index 0000000..2d19941 --- /dev/null +++ b/modules/services/radicale.nix @@ -0,0 +1,75 @@ +{lib, pkgs, config, nglib, ...}: +let + cfg = config.services.radicale; + + settingsFormat = pkgs.formats.ini { + listToValue = lib.concatMapStringsSep ", " (lib.generators.mkValueStringDefault { }); + }; +in +{ + options.services.radicale = { + enable = lib.mkEnableOption "radicale"; + package = lib.mkPackageOption pkgs "radicale" { }; + + user = lib.mkOption { + description = "radicale user"; + type = lib.types.str; + default = "radicale"; + }; + + group = lib.mkOption { + description = "radicale group"; + type = lib.types.str; + default = "radicale"; + }; + + settings = lib.mkOption { + type = settingsFormat.type; + default = { }; + description = '' + Configuration for Radicale. See + . + ''; + example = lib.literalExpression '' + server = { + hosts = [ "0.0.0.0:5232" "[::]:5232" ]; + }; + auth = { + type = "htpasswd"; + htpasswd_filename = "/etc/radicale/users"; + htpasswd_encryption = "bcrypt"; + }; + storage = { + filesystem_folder = "/var/lib/radicale/collections"; + }; + ''; + }; + }; + + config = lib.mkIf cfg.enable (let + configFile = settingsFormat.generate "radicale.ini" cfg.settings; + in + { + init.services.radicale = { + enabled = true; + + script = pkgs.writeShellScript "radicale-run" '' + chpst -u ${cfg.user}:${cfg.group} ${cfg.package}/bin/radicale \ + --config ${configFile} + ''; + }; + + environment.systemPackages = [ cfg.package ]; + + users.users.${cfg.user} = nglib.mkDefaultRec { + description = "radicale"; + group = cfg.group; + createHome = false; + home = "/var/empty"; + useDefaultShell = true; + uid = config.ids.uids.radicale; + }; + + users.groups.${cfg.group} = nglib.mkDefaultRec { gid = config.ids.gids.radicale; }; + }); +} From 436f267a26af12cd780fd4625dcb60bfdeaed98a Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Tue, 17 Dec 2024 23:10:00 +0100 Subject: [PATCH 2/2] Formatting --- examples/radicale/default.nix | 52 ++++++++++++++++++----------------- modules/services/radicale.nix | 50 +++++++++++++++++++-------------- 2 files changed, 56 insertions(+), 46 deletions(-) diff --git a/examples/radicale/default.nix b/examples/radicale/default.nix index e7ccf8d..47a0578 100644 --- a/examples/radicale/default.nix +++ b/examples/radicale/default.nix @@ -1,40 +1,42 @@ -{ nglib, nixpkgs, ...}: +{ nglib, nixpkgs, ... }: nglib.makeSystem { inherit nixpkgs; system = "x86_64-linux"; name = "nixng-radicale"; - config = {...}: { - dinit.enable = true; - init.services.radicale = { - shutdownOnExit = true; + config = + { ... }: + { + dinit.enable = true; + init.services.radicale = { + shutdownOnExit = true; - ensureSomething.create."stateDir" = { - type = "directory"; - mode = "755"; - owner = "radicale:radicale"; - persistent = true; - dst = "/var/lib/radicale"; + ensureSomething.create."stateDir" = { + type = "directory"; + mode = "755"; + owner = "radicale:radicale"; + persistent = true; + dst = "/var/lib/radicale"; + }; }; - }; - services.radicale = { - enable = true; + services.radicale = { + enable = true; - settings = { - server = { - hosts = "0.0.0.0:5232, [::]:5232"; - ssl = false; - }; + settings = { + server = { + hosts = "0.0.0.0:5232, [::]:5232"; + ssl = false; + }; - auth = { - type = "none"; - }; + auth = { + type = "none"; + }; - storage = { - filesystem_folder = "/var/lib/radicale/collections"; + storage = { + filesystem_folder = "/var/lib/radicale/collections"; + }; }; }; }; - }; } diff --git a/modules/services/radicale.nix b/modules/services/radicale.nix index 2d19941..106f982 100644 --- a/modules/services/radicale.nix +++ b/modules/services/radicale.nix @@ -1,7 +1,13 @@ -{lib, pkgs, config, nglib, ...}: +{ + lib, + pkgs, + config, + nglib, + ... +}: let cfg = config.services.radicale; - + settingsFormat = pkgs.formats.ini { listToValue = lib.concatMapStringsSep ", " (lib.generators.mkValueStringDefault { }); }; @@ -46,30 +52,32 @@ in }; }; - config = lib.mkIf cfg.enable (let + config = lib.mkIf cfg.enable ( + let configFile = settingsFormat.generate "radicale.ini" cfg.settings; in { - init.services.radicale = { - enabled = true; + init.services.radicale = { + enabled = true; - script = pkgs.writeShellScript "radicale-run" '' - chpst -u ${cfg.user}:${cfg.group} ${cfg.package}/bin/radicale \ - --config ${configFile} - ''; - }; + script = pkgs.writeShellScript "radicale-run" '' + chpst -u ${cfg.user}:${cfg.group} ${cfg.package}/bin/radicale \ + --config ${configFile} + ''; + }; - environment.systemPackages = [ cfg.package ]; + environment.systemPackages = [ cfg.package ]; - users.users.${cfg.user} = nglib.mkDefaultRec { - description = "radicale"; - group = cfg.group; - createHome = false; - home = "/var/empty"; - useDefaultShell = true; - uid = config.ids.uids.radicale; - }; + users.users.${cfg.user} = nglib.mkDefaultRec { + description = "radicale"; + group = cfg.group; + createHome = false; + home = "/var/empty"; + useDefaultShell = true; + uid = config.ids.uids.radicale; + }; - users.groups.${cfg.group} = nglib.mkDefaultRec { gid = config.ids.gids.radicale; }; - }); + users.groups.${cfg.group} = nglib.mkDefaultRec { gid = config.ids.gids.radicale; }; + } + ); }