diff --git a/flake.lock b/flake.lock index 3cfbd17..2f05ab5 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1697723726, - "narHash": "sha256-SaTWPkI8a5xSHX/rrKzUe+/uVNy6zCGMXgoeMb7T9rg=", + "lastModified": 1699099776, + "narHash": "sha256-X09iKJ27mGsGambGfkKzqvw5esP1L/Rf8H3u3fCqIiU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "7c9cc5a6e5d38010801741ac830a3f8fd667a7a0", + "rev": "85f1ba3e51676fa8cc604a3d863d729026a6b8eb", "type": "github" }, "original": { @@ -37,7 +37,8 @@ "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "webfortune": "webfortune" } }, "systems": { @@ -54,6 +55,29 @@ "repo": "default", "type": "github" } + }, + "webfortune": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1699458242, + "narHash": "sha256-khZACvN8CwU1lpwzb4VrcTAIQO47PViI//9nST2zPbU=", + "owner": "sumnerevans", + "repo": "webfortune", + "rev": "6b61d41f3aaf7b40a5b0073892bdbc5c80c7a8f3", + "type": "github" + }, + "original": { + "owner": "sumnerevans", + "repo": "webfortune", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index e53927f..6a85033 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; diff --git a/host-configurations/morak.nix b/host-configurations/morak.nix index b7a651a..602b8b7 100644 --- a/host-configurations/morak.nix +++ b/host-configurations/morak.nix @@ -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 = { @@ -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"; diff --git a/host-configurations/tatooine.nix b/host-configurations/tatooine.nix index 696a4fe..8e839fe 100644 --- a/host-configurations/tatooine.nix +++ b/host-configurations/tatooine.nix @@ -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" ]; diff --git a/modules/services/default.nix b/modules/services/default.nix index 3f5c5b5..67f4b95 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -18,6 +18,7 @@ ./restic.nix ./sshd.nix ./syncthing.nix + ./webfortune.nix ./xandikos.nix ]; diff --git a/modules/services/webfortune.nix b/modules/services/webfortune.nix new file mode 100644 index 0000000..cf27f1a --- /dev/null +++ b/modules/services/webfortune.nix @@ -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"; + }; + }; + }; +}