dotfiles/nixos/modules/muflax-blog.nix

62 lines
2.0 KiB
Nix
Raw Permalink Normal View History

2022-05-15 14:35:03 +02:00
{ pkgs, config, lib, ... }:
let
cfg = config.services.muflax-blog;
2018-03-11 18:28:25 +01:00
muflax-source = builtins.fetchGit {
2016-09-19 21:02:33 +02:00
rev = "e5ce7ae4296c6605a7e886c153d569fc38318096";
2018-03-11 18:28:25 +01:00
ref = "HEAD";
url = "https://github.com/fmap/muflax65ngodyewp.onion.git";
2021-05-29 18:05:31 +02:00
};
nixpkgs = import (builtins.fetchTarball {
url =
"https://github.com/NixOS/nixpkgs-channels/archive/78e9665b48ff45d3e29f45b3ebeb6fc6c6e19922.tar.gz";
sha256 = "09f50jaijvry9lrnx891qmcf92yb8qs64n1cvy0db2yjrmxsxyw8";
2022-05-15 14:35:03 +02:00
}) { system = pkgs.stdenv.system; };
2021-05-29 18:05:31 +02:00
blog = lib.overrideDerivation
(nixpkgs.callPackage "${muflax-source}/maintenance" { }) (default: {
buildPhase = default.buildPhase + "\n" + ''
grep -lr '[^@]muflax.com' out | xargs -r sed -i 's/\([^@]\)muflax.com/\1${cfg.hidden-service.hostname}/g'
'';
});
in with lib; {
options.services.muflax-blog = {
2021-05-29 18:05:31 +02:00
enable = mkOption {
type = types.bool;
default = false;
};
2021-05-29 18:05:31 +02:00
web-server = { port = mkOption { type = types.int; }; };
hidden-service = {
2021-05-29 18:05:31 +02:00
hostname = mkOption { type = types.str; };
private_key = mkOption { type = types.str; };
};
};
config = mkIf cfg.enable {
services.nginx = {
enable = true;
appendHttpConfig = ''
server {
index index.html;
port_in_redirect off;
listen 127.0.0.1:${toString cfg.web-server.port};
server_name ${cfg.hidden-service.hostname};
root ${blog}/muflax;
}
'' + concatStringsSep "\n" (map (site: ''
server {
index index.html;
port_in_redirect off;
listen 127.0.0.1:${toString cfg.web-server.port};
server_name ${site}.${cfg.hidden-service.hostname};
root ${blog}/${site};
}
2021-05-29 18:05:31 +02:00
'') [ "daily" "gospel" "blog" ]);
};
2018-11-20 22:31:05 +01:00
services.tor.enable = true;
2021-06-06 19:34:30 +02:00
services.tor.relay.onionServices.muflax-blog.map = [{
2021-05-29 18:05:31 +02:00
port = 80;
2021-06-06 19:34:30 +02:00
target.port = cfg.web-server.port;
2021-05-29 18:05:31 +02:00
}];
2018-03-11 18:28:25 +01:00
services.tor.service-keys.muflax-blog = cfg.hidden-service.private_key;
};
2018-03-11 18:28:25 +01:00
}