website/flake.nix
Magic_RB c09e618bc1
Update rlib
Signed-off-by: Magic_RB <magic_rb@redalder.org>
2021-03-31 12:45:54 +02:00

144 lines
4.2 KiB
Nix

{
inputs = {
nixpkgs.url = "nixpkgs";
org-thtml = {
url = "github:juanjosegarciaripoll/org-thtml";
flake = false;
};
emacs-htmlize = {
url = "github:hniksic/emacs-htmlize";
flake = false;
};
rlib = {
url = "git+https://gitea.redalder.org/RedAlder/rlib";
flake = true;
};
};
outputs = { self, nixpkgs, org-thtml, emacs-htmlize, ... }@inputs:
let
supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
rlib = inputs.rlib.lib {
inherit nixpkgs;
system = "x86_64-linux";
packages = {
nixpkgs = {
config = {};
versions = {
stable = inputs.nixpkgs;
};
};
custom = {};
};
self = rlib;
};
websiteBase = pkgs:
pkgs.stdenv.mkDerivation {
name = "magic_rb-website";
version = "0.1";
src = ./.;
nativeBuildInputs = [ pkgs.emacs ];
buildPhase = ''
cp ${org-thtml}/ox-thtml.el ./ox-thtml.el
cp ${emacs-htmlize}/htmlize.el ./htmlize.el
mkdir tmp && export HOME=$(pwd)/tmp
emacs --script ./make.el
find public_html -name 'sitemap.*' -exec rm {} \;
'';
installPhase = ''
mkdir -p $out
cp -r public_html/* $out
'';
};
in
{
website = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };
in
websiteBase pkgs
);
dockerImages = with rlib.dockerTools; {
apache = buildLayeredImage
({ nixpkgs, custom, rlib }:
with rlib.dockerTools;
let
shadow = makeShadow {
withNixbld = false;
users = [
{
name = "www-data";
uid = "5000";
gid = "5000";
home = "/var/empty";
shell = "${nixpkgs.stable.bash}/bin/bash";
description = "Apache HTTPD user";
}
];
groups = [
{
name = "www-data";
id = 5000;
}
];
};
ca-certificates = makeCerts {
certs = [];
};
apache = nixpkgs.stable.apache.override {
proxySupport = false;
sslSupport = false;
http2Support = false;
ldapSupport = false;
libxml2Support = false;
brotliSupport = false;
};
entrypoint = nixpkgs.stable.writeShellScriptBin "entrypoint.sh" (builtins.readFile ./docker/entrypoint.sh);
website = nixpkgs.stable.runCommandNoCCLocal "website" {} ''
mkdir -p $out/var/
ln -s ${websiteBase nixpkgs.stable} $out/var/www
'';
logs = nixpkgs.stable.runCommandNoCCLocal "logs" {} ''
mkdir -p $out/var/log/apache2
'';
in
{
name = "magic_rb-website-apache";
tag = "latest";
contents = [
entrypoint
shadow
ca-certificates
makeBasicBin
website
logs
];
config = with nixpkgs.stable; {
Entrypoint = [ "${dumb-init}/bin/dumb-init" "--" "/bin/entrypoint.sh" ];
Env = [
"PATH=${lib.makeBinPath [ busybox apacheHttpd bash ]}"
"_apache_cfg=${./docker/apache.cfg}"
];
};
extraCommands = ''
mkdir -p tmp var/empty
chmod 777 tmp
'';
});
};
};
}