Skip to content

Commit

Permalink
webfortune: init
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <me@sumnerevans.com>
  • Loading branch information
sumnerevans committed Nov 8, 2023
1 parent 582095f commit 6ecaf21
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 7 deletions.
32 changes: 28 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
webfortune = {
url = "github:sumnerevans/webfortune";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};

outputs = { self, nixpkgs, flake-utils }@inputs: {
outputs = inputs@{ self, nixpkgs, flake-utils, webfortune }: {
nixosConfigurations = {
tatooine = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
Expand Down
16 changes: 15 additions & 1 deletion host-configurations/morak.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{ config, lib, pkgs, modulesPath, ... }: with lib; {
{ config, lib, pkgs, modulesPath, inputs, ... }: with lib; let
quotesfile = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/sumnerevans/home-manager-config/master/modules/email/quotes";
hash = "sha256-79oQM/7QyVRDXV+BBz6qfhp7n6dakaNgJAMvnbqGPx0=";
};
in
{
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];

boot = {
Expand Down Expand Up @@ -124,6 +130,14 @@
services.backup.healthcheckId = "6c9caf62-4f7b-4ef7-82ac-d858d3bcbcb5";
services.backup.healthcheckPruneId = "f90ed04a-2596-49d0-a89d-764780a27fc6";

# Webfortune
services.webfortune = {
enable = true;
inherit quotesfile;
sourceUrl = "https://github.com/sumnerevans/home-manager-config/blob/master/modules/email/quotes";
virtualHost = "fortune.sumnerevans.com";
};

# Add a backup service for the actual config.
services.backup.backups.syncthing-pictures-tmp-data = {
path = "/mnt/syncthing-pictures-tmp";
Expand Down
2 changes: 1 addition & 1 deletion host-configurations/tatooine.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ modulesPath, ... }: {
{ modulesPath, pkgs, ... }: {
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];

boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "virtio_pci" "sd_mod" "sr_mod" ];
Expand Down
1 change: 1 addition & 0 deletions modules/services/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
./restic.nix
./sshd.nix
./syncthing.nix
./webfortune.nix
./xandikos.nix
];

Expand Down
58 changes: 58 additions & 0 deletions modules/services/webfortune.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{ config, inputs, lib, pkgs, ... }:
with lib;
let
cfg = config.services.webfortune;
in
{
options = {
services.webfortune = {
enable = mkEnableOption "webfortune";
quotesfile = mkOption {
type = types.path;
description = "Path to the quotesfile";
};
sourceUrl = mkOption {
type = types.str;
description = "URL to the quotesfile";
};
virtualHost = mkOption {
type = types.str;
description = "The virtual host to use";
};
listenAddr = mkOption {
type = types.str;
default = "0.0.0.0:8477";
description = "Address to listen on";
};
};
};

config = mkIf cfg.enable {
services.nginx = {
enable = true;
virtualHosts.${cfg.virtualHost} = {
addSSL = true;
enableACME = true;
locations."/" = {
recommendedProxySettings = true;
proxyPass = "http://${cfg.listenAddr}";
};
};
};

systemd.services.webfortune = {
description = "webfortune";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
environment = {
QUOTESFILE = cfg.quotesfile;
QUOTESFILE_SOURCE_URL = cfg.sourceUrl;
LISTEN_ADDR = cfg.listenAddr;
};
serviceConfig = {
ExecStart = "${inputs.webfortune.packages.${pkgs.system}.webfortune}/bin/webfortune";
Restart = "always";
};
};
};
}

0 comments on commit 6ecaf21

Please sign in to comment.