DEVELOPMENT ENVIRONMENT

~liljamo/nix-arta

nix-arta/lxc/hosts/cloud/default.nix -rw-r--r-- 5.9 KiB
5cced0a1Jonni Liljamo feat(lxc): update to 24.11, make required changes an hour ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
{
  config,
  lib,
  pkgs,
  ...
}: let
  outlinePort = 3000;
in {
  imports = [
    ./miniflux.nix
    ./vikunja.nix
  ];
  sops.secrets.rootPwd.neededForUsers = true;

  roles.base.root.hashedPasswordFile = config.sops.secrets.rootPwd.path;

  # Outline is under BSL1.1.
  roles.unfree.allow = ["outline"];

  networking.firewall.allowedTCPPorts = [80 config.services.outline.port];

  sops.secrets."outline/secretKey" = {
    owner = "outline";
    group = "outline";
  };
  sops.secrets."outline/utilsSecret" = {
    owner = "outline";
    group = "outline";
  };
  sops.secrets."outline/oidcSecret" = {
    owner = "outline";
    group = "outline";
  };
  sops.secrets."outline/smtpPwd" = {
    owner = "outline";
    group = "outline";
  };
  sops.secrets."nextcloud/adminpass" = {
    owner = "nextcloud";
    group = "nextcloud";
  };
  sops.secrets."nextcloud/dbpass" = {
    owner = "nextcloud";
    group = "nextcloud";
  };

  environment.systemPackages = with pkgs; [
    ffmpeg-headless
    gnumake
    nodePackages_latest.nodejs
    nodePackages_latest.node-pre-gyp
    python3
  ];
  users.users.nextcloud.extraGroups = ["render" "users"];

  services = {
    nextcloud = {
      enable = true;
      package = pkgs.nextcloud30;
      caching = {
        redis = true;
      };
      config = {
        adminpassFile = config.sops.secrets."nextcloud/adminpass".path;
        adminuser = "admin";
        dbhost = "127.0.0.1:5432";
        dbname = "nextcloud";
        dbtype = "pgsql";
        dbuser = "nextcloud";
        dbpassFile = config.sops.secrets."nextcloud/dbpass".path;
      };
      configureRedis = true;
      settings = {
        default_phone_region = "FI";
        loglevel = 2;
        log_type = "file";
        maintenance_window_start = 0; # Maintenance window from UTC 0000 to 0400.
        redis = {
          host = "/run/redis-nextcloud/redis.sock";
        };
        trusted_domains = ["nextcloud.rustylily.home.arpa"];
        trusted_proxies = ["10.1.2.10"];
        overwriteprotocol = "https";

        # OPcache memory settings, values are in megabytes.
        opcache.interned_strings_buffer = 32; # Default is 8.
        opcache.memory_consumption = 256; # Default is 128.

        # Programs needed for... stuff.
        preview_ffmpeg_path = "${lib.getExe pkgs.ffmpeg}";
        memories.exiftool = "${lib.getExe pkgs.exiftool}";
        memories.exiftool_no_local = true;
        memories.ffmpeg_path = "${pkgs.ffmpeg-headless}/bin/ffmpeg";
        memories.ffprobe_path = "${pkgs.ffmpeg-headless}/bin/ffprobe";
        memories.vod.ffmpeg = "${pkgs.ffmpeg-headless}/bin/ffmpeg";
        memories.vod.ffprobe = "${pkgs.ffmpeg-headless}/bin/ffprobe";
      };
      hostName = "cloud.liljamo.com";
      https = true;
      maxUploadSize = "2048M";
      phpOptions."output_buffering" = "0";
      phpExtraExtensions = all: [all.pdlib all.bz2];
    };
    outline = {
      enable = true;
      port = outlinePort;
      user = "outline";
      group = "outline";
      databaseUrl = "postgres://outline:outline@127.0.0.1/outline?sslmode=disable";
      redisUrl = "redis://127.0.0.1:3079";
      enableUpdateCheck = false;
      maximumImportSize = 5120000;
      publicUrl = "https://docs.liljamo.com";
      secretKeyFile = config.sops.secrets."outline/secretKey".path;
      utilsSecretFile = config.sops.secrets."outline/utilsSecret".path;
      storage = {
        storageType = "local";
      };
      oidcAuthentication = {
        authUrl = "https://auth.liljamo.com/api/oidc/authorization";
        clientId = "outline";
        clientSecretFile = config.sops.secrets."outline/oidcSecret".path;
        displayName = "Liljamo Auth";
        scopes = ["openid" "offline_access" "profile" "email"];
        tokenUrl = "https://auth.liljamo.com/api/oidc/token";
        userinfoUrl = "https://auth.liljamo.com/api/oidc/userinfo";
        usernameClaim = "preferred_username";
      };
      smtp = {
        host = "smtp.migadu.com";
        port = 465;
        fromEmail = "outline@liljamo.com";
        replyEmail = "outline@liljamo.com";
        username = "outline@liljamo.com";
        passwordFile = config.sops.secrets."outline/smtpPwd".path;
      };
    };
    postgresql = {
      package = pkgs.postgresql_15;
      enable = true;
      settings.port = 5432;
      ensureDatabases = ["outline" "nextcloud"];
      ensureUsers = [
        {
          name = "outline";
          ensureDBOwnership = true;
        }
        {
          name = "nextcloud";
          ensureDBOwnership = true;
        }
      ];
    };
    redis.servers = {
      outline = {
        enable = true;
        bind = "127.0.0.1";
        port = 3079;
      };
      nextcloud = {
        enable = true;
        bind = "127.0.0.1";
        port = 3179;
      };
    };
  };

  systemd = {
    timers = {
      nextcloud-update-files = {
        wantedBy = ["timers.target"];
        timerConfig = {
          OnBootSec = "2m";
          OnUnitActiveSec = "15m";
          Unit = "nextcloud-update-files.service";
        };
      };
    };
    services = {
      nextcloud-cron.path = [pkgs.perl];
      nextcloud-update-files = {
        bindsTo = ["postgresql.service" "phpfpm-nextcloud.service"];
        after = ["postgresql.service" "phpfpm-nextcloud.service"];
        script = ''
          ${config.services.nextcloud.occ}/bin/nextcloud-occ files:scan -q --all
          ${config.services.nextcloud.occ}/bin/nextcloud-occ preview:pre-generate
        '';
        serviceConfig.User = "nextcloud";
        path = ["config.services.nextcloud" pkgs.perl];
      };
      nextcloud-occ-settings = {
        after = ["nextcloud-setup.service"];
        serviceConfig = {
          Type = "oneshot";
          User = "nextcloud";
        };
        script = ''
          ${config.services.nextcloud.occ}/bin/nextcloud-occ config:app:set dav system_addressbook_exposed --value="no"
        '';
      };
    };
  };

  system.stateVersion = "24.05";
}