nixos/sks: Make the webroot option optional

That way the built-in web server is usable by default but users can use
$HOME/web directly (instead of having to use a symlink), if they want to
customize the webpage.
This commit is contained in:
Michael Weiss 2018-09-08 16:45:58 +02:00
parent eb0050ca45
commit 53ef5441bb

View File

@ -55,17 +55,18 @@ in {
}; };
webroot = mkOption { webroot = mkOption {
type = types.path; type = types.nullOr types.path;
default = "${sksPkg.webSamples}/OpenPKG"; default = "${sksPkg.webSamples}/OpenPKG";
defaultText = "\${pkgs.sks.webSamples}/OpenPKG"; defaultText = "\${pkgs.sks.webSamples}/OpenPKG";
description = '' description = ''
Source directory (will be symlinked) for the files the built-in Source directory (will be symlinked, if not null) for the files the
webserver should serve. SKS (''${pkgs.sks.webSamples}) provides the built-in webserver should serve. SKS (''${pkgs.sks.webSamples})
following examples: "HTML5", "OpenPKG", and "XHTML+ES". The index provides the following examples: "HTML5", "OpenPKG", and "XHTML+ES".
file can be named index.html, index.htm, index.xhtm, or index.xhtml. The index file can be named index.html, index.htm, index.xhtm, or
Files with the extensions .css, .es, .js, .jpg, .jpeg, .png, or .gif index.xhtml. Files with the extensions .css, .es, .js, .jpg, .jpeg,
are supported. Subdirectories and filenames with anything other than .png, or .gif are supported. Subdirectories and filenames with
alphanumeric characters and the '.' character will be ignored. anything other than alphanumeric characters and the '.' character
will be ignored.
''; '';
}; };
}; };
@ -95,7 +96,8 @@ in {
after = [ "network.target" ]; after = [ "network.target" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
preStart = '' preStart = ''
ln -sfT "${cfg.webroot}" web ${lib.optionalString (cfg.webroot != null)
"ln -sfT \"${cfg.webroot}\" web"}
mkdir -p dump mkdir -p dump
${sksPkg}/bin/sks build dump/*.gpg -n 10 -cache 100 || true #*/ ${sksPkg}/bin/sks build dump/*.gpg -n 10 -cache 100 || true #*/
${sksPkg}/bin/sks cleandb || true ${sksPkg}/bin/sks cleandb || true