|
|
|
@ -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); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|