This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
static/flake.nix

145 lines
3.9 KiB
Nix
Raw Permalink Normal View History

# Inspiration from: https://technogothic.net/pages/JekyllOnNix/
{
inputs = {
nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
systems.url = "github:nix-systems/default";
devenv.url = "github:cachix/devenv";
devenv.inputs.nixpkgs.follows = "nixpkgs";
2024-04-21 09:48:38 +00:00
nginx = {
url = "github:nginx/nginx";
flake = false;
};
};
nixConfig = {
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
extra-substituters = "https://devenv.cachix.org";
};
2024-04-21 09:48:38 +00:00
outputs = { self, nixpkgs, devenv, systems, nginx, ... }@inputs:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
rec {
packages = forEachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
2024-04-21 09:48:38 +00:00
# Copied from: https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/docker/examples.nix
nginx =
let
nginxPort = "80";
nginxConf = pkgs.writeText "nginx.conf" ''
user nobody nobody;
daemon off;
error_log /dev/stdout info;
pid /dev/null;
events {}
http {
access_log /dev/stdout;
2024-04-21 09:48:38 +00:00
include ${nginx.outPath}/conf/mime.types;
server {
listen ${nginxPort};
index index.html;
location / {
root ${packages.${system}.website};
}
}
}
'';
in
pkgs.dockerTools.buildLayeredImage {
2024-04-21 10:01:45 +00:00
name = "static";
tag = "test";
contents = [
pkgs.fakeNss
pkgs.nginx
];
extraCommands = ''
mkdir -p tmp/nginx_client_body
# nginx still tries to read this directory even if error_log
# directive is specifying another file :/
mkdir -p var/log/nginx
'';
config = {
Cmd = [ "nginx" "-c" nginxConf ];
ExposedPorts = {
"${nginxPort}/tcp" = { };
};
};
};
website = pkgs.stdenv.mkDerivation
(
let
# TODO: DRY
gems = pkgs.bundlerEnv {
name = "static";
gemdir = ./src;
};
patch-feed-date = pkgs.stdenv.mkDerivation {
name = "patch-feed-date";
propagatedBuildInputs = [ pkgs.python3 ];
dontUnpack = true;
installPhase = "install -Dm755 ${./patch-feed-date.py} $out/bin/patch-feed-date";
};
in
{
version = "0.0.1";
name = "website";
src = ./src;
buildInputs = [
gems
gems.wrappedRuby
patch-feed-date
];
sourceRoot = "src";
buildPhase = ''
bundle exec jekyll build
'';
installPhase = ''
mkdir -p $out
cp -r _site/* $out/
patch-feed-date --file _site/feed.xml > $out/feed.xml
'';
}
);
}
);
devShells = forEachSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
gems = pkgs.bundlerEnv {
name = "static";
gemdir = ./src;
};
in
{
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
{
packages = [ gems gems.wrappedRuby ];
}
];
};
});
};
}