{ inputs = { utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:NixOS/nixpkgs/master"; nix-filter.url = "github:numtide/nix-filter"; }; outputs = { self, nixpkgs, utils, nix-filter, }: utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; filter = nix-filter.lib; nodejs = pkgs.nodejs-18_x; node_modules = pkgs.stdenv.mkDerivation { name = "node_modules"; src = filter { root = ./.; include = [ ./package.json ./package-lock.json ]; }; __noChroot = true; configurePhase = '' export HOME=$TMP ''; buildInputs = [ nodejs ]; buildPhase = '' ${nodejs}/bin/npm ci ''; installPhase = '' mkdir $out mv node_modules $out/node_modules ''; }; in { packages = { default = pkgs.stdenv.mkDerivation { name = "ashen.earth"; src = filter { root = ./.; exclude = [ ./.next ./node_modules ]; }; nativeBuildInputs = [ nodejs ]; buildPhase = '' npx next build ''; configurePhase = '' ln -sf ${node_modules}/node_modules node_modules export HOME=$TMP ''; installPhase = '' # Copy static export mv out $out ''; }; }; }) // { nixosModule = {config, lib, pkgs, ...}: with lib; let cfg = config.ashe.services."ashen.earth"; pkg = self.packages.${pkgs.system}.default; in { options.ashe.services."ashen.earth" = { enable = mkEnableOption "Enables the ashen.earth HTTP service"; domain = mkOption rec { type = types.str; default = "ashen.earth"; example = default; description = "The domain name for ashen.earth"; }; }; config = mkIf cfg.enable { services.nginx.virtualHosts.${cfg.domain} = { root = "${pkg}"; forceSSL = true; enableACME = true; locations."/" = { tryFiles = "$uri $uri.html $uri/index.html =404"; }; }; }; }; }; }