make working on websites nicer

(since every time we have to change anything on these I get annoyed at
having to remember how to build these. Now you can just use `nix run`!)
nextcloud-docs-on-website
stuebinm 9 months ago
parent 7fd1c9ff80
commit a6d21f4fd9

@ -36,6 +36,23 @@ nix build .#nixosConfigurations.parsons.config.system.build.toplevel
(but you might have trouble deploying it)
## Working on websites
Websites are exposed as flake outputs: if you're working on a website & want to
check it in a browser, do e.g.
~~~shell
nix run .#\"muc.hacc.earth\"
~~~
to start a local http server (note that some of our websites need a directory
to be built in; these use `/tmp/hacc-website`).
To add a new website, add a new subdirectory to `websites`; nix will generate a
vhost config based on that directory's name. Add a `default.nix` in your directory
describing how to build the website, and give its derivation a `watch` attribute
to make the `nix run` setup work.
## I don't want to build this long dependency / want a cached version!
If it's still available on parsons from a previous deploy, do:

@ -85,6 +85,9 @@
checks = builtins.mapAttrs
(system: deployLib: deployLib.deployChecks self.deploy)
deploy-rs.lib;
packages.x86_64-linux =
self.nixosConfigurations.parsons.config.hacc.websites.builders;
};
}

@ -21,33 +21,42 @@ in
default = [];
description = "subdirectories that shouldn't be published";
};
builders = mkOption {
type = types.lazyAttrsOf types.package;
default = {};
description = "exposes website builders, for use with nix run";
};
};
config = mkIf cfg.enable {
config = let
subdirs =
let dirAttrs = filterAttrs
(n: v: v == "directory" || lists.elem n cfg.ignore)
(builtins.readDir cfg.directory);
in mapAttrsToList (n: v: n) dirAttrs;
mkWebsiteDrv = subdir:
pkgs.callPackage "${cfg.directory}/${subdir}" {};
mkWebsiteVHost = subdir: {
name = subdir;
# the nginx virtualhost config (for all sites) goes in here
value = {
enableACME = true;
forceSSL = true;
locations."/".root =
(mkWebsiteDrv subdir).outPath;
};
};
in mkIf cfg.enable {
services.nginx = {
enable = true;
virtualHosts =
let
subdirs =
let dirAttrs = filterAttrs
(n: v: v == "directory" || lists.elem n cfg.ignore)
(builtins.readDir cfg.directory);
in mapAttrsToList (n: v: n) dirAttrs;
mkWebsite = subdir: {
name = subdir;
# the nginx virtualhost config (for all sites) goes in here
value = {
enableACME = true;
forceSSL = true;
# naive string interpolation is safe here since nix will always immediately
# resolve relative paths to absolute paths; it's not lazy about that.
locations."/".root =
(pkgs.callPackage "${cfg.directory}/${subdir}" {}).outPath;
};
};
in listToAttrs (map mkWebsite subdirs);
listToAttrs (map mkWebsiteVHost subdirs);
};
hacc.websites.builders =
listToAttrs (map (subdir: {
name = subdir;
value = if (mkWebsiteDrv subdir) ? watch then (mkWebsiteDrv subdir).watch else null;
}) subdirs);
};
}

@ -1,6 +1,6 @@
{ stdenvNoCC }:
{ stdenvNoCC, sfz, writeScriptBin }:
stdenvNoCC.mkDerivation {
stdenvNoCC.mkDerivation rec {
name = "hacc.earth-static";
src = ./.;
@ -13,4 +13,7 @@ stdenvNoCC.mkDerivation {
rm $out/default.nix
'';
watch = writeScriptBin "watch" ''
${sfz}/bin/sfz -r ${src} "$@"
'';
}

@ -1,6 +1,6 @@
{ stdenvNoCC }:
{ stdenvNoCC, sfz, writeScriptBin }:
stdenvNoCC.mkDerivation {
stdenvNoCC.mkDerivation rec {
name = "muc.hacc.earth-static";
src = ./.;
@ -13,4 +13,7 @@ stdenvNoCC.mkDerivation {
rm $out/default.nix
'';
watch = writeScriptBin "watch" ''
${sfz}/bin/sfz -r ${src}
'';
}

@ -1,6 +1,6 @@
{ jekyll, stdenvNoCC }:
{ jekyll, stdenvNoCC, writeScriptBin }:
stdenvNoCC.mkDerivation {
stdenvNoCC.mkDerivation rec {
name = "infra4future.de-static";
src = ./.;
@ -11,4 +11,8 @@ stdenvNoCC.mkDerivation {
${jekyll}/bin/jekyll build -d $out --disable-disk-cache
'';
watch = writeScriptBin "watch" ''
rm -rf /tmp/hacc-website
${jekyll}/bin/jekyll serve -s ${src} --disable-disk-cache -d /tmp/hacc-website
'';
}

@ -1,6 +1,6 @@
{ stdenvNoCC }:
{ stdenvNoCC, sfz, writeScriptBin }:
stdenvNoCC.mkDerivation {
stdenvNoCC.mkDerivation rec {
name = "muc.hacc.earth-static";
src = ./.;
@ -13,4 +13,7 @@ stdenvNoCC.mkDerivation {
rm $out/default.nix
'';
watch = writeScriptBin "watch" ''
${sfz}/bin/sfz -r ${src}
'';
}

@ -1,6 +1,6 @@
{ jekyll, stdenvNoCC }:
{ jekyll, stdenvNoCC, writeScriptBin }:
stdenvNoCC.mkDerivation {
stdenvNoCC.mkDerivation rec {
name = "mumble.infra4future.de-static";
src = ./.;
@ -11,4 +11,8 @@ stdenvNoCC.mkDerivation {
${jekyll}/bin/jekyll build -d $out --disable-disk-cache
'';
watch = writeScriptBin "watch" ''
rm -rf /tmp/hacc-website
${jekyll}/bin/jekyll serve -s ${src} --disable-disk-cache -d /tmp/hacc-website
'';
}

Loading…
Cancel
Save