website/flake.nix

94 lines
3.1 KiB
Nix
Raw Normal View History

2024-08-15 12:28:51 +03:00
{
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,
system,
2024-08-15 12:28:51 +03:00
...
}: let
pkgs = inp.nixpkgs.legacyPackages.${system};
2024-08-15 12:28:51 +03:00
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 = ./.;
2025-02-07 06:06:33 +09:00
outputHash = "sha256-kP4m6ztiTcs0rMV2EjhjHjCbv3uVLbQg6SSYpU+yzIA=";
2024-08-15 12:28:51 +03:00
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 = ./.;
2024-09-19 03:28:19 +03:00
nativeBuildInputs = [pkgs.makeBinaryWrapper pkgs.rsync];
2024-08-15 12:28:51 +03:00
buildInputs = [pkgs.bun];
2024-08-23 16:46:57 +03:00
PUBLIC_BASE_URL="http://localhost:5173";
GUESTBOOK_BASE_URL="http://localhost:8080";
2024-08-15 12:28:51 +03:00
configurePhase = ''
runHook preConfigure
2024-09-19 03:28:19 +03:00
cp -R --no-preserve=ownership ${config.packages.gazesys-modules} node_modules
find node_modules -type d -exec chmod 755 {} \;
2024-08-15 12:28:51 +03:00
substituteInPlace node_modules/.bin/vite \
2024-09-19 03:28:19 +03:00
--replace-fail "/usr/bin/env node" "${pkgs.nodejs-slim_latest}/bin/node"
2024-08-15 12:28:51 +03:00
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 ]} \
2025-01-16 21:27:26 +09:00
--add-flags "run --bun --prefer-offline --no-install --cwd $out start"
2024-08-15 12:28:51 +03:00
runHook postInstall
'';
};
packages.default = config.packages.gazesys;
};
};
}