Sites statique #5
5 changed files with 23 additions and 17 deletions
|
@ -1,11 +1,11 @@
|
||||||
# Inspire du club reseau
|
# Inspire du club reseau
|
||||||
{ ... }:
|
{ lib, ... }:
|
||||||
{
|
{
|
||||||
imports = [ ./modules/my.nix ];
|
imports = [ ./modules/my.nix ];
|
||||||
|
|
||||||
my = {
|
my = {
|
||||||
email = "hackens@clipper.ens.fr";
|
email = "hackens@clipper.ens.fr";
|
||||||
acmeStaging = true;
|
acmeStaging = lib.mkDefault true;
|
||||||
debug = false;
|
debug = false;
|
||||||
subZone = "new.hackens.org";
|
subZone = "new.hackens.org";
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{ lib, config , ... }:
|
{ lib, config , ... }:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
eachSite = config.services.staticWebsite;
|
eachSite = config.services.staticWebsites;
|
||||||
website = { name, ... }: {
|
website = { name, ... }: {
|
||||||
options = {
|
options = {
|
||||||
root = mkOption {
|
root = mkOption {
|
||||||
|
@ -16,14 +16,18 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
debug = config.my.debug;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.staticWebsite = lib.mkOption {
|
options.services.staticWebsites = {
|
||||||
type = types.attrsOf (types.submodule website);
|
sites = mkOption {
|
||||||
description = "Specification of one or more static-websites to serve";
|
type = types.attrsOf (types.submodule website);
|
||||||
|
description = "Specification of one or more static websites to serve";
|
||||||
|
};
|
||||||
|
debug = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf (eachSite != {}) {
|
config = mkIf (eachSite != {}) {
|
||||||
services.nginx = {
|
services.nginx = {
|
||||||
enable = true;
|
enable = true;
|
|
@ -3,12 +3,11 @@ with lib;
|
||||||
let
|
let
|
||||||
json = pkgs.formats.json {};
|
json = pkgs.formats.json {};
|
||||||
cfg = config.services.webhook;
|
cfg = config.services.webhook;
|
||||||
debug = config.my.debug;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.webhook = {
|
options.services.webhooks = {
|
||||||
enable = mkEnableOption "Set up webhooks";
|
enable = mkEnableOption "Set up webhooks";
|
||||||
pkg = mkOption {
|
package = mkOption {
|
||||||
type = types.package;
|
type = types.package;
|
||||||
default = pkgs.webhook;
|
default = pkgs.webhook;
|
||||||
description = "`webhook` package to use";
|
description = "`webhook` package to use";
|
||||||
|
@ -17,7 +16,7 @@ in
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The vhost on which webhook will listen";
|
description = "The vhost on which webhook will listen";
|
||||||
};
|
};
|
||||||
endPoint = mkOption {
|
endpoint = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "hooks";
|
default = "hooks";
|
||||||
description = "The endpoint of the webhooks";
|
description = "The endpoint of the webhooks";
|
||||||
|
@ -31,13 +30,16 @@ in
|
||||||
default = 9000;
|
default = 9000;
|
||||||
description = "The local port used to (proxy)pass requests from nginx to webhook";
|
description = "The local port used to (proxy)pass requests from nginx to webhook";
|
||||||
};
|
};
|
||||||
|
debug = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
};
|
};
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
services.nginx = {
|
services.nginx = {
|
||||||
enable = true;
|
enable = true;
|
||||||
virtualHosts."${cfg.hostname}" = {
|
virtualHosts."${cfg.hostname}" = {
|
||||||
locations."${cfg.endPoint}".proxyPass = "http://127.0.0.1:${toString cfg.internalPort}/hooks";
|
locations."${cfg.endpoint}".proxyPass = "http://127.0.0.1:${toString cfg.internalPort}/hooks";
|
||||||
enableACME = if debug then false else true;
|
enableACME = if cfg.debug then false else true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
systemd.services.webhook = {
|
systemd.services.webhook = {
|
||||||
|
@ -46,7 +48,7 @@ in
|
||||||
Description = "Small server for creating HTTP hooks";
|
Description = "Small server for creating HTTP hooks";
|
||||||
Documentation = "https://github.com/adnanh/webhook/";
|
Documentation = "https://github.com/adnanh/webhook/";
|
||||||
};
|
};
|
||||||
script = "${cfg.pkg}/bin/webhook -nopanic -ip \"127.0.0.1\" -port \"${toString cfg.internalPort}\" -verbose -hooks ${json.generate "conf.json" cfg.hooks}";
|
script = "${cfg.package}/bin/webhook -nopanic -ip \"127.0.0.1\" -port \"${toString cfg.internalPort}\" -verbose -hooks ${json.generate "conf.json" cfg.hooks}";
|
||||||
wantedBy = [ "mulit-user.target" ];
|
wantedBy = [ "mulit-user.target" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
{
|
{
|
||||||
services.staticWebsite.test = {
|
services.staticWebsites.test = {
|
||||||
hostname = "test.${config.my.subZone}";
|
hostname = "test.${config.my.subZone}";
|
||||||
root = pkgs.writeTextDir "index.html" "Hello world!";
|
root = pkgs.writeTextDir "index.html" "Hello world!";
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
{
|
{
|
||||||
services.webhook = {
|
services.webhooks = {
|
||||||
enable = true;
|
enable = true;
|
||||||
hostname = "test-webhook.${config.my.subZone}";
|
hostname = "test-webhook.${config.my.subZone}";
|
||||||
hooks = [
|
hooks = [
|
||||||
|
|
Loading…
Reference in a new issue