From 9ea565566922e785bab859a8de0335f3b65c4549 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 4 Jan 2025 17:36:30 +0000 Subject: [PATCH] nixedo: add beaverhabits --- nix/hosts/nixedo/default.nix | 1 + .../nixos/features/homelab/beaverhabits.nix | 102 ++++++++++++++++++ .../nixos/features/homelab/default.nix | 1 + 3 files changed, 104 insertions(+) create mode 100644 nix/modules/nixos/features/homelab/beaverhabits.nix diff --git a/nix/hosts/nixedo/default.nix b/nix/hosts/nixedo/default.nix index b001149..5a6d0ad 100644 --- a/nix/hosts/nixedo/default.nix +++ b/nix/hosts/nixedo/default.nix @@ -6,6 +6,7 @@ homelab = { audiobookshelf.enable = true; + beaverhabits.enable = true; forgejo.enable = true; freshrss.enable = true; gitea.enable = true; diff --git a/nix/modules/nixos/features/homelab/beaverhabits.nix b/nix/modules/nixos/features/homelab/beaverhabits.nix new file mode 100644 index 0000000..98f362c --- /dev/null +++ b/nix/modules/nixos/features/homelab/beaverhabits.nix @@ -0,0 +1,102 @@ +# Auto-generated using compose2nix v0.3.2-pre. +{ + config, + pkgs, + lib, + ... +}: + +with lib; + +let + cfg = config.features.homelab.beaverhabits; + + port = 8084; +in +{ + options.features.homelab.beaverhabits.enable = mkEnableOption "Enable beaverhabits"; + + config = mkIf cfg.enable { + virtualisation = { + docker = { + enable = true; + autoPrune.enable = true; + }; + + oci-containers = { + backend = "docker"; + + containers."beaverhabits" = { + image = "daya0576/beaverhabits:latest"; + + environment = { + "HABITS_STORAGE" = "DATABASE"; + }; + + volumes = [ + "/mnt/media/beaverhabits:/app/.user:rw" + ]; + + ports = [ + "${toString port}:8080/tcp" + ]; + + user = "1000:1000"; + + log-driver = "journald"; + + extraOptions = [ + "--network-alias=beaverhabits" + "--network=beaverhabits_default" + ]; + }; + }; + }; + + systemd = { + services = { + "docker-beaverhabits" = { + serviceConfig = { + Restart = lib.mkOverride 90 "always"; + RestartMaxDelaySec = lib.mkOverride 90 "1m"; + RestartSec = lib.mkOverride 90 "100ms"; + RestartSteps = lib.mkOverride 90 9; + }; + + after = [ "docker-network-beaverhabits_default.service" ]; + requires = [ "docker-network-beaverhabits_default.service" ]; + partOf = [ "docker-compose-beaverhabits-root.target" ]; + wantedBy = [ "docker-compose-beaverhabits-root.target" ]; + }; + + "docker-network-beaverhabits_default" = { + path = [ pkgs.docker ]; + + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStop = "docker network rm -f beaverhabits_default"; + }; + + script = '' + docker network inspect beaverhabits_default || docker network create beaverhabits_default + ''; + + partOf = [ "docker-compose-beaverhabits-root.target" ]; + wantedBy = [ "docker-compose-beaverhabits-root.target" ]; + }; + }; + + targets."docker-compose-beaverhabits-root" = { + unitConfig.Description = "Root target generated by compose2nix."; + wantedBy = [ "multi-user.target" ]; + }; + }; + + services.caddy.virtualHosts."beaverhabits.opdavies.uk" = { + useACMEHost = "opdavies.uk"; + + extraConfig = "reverse_proxy localhost:${toString port}"; + }; + }; +} diff --git a/nix/modules/nixos/features/homelab/default.nix b/nix/modules/nixos/features/homelab/default.nix index 7231aa8..897465c 100644 --- a/nix/modules/nixos/features/homelab/default.nix +++ b/nix/modules/nixos/features/homelab/default.nix @@ -1,6 +1,7 @@ { imports = [ ./audiobookshelf.nix + ./beaverhabits.nix ./forgejo.nix ./freshrss.nix ./gitea.nix