From 30e649a6d43c4ef2473a1820930cbe7d43e28432 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 2 Aug 2024 22:39:02 +0200 Subject: refactor(nixos/{nginx, nix-sync}): Migrate from `system/services` Nix-sync was sort-of mixed into the nginx configuration, thus separating it completely seemed reasonable. --- modules/nixos/vhack/nix-sync/default.nix | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 modules/nixos/vhack/nix-sync/default.nix (limited to 'modules/nixos/vhack/nix-sync/default.nix') diff --git a/modules/nixos/vhack/nix-sync/default.nix b/modules/nixos/vhack/nix-sync/default.nix new file mode 100644 index 0000000..a624e0e --- /dev/null +++ b/modules/nixos/vhack/nix-sync/default.nix @@ -0,0 +1,61 @@ +{ + config, + lib, + ... +}: let + cfg = config.vhack.nix-sync; + + mkNixSyncRepository = { + domain, + root ? "", + url, + extraSettings ? {}, + }: { + name = "${domain}"; + value = { + path = "/etc/nginx/websites/${domain}/${root}"; + uri = "${url}"; + inherit extraSettings; + }; + }; + nixSyncRepositories = builtins.listToAttrs (builtins.map mkNixSyncRepository domains); + + mkVirtHost = { + domain, + root ? "", + url, + extraSettings ? {}, + }: { + name = "${domain}"; + value = + lib.recursiveUpdate { + forceSSL = true; + enableACME = true; + root = "/etc/nginx/websites/${domain}/${root}"; + } + extraSettings; + }; + virtHosts = builtins.listToAttrs (builtins.map mkVirtHost domains); + + domains = import ./hosts.nix {}; +in { + imports = [ + ./module.nix + ]; + + options.vhack.nix-sync = { + enable = lib.mkEnableOption '' + a website git ops solution. + ''; + }; + + config = lib.mkIf cfg.enable { + services.nix-sync = { + enable = true; + repositories = nixSyncRepositories; + }; + + vhack.nginx.enable = true; + services.nginx.virtualHosts = virtHosts; + }; +} -- cgit 1.4.1