-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
64 lines (60 loc) · 1.96 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
outputs = _: {
# Parent flake import the default module to install the site's package, and configure serving it with nginx
nixosModules = {
default = {
lib,
pkgs,
config,
...
}: let
# Convenience
pkgName = "cs4600";
# Create a new derivation which simply copies the static site contents to the /nix/store
website = pkgs.stdenv.mkDerivation {
name = "website-${pkgName}";
src = ./.;
installPhase = ''
cp -r $src $out
'';
};
# Check if both the website service is enabled, and this specific site is enabled.
cfgcheck = config.services.websites.enable && config.services.websites.sites.${pkgName}.enable;
# Website url
domain = config.services.websites.sites.${pkgName}.domain;
in {
# Create the option to enable this site, and set its domain name
options = {
services = {
websites = {
sites = {
cs4600 = {
enable = lib.mkEnableOption "University of Utah's CS4600 Class Projects (static website)";
domain = lib.mkOption {
type = lib.types.str;
default = "cs4600.xvrqt.com";
example = "gateway.xvrqt.com";
description = "Domain name for the website. In the form: sub.domain.tld, domain.tld";
};
};
};
};
};
};
config = {
# Add the website to the system's packages
environment.systemPackages = [website];
# Configure a virtual host on nginx
services.nginx.virtualHosts.${domain} = lib.mkIf cfgcheck {
forceSSL = true;
enableACME = true;
acmeRoot = null;
locations."/" = {
root = "${website}";
};
};
};
};
};
};
}