# 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"; 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"; }; 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 { # 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; include ${nginx.outPath}/conf/mime.types; server { listen ${nginxPort}; index index.html; location / { root ${packages.${system}.website}; } } } ''; in pkgs.dockerTools.buildLayeredImage { 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; }; 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 ]; } ]; }; }); }; }