From a2451e41846ec6ea68b5a0d14672497103f2773d Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Thu, 24 Aug 2023 17:57:33 -0600 Subject: [PATCH] Initial nix config --- .gitignore | 1 + flake.lock | 77 +++++++++++++++++++++++++++++++++++++ flake.nix | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 30cf731..9cdd388 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ npm-debug.log* yarn-debug.log* yarn-error.log* dist/ +/result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..04e81c3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,77 @@ +{ + "nodes": { + "nix-filter": { + "locked": { + "lastModified": 1681154353, + "narHash": "sha256-MCJ5FHOlbfQRFwN0brqPbCunLEVw05D/3sRVoNVt2tI=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "f529f42792ade8e32c4be274af6b6d60857fbee7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1686547151, + "narHash": "sha256-lnu+ziAXNa3iiPtFVg9Ex7ZUcsYCb7zZVpv9OiB1iac=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4e3d46a3ea37d09c3d6dda557a0623c18ed58afe", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nix-filter": "nix-filter", + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f384c20 --- /dev/null +++ b/flake.nix @@ -0,0 +1,110 @@ +{ + 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"; + __noChroot = true; + + src = filter { + root = ./.; + include = [ + ./package.json + ./package-lock.json + ]; + }; + + 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 = "drowning"; + + src = filter { + root = ./.; + exclude = [ + ./node_modules + ]; + }; + + nativeBuildInputs = [ nodejs ]; + + configurePhase = '' + ln -sf ${node_modules}/node_modules node_modules + export HOME=$TMP + ''; + + buildPhase = ''npm run build''; + + installPhase = '' + mkdir -p $out + mv dist/index.html $out/ + mv dist/assets $out/ + ''; + }; + + }; + }) // { + nixosModule = {config, lib, pkgs, ...}: + with lib; + let cfg = config.ashe.services.drowning; + pkg = self.packages.${pkgs.system}.default; + + in { + options.ashe.services.drowning = { + enable = mkEnableOption "Enables the drowning site"; + + domain = mkOption rec { + type = types.str; + default = "drowning.ashen.earth"; + example = default; + description = "The domain name to serve the Drowning Among Stars game at"; + }; + }; + + config = mkIf cfg.enable { + services.nginx.virtualHosts.${cfg.domain} = { + locations."/" = { + root = "${pkg}"; + }; + forceSSL = true; + enableACME = true; + }; + }; + }; + }; +}