mirror of
https://github.com/versia-pub/server.git
synced 2026-04-27 20:59:15 +02:00
feat: flake
This commit is contained in:
parent
8b96401c71
commit
e588e98f4e
6 changed files with 753 additions and 45 deletions
114
flake.nix
114
flake.nix
|
|
@ -1,31 +1,97 @@
|
|||
{
|
||||
description = "JavaScript example flake for Zero to Nix";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||
systems.url = "github:nix-systems/default";
|
||||
|
||||
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
|
||||
};
|
||||
|
||||
outputs = {
|
||||
systems,
|
||||
nixpkgs,
|
||||
...
|
||||
} @ inputs: let
|
||||
eachSystem = f:
|
||||
nixpkgs.lib.genAttrs (import systems) (
|
||||
system:
|
||||
f nixpkgs.legacyPackages.${system}
|
||||
);
|
||||
in {
|
||||
devShells = eachSystem (pkgs: {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
pkgs.bun
|
||||
pkgs.nodePackages.typescript
|
||||
pkgs.nodePackages.typescript-language-server
|
||||
];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
outputs = { self, nixpkgs, flake-compat }:
|
||||
let
|
||||
# Systems supported
|
||||
allSystems = [
|
||||
"x86_64-linux" # 64-bit Intel/AMD Linux
|
||||
"aarch64-linux" # 64-bit ARM Linux
|
||||
"x86_64-darwin" # 64-bit Intel macOS
|
||||
"aarch64-darwin" # 64-bit ARM macOS
|
||||
];
|
||||
|
||||
# Helper to provide system-specific attributes
|
||||
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
});
|
||||
in
|
||||
{
|
||||
packages = forAllSystems ({ pkgs }: {
|
||||
default = let
|
||||
pin = pkgs.lib.importJSON ./pin.json;
|
||||
src = self;
|
||||
node_modules = pkgs.stdenv.mkDerivation {
|
||||
pname = "versiajs-node_modules";
|
||||
inherit src;
|
||||
version = pin.version;
|
||||
impureEnvVars = pkgs.lib.fetchers.proxyImpureEnvVars
|
||||
++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" ];
|
||||
nativeBuildInputs = with pkgs; [ bun nodejs nodePackages.typescript nodePackages.typescript-language-server ];
|
||||
buildInputs = with pkgs; [ libstdcxx5 ];
|
||||
dontConfigure = true;
|
||||
buildPhase = ''
|
||||
bun install --production --frozen-lockfile --ignore-scripts
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/node_modules
|
||||
cp -R ./node_modules $out
|
||||
'';
|
||||
outputHash = pin."${pkgs.stdenv.system}";
|
||||
outputHashAlgo = "sha256";
|
||||
outputHashMode = "recursive";
|
||||
dontFixup = true;
|
||||
};
|
||||
in pkgs.stdenv.mkDerivation {
|
||||
name = "versiajs";
|
||||
version = pin.version;
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
ln -s ${node_modules}/node_modules .
|
||||
bun run build
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
mkdir -p $out/bin
|
||||
cp -R ./* $out
|
||||
makeBinaryWrapper ${pkgs.bun}/bin/bun $out/bin/versiajs \
|
||||
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.bun ]} \
|
||||
--add-flags "run --prefer-offline --no-install --cwd $out ./cli/index.ts start"
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
nodejs
|
||||
];
|
||||
|
||||
nativeBuildInputs = with pkgs; [ makeBinaryWrapper bun ];
|
||||
|
||||
inherit src;
|
||||
|
||||
dontConfigure = true;
|
||||
};
|
||||
});
|
||||
devShells = forAllSystems ({ pkgs }: {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
bun
|
||||
nodejs
|
||||
nodePackages.typescript
|
||||
nodePackages.typescript-language-server
|
||||
nix-ld
|
||||
];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue