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

140 lines
3.7 KiB
Nix

# 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";
};
nixConfig = {
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
extra-substituters = "https://devenv.cachix.org";
};
outputs = { self, nixpkgs, devenv, systems, ... } @ inputs:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
rec {
packages = forEachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
# images.hello = pkgs.dockerTools.buildImage {
# name = "hello-docker";
# copyToRoot = pkgs.buildEnv {
# name = "image-root";
# paths = [ pkgs.bashInteractive ];
# pathsToLink = [ "/bin" ]; # For bash
# };
# config = {
# Cmd = [ "${pkgs.coreutils}/bin/sleep" "99999" ];
# };
# };
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;
include ${./mime.types};
server {
listen ${nginxPort};
index index.html;
location / {
root ${packages.${system}.website};
}
}
}
'';
in
pkgs.dockerTools.buildLayeredImage {
name = "nginx-container";
tag = "latest";
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;
};
in
{
version = "0.0.1";
name = "website";
src = ./src;
buildInputs = [
gems
gems.wrappedRuby
];
sourceRoot = "src";
buildPhase = ''
bundle exec jekyll build
'';
installPhase = ''
mkdir -p $out
cp -r _site/* $out/
'';
}
);
}
);
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 ];
}
];
};
});
};
}