diff --git a/hosts/hackens-org/2048.nix b/hosts/hackens-org/2048.nix new file mode 100644 index 0000000..7de6c21 --- /dev/null +++ b/hosts/hackens-org/2048.nix @@ -0,0 +1,15 @@ +{ config, pkgs, ... }: +{ + staticWebsites.sites = { + "2048" = { + root = pkgs.fetchFromGitHub { + owner = "hackEns"; + repo = "2048NdS"; + rev = "1df6db154ca22c380eb52844c7a6a7f888fb5610"; + sha256 = "087471kpbpcg5920wy6fgcx6jz613zbyy0jn5iiimwjk1im1wa4q"; + }; + hostname = config.my.subZone; + location = "/2048"; + }; + }; +} diff --git a/hosts/hackens-org/modules/staticWebsites.nix b/hosts/hackens-org/modules/staticWebsites.nix index 83d9d46..fa12992 100644 --- a/hosts/hackens-org/modules/staticWebsites.nix +++ b/hosts/hackens-org/modules/staticWebsites.nix @@ -1,7 +1,7 @@ { lib, config , ... }: with lib; let - eachSite = config.services.staticWebsites; + eachSite = config.services.staticWebsites.sites; website = { name, ... }: { options = { root = mkOption { @@ -14,6 +14,11 @@ let default = name; description = "Website hostname"; }; + location = mkOption { + type = types.nullOr types.str; + default = null; + description = "Add a location rule if not null"; + }; }; }; in @@ -31,12 +36,27 @@ in config = mkIf (eachSite != {}) { services.nginx = { enable = true; - virtualHosts = mapAttrs ( hostName: conf: { - serverName = conf.hostname; - root = conf.root; - forceSSL = if debug then false else true; - enableACME = if debug then false else true; - }) eachSite; + virtualHosts = mapAttrs ( hostName: conf: (mkMerge [ + { + serverName = conf.hostname; + forceSSL = if debug then false else true; + enableACME = if debug then false else true; + } + + (mkIf (conf.location == null) { + root = conf.root; + }) + + (mkIf (conf.location != null) { + location = { + "~ ^${conf.location}" = { + alias = conf.root; + }; + }; + }) + + ]) + ) eachSite; }; }; }