blog/flake.nix

98 lines
2.4 KiB
Nix

{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flutils.url = "github:numtide/flake-utils";
nixng = {
url = "github:pizzapim/NixNG/kubernetes";
inputs.nixpkgs.follows = "nixpkgs";
};
nginx = {
url = "github:nginx/nginx";
flake = false;
};
};
outputs = { self, nixpkgs, flutils, nixng, nginx, ...}: flutils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
gems = pkgs.bundlerEnv {
name = "blog";
gemdir = ./src;
};
patch-feed-date = pkgs.stdenv.mkDerivation {
name = "path-feed-date";
propagatedBuildInputs = [ pkgs.python3 ];
dontUnpack = true;
installPhase = "install -Dm755 ${./patch-feed-date.py} $out/bin/patch-feed-date";
};
nginxPort = "80";
nginxConf = pkgs.writeText "nginx.conf" ''
user nginx nginx;
daemon off;
error_log /dev/stderr;
pid /httpd.pid;
events {}
http {
access_log /dev/stdout;
include ${nginx.outPath}/conf/mime.types;
server {
listen ${nginxPort};
index index.html;
location / {
root ${self.packages.${system}.default};
}
}
}
'';
in
{
packages.default = pkgs.stdenv.mkDerivation {
name = "blog";
src = ./src;
sourceRoot = "src";
buildInputs = [
gems
gems.wrappedRuby
patch-feed-date
];
buildPhase = ''
bundle exec jekyll build --future
'';
installPhase = ''
mkdir -p $out
cp -r _site/* $out/
patch-feed-date --file _site/feed.xml > $out/feed.xml
'';
};
nixngConfigurations.default = nixng.nglib.makeSystem {
inherit nixpkgs system;
name = "nixng-blog";
config = {config, lib, ...}: {
dinit.enable = true;
init.services.nginx = {
shutdownOnExit = true;
script = lib.mkForce (pkgs.writeShellScript "nginx-run" ''
HOME=~nginx ${config.services.nginx.package}/bin/nginx -c ${nginxConf}
'');
};
services.nginx = {
enable = true;
configuration = [];
};
};
};
});
}