Start migrating config to NixOS modules

This commit is contained in:
Paul-Henri Froidmont 2022-09-16 01:29:46 +02:00
parent c1211cb4e5
commit c0d929be0b
Signed by: phfroidmont
GPG key ID: BE948AFD7E7873BE
11 changed files with 283 additions and 183 deletions

View file

@ -1,32 +1,40 @@
{ config, ... }:
{ config, lib, ... }:
with lib;
let
cfg = config.custom.services.binary-cache;
in
{
options.custom.services.binary-cache = {
sops.secrets = {
nixCacheKey = {
key = "nix/cache_secret_key";
enable = mkEnableOption "binary-cache";
secretKeyFile = mkOption {
type = types.path;
};
};
services.nix-serve = {
enable = true;
port = 1500;
secretKeyFile = config.sops.secrets.nixCacheKey.path;
};
config = mkIf cfg.enable {
services.nix-serve = {
enable = true;
port = 1500;
secretKeyFile = config.sops.secrets.nixCacheKey.path;
};
services.nginx = {
virtualHosts = {
"cache.${config.networking.domain}" = {
services.nginx = {
virtualHosts = {
"cache.${config.networking.domain}" = {
enableACME = true;
forceSSL = true;
enableACME = true;
forceSSL = true;
locations."/".extraConfig = ''
proxy_pass http://localhost:${toString config.services.nix-serve.port};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
'';
locations."/".extraConfig = ''
proxy_pass http://localhost:${toString config.services.nix-serve.port};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
'';
};
};
};
};