diff --git a/flake.nix b/flake.nix index 2419828..57f2632 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "A very basic flake"; + description = "Content and server config for erambler.co.uk"; inputs.nixpkgs.url = "github:NixOS/nixpkgs"; inputs.flake-utils.url = "github:numtide/flake-utils"; @@ -8,39 +8,9 @@ (flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; in { - defaultPackage = pkgs.stdenv.mkDerivation { - name = "erambler-html"; - src = ./.; - nativeBuildInputs = [ pkgs.hugo ]; - buildPhase = "hugo"; - installPhase = '' - mkdir $out - cp -R public/* public/.well-known $out - ''; - }; - - devShell = pkgs.mkShell { - buildInputs = with pkgs; [ - (python38.withPackages - (py: with py; [ python invoke rich requests ruamel_yaml sh ])) - yarn - hugo - ]; - }; + defaultPackage = pkgs.callPackage ./nix/build.nix { }; + devShell = pkgs.callPackage ./nix/shell.nix { }; })) // { - nixosModule = { config, pkgs, ... }: { - services.nginx = { - enable = true; - - virtualHosts."erambler.co.uk" = { - enableACME = true; - forceSSL = true; - - root = self.defaultPackage.${pkgs.system}; - }; - }; - - networking.firewall.allowedTCPPorts = [ 80 443 ]; - }; + nixosModule = import ./nix/server.nix; }; } diff --git a/nix/build.nix b/nix/build.nix new file mode 100644 index 0000000..59ac3c3 --- /dev/null +++ b/nix/build.nix @@ -0,0 +1,13 @@ +{ pkgs, ... }: + +with pkgs; +stdenv.mkDerivation { + name = "erambler-html"; + src = ./.; + nativeBuildInputs = [ hugo ]; + buildPhase = "hugo"; + installPhase = '' + mkdir $out + cp -R public/* public/.well-known $out + ''; +} diff --git a/nix/server.nix b/nix/server.nix new file mode 100644 index 0000000..0fbc218 --- /dev/null +++ b/nix/server.nix @@ -0,0 +1,27 @@ +{ config, pkgs, ... }: + +{ + services.nginx = { + enable = true; + + virtualHosts."erambler.co.uk" = { + enableACME = true; + forceSSL = true; + + root = self.defaultPackage.${pkgs.system}; + extraConfig = '' + rewrite ^/.well-known/(host-meta|webfinger).* https://fed.brid.gy$request_uri redirect; + ''; + locations = { + "~ ^/(feed|rss)(\\.xml|/)".return = "301 /index.xml"; + "~ ^/tags/([a-zA-Z-]+)\\.xml".return = "301 /tags/$1/index.xml"; + + "/index.xml".extraConfig = '' + add_header Link '; rel="self"'; + ''; + }; + }; + }; + + networking.firewall.allowedTCPPorts = [ 80 443 ]; +} diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..3395bcf --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,11 @@ +{ pkgs ? import { } }: + +with pkgs; +mkShell { + buildInputs = [ + (python38.withPackages + (py: with py; [ python invoke rich requests ruamel_yaml sh ])) + yarn + hugo + ]; +}