diff --git a/.gitignore b/.gitignore index 79518f7..2228764 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ Thumbs.db # Vite vite.config.js.timestamp-* vite.config.ts.timestamp-* + +# nix +/result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..655e7bb --- /dev/null +++ b/flake.lock @@ -0,0 +1,90 @@ +{ + "nodes": { + "naked-shell": { + "locked": { + "lastModified": 1681286841, + "narHash": "sha256-3XlJrwlR0nBiREnuogoa5i1b4+w/XPe0z8bbrJASw0g=", + "owner": "yusdacra", + "repo": "mk-naked-shell", + "rev": "7612f828dd6f22b7fb332cc69440e839d7ffe6bd", + "type": "github" + }, + "original": { + "owner": "yusdacra", + "repo": "mk-naked-shell", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1723637854, + "narHash": "sha256-med8+5DSWa2UnOqtdICndjDAEjxr5D7zaIiK4pn0Q7c=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "c3aa7b8938b17aebd2deecf7be0636000d62a2b9", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1722555339, + "narHash": "sha256-uFf2QeW7eAHlYXuDktm9c25OxOyCoUOQmh5SZ9amE5Q=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz" + } + }, + "parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1722555600, + "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "root": { + "inputs": { + "naked-shell": "naked-shell", + "nixpkgs": "nixpkgs", + "parts": "parts", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1680978846, + "narHash": "sha256-Gtqg8b/v49BFDpDetjclCYXm8mAnTrUzR0JnE2nv5aw=", + "owner": "nix-systems", + "repo": "x86_64-linux", + "rev": "2ecfcac5e15790ba6ce360ceccddb15ad16d08a8", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "x86_64-linux", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6e52882 --- /dev/null +++ b/flake.nix @@ -0,0 +1,90 @@ +{ + inputs.parts.url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + inputs.systems.url = "github:nix-systems/x86_64-linux"; + inputs.naked-shell.url = "github:yusdacra/mk-naked-shell"; + + outputs = inp: + inp.parts.lib.mkFlake {inputs = inp;} { + systems = import inp.systems; + imports = [ + inp.naked-shell.flakeModule + ]; + perSystem = { + config, + pkgs, + ... + }: let + packageJson = builtins.fromJSON (builtins.readFile ./package.json); + in { + devShells.default = config.mk-naked-shell.lib.mkNakedShell { + name = "gazesys-devshell"; + packages = with pkgs; [ + nodejs-slim_latest bun + nodePackages.svelte-language-server + nodePackages.typescript-language-server + ]; + shellHook = '' + export PATH="$PATH:$PWD/node_modules/.bin" + ''; + }; + packages.gazesys-modules = pkgs.stdenv.mkDerivation { + pname = "${packageJson.name}-modules"; + version = packageJson.version; + + src = ./.; + + outputHash = "sha256-yZRtcXr+yYiuq9bIDwx/C/7T22VCaJ/d3Lv4kdOjHnk="; + outputHashAlgo = "sha256"; + outputHashMode = "recursive"; + + nativeBuildInputs = with pkgs; [bun]; + + dontConfigure = true; + impureEnvVars = pkgs.lib.fetchers.proxyImpureEnvVars + ++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" ]; + + buildPhase = "bun install --no-progress --frozen-lockfile"; + installPhase = "mv node_modules $out"; + }; + packages.gazesys = pkgs.stdenv.mkDerivation { + pname = packageJson.name; + version = packageJson.version; + + src = ./.; + + nativeBuildInputs = [pkgs.makeBinaryWrapper]; + buildInputs = [pkgs.bun]; + + PUBLIC_BASEURL="localhost:5173"; + + configurePhase = '' + runHook preConfigure + cp -R ${config.packages.gazesys-modules} node_modules + substituteInPlace node_modules/.bin/vite \ + --replace "/usr/bin/env node" "${pkgs.nodejs-slim_latest}/bin/node" + runHook postConfigure + ''; + buildPhase = '' + runHook preBuild + bun --prefer-offline run build + runHook postBuild + ''; + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + ln -s ${config.packages.gazesys-modules} $out + cp -R ./build/* $out + + makeBinaryWrapper ${pkgs.bun}/bin/bun $out/bin/${packageJson.name} \ + --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.bun ]} \ + --add-flags "run --prefer-offline --no-install --cwd $out start" + + runHook postInstall + ''; + }; + packages.default = config.packages.gazesys; + }; + }; +}