{ description = "Angestöpselt Homepage"; inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; inputs.flake-utils.url = "github:numtide/flake-utils"; outputs = {self, nixpkgs, flake-utils }: let base = flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; nodejs = pkgs.nodejs-16_x; nodePackages = import ./nix/default.nix { inherit pkgs system nodejs; }; nodeDependencies = nodePackages.nodeDependencies.override { nativeBuildInputs = with pkgs; [ pkg-config ]; buildInputs = with pkgs; [ vips ]; dontNpmInstall = true; }; python = pkgs.python310.withPackages (ps: with ps; [ itsdangerous requests ]); in rec { packages = { site = pkgs.stdenv.mkDerivation { name = "angestoepselt-site"; src = self; buildInputs = [ nodejs nodeDependencies ]; SITE = "angestoepselt"; buildPhase = '' npm run build ''; installPhase = '' mv dist $out ''; }; lighttpdConfig = pkgs.substituteAll { src = ./sites/angestoepselt/httpd.conf; inherit (packages) site; inherit python; mimetypes = "${pkgs.lighttpd}/share/lighttpd/doc/config/conf.d/mime.conf"; cgibin = pkgs.copyPathToStore ./cgi-bin; }; container = pkgs.dockerTools.buildLayeredImage { name = "angestoepselt-site"; tag = "latest"; created = "now"; # See here for the documentation on this option: # https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions config = { Env = [ # We need to provide these default variables because otherwise # lighttpd doesn't even parse its configuration file: "ZAMMAD_URL=https://ticket.z31.it" "ZAMMAD_GROUP=" ]; ExposedPorts = { "80/tcp" = {}; }; # See here for the stdout redirection: # https://redmine.lighttpd.net/boards/2/topics/8382 Cmd = [ (pkgs.writeShellScript "angestoepselt-site" '' ${pkgs.coreutils}/bin/mkdir -p /var/tmp exec 3>&1 ${pkgs.lighttpd}/bin/lighttpd -Df ${packages.lighttpdConfig} '') ]; Healthcheck = { Test = [ "CMD" "${pkgs.curl}/bin/curl" "--fail" "localhost" ]; Interval = 30000000000; # 30 seconds Timeout = 10000000000; # 10 seconds Retries = 3; }; }; }; # This package isn't actually the fully-built site, but rather a # derivation that contains the relevant programs (with correctly set up # environment) to develop and build the site. It can either be used with # `nix develop` – see the repository's readme for details – or compiled # with `nix build`. The latter will output a folder which contains node # and npm binaries that can be used in an IDE. devEnv = pkgs.symlinkJoin { name = "devEnv"; buildInputs = [ pkgs.makeWrapper ]; paths = [ pkgs.lighttpd nodejs nodeDependencies python ]; postBuild = '' wrapProgram "$out/bin/node" \ --prefix PATH : "$out/lib/node_modules/.bin" \ --prefix NODE_PATH : "$out/lib/node_modules" ''; shellHook = '' export NODE_PATH=${nodeDependencies}/lib/node_modules export PATH="${pkgs.lighttpd}/bin:${nodeDependencies}/bin:${nodejs}/bin:${pkgs.nodePackages.npm-check-updates}/bin:${python}/bin:$PATH" echo "" echo " To start editing content, run:" echo "" echo "npm run build:styles" echo "npm run dev:site" echo "" echo " The site will be available under http://localhost:8080/ for" echo " local development and rebuilds automatically when content" echo " changes." echo "" ''; }; deployToProduction = pkgs.writeShellScript "deploy-to-production" '' echo "Deploying ${packages.container} ..." ${pkgs.curl}/bin/curl 62.146.78.173:9337/hooks/angestoepselt_homepage ''; }; defaultPackage = packages.angestoepseltSite; devShell = packages.devEnv; }); in (base // { hydraJobs = rec { inherit (base.packages.x86_64-linux) site; container = let pkgs = import nixpkgs { system = "x86_64-linux"; }; containerFile = base.packages.x86_64-linux.container; in pkgs.runCommand "container" {} '' mkdir -p $out/nix-support ln -s ${containerFile} $out/angestoepselt-site.tar.gz echo "file oci $out/angestoepselt-site.tar.gz" > $out/nix-support/hydra-build-products ''; }; }); }