Refactor flake.nix parts into separate files

This commit is contained in:
Jez Cope 2021-09-11 21:46:46 +01:00
parent ac2d5e789c
commit f11d7a5970
4 changed files with 55 additions and 34 deletions

View File

@ -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;
};
}

13
nix/build.nix Normal file
View File

@ -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
'';
}

27
nix/server.nix Normal file
View File

@ -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 '<https://erambler.co.uk/rss.xml>; rel="self"';
'';
};
};
};
networking.firewall.allowedTCPPorts = [ 80 443 ];
}

11
nix/shell.nix Normal file
View File

@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
mkShell {
buildInputs = [
(python38.withPackages
(py: with py; [ python invoke rich requests ruamel_yaml sh ]))
yarn
hugo
];
}