build: add nix

This commit is contained in:
dusk 2024-08-15 12:28:51 +03:00
parent eb7720b266
commit f93c66c0de
Signed by: dusk
SSH Key Fingerprint: SHA256:Abmvag+juovVufZTxyWY8KcVgrznxvBjQpJesv071Aw
3 changed files with 183 additions and 0 deletions

3
.gitignore vendored
View File

@ -19,3 +19,6 @@ Thumbs.db
# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
# nix
/result

90
flake.lock Normal file
View File

@ -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
}

90
flake.nix Normal file
View File

@ -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;
};
};
}