feat(nix): derivation for frontend

This commit is contained in:
nelind
2026-01-28 17:42:13 +00:00
committed by Tangled
parent f6a14467d6
commit afc1db95e0
3 changed files with 100 additions and 6 deletions
Generated
+18 -1
View File
@@ -16,9 +16,26 @@
"type": "github"
}
},
"nixpkgs-fetch-deno": {
"locked": {
"lastModified": 1766410835,
"narHash": "sha256-dRhVt0aFDyTqppyzRLxiO1JZEAoIA2fUnaeyJTe+UwU=",
"owner": "aMOPel",
"repo": "nixpkgs",
"rev": "c9801acc8c4fac6377d076bc1c102b15bd9cfa6f",
"type": "github"
},
"original": {
"owner": "aMOPel",
"ref": "feat/fetchDenoDeps",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"nixpkgs-fetch-deno": "nixpkgs-fetch-deno"
}
}
},
+16 -5
View File
@@ -1,18 +1,29 @@
{
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
outputs = { self, nixpkgs, ... }: let
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
# tranquil frontend uses deno as its package manager and build time runtime.
# nixpkgs does not have deno support yet but its being worked on in https://github.com/NixOS/nixpkgs/pull/419255
# for now we important that PR as well purely for its fetchDenoDeps
nixpkgs-fetch-deno.url = "github:aMOPel/nixpkgs/feat/fetchDenoDeps";
};
outputs = { self, nixpkgs, ... } @ inputs : let
forAllSystems =
function:
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (
system: function nixpkgs.legacyPackages.${system}
system: (function system nixpkgs.legacyPackages.${system})
);
in {
packages = forAllSystems (pkgs: {
packages = forAllSystems (system: pkgs: {
tranquil-pds = pkgs.callPackage ./default.nix { };
tranquil-frontend = pkgs.callPackage ./frontend.nix {
inherit (inputs.nixpkgs-fetch-deno.legacyPackages.${system}) fetchDenoDeps;
};
default = self.packages.${pkgs.stdenv.hostPlatform.system}.tranquil-pds;
});
devShells = forAllSystems (pkgs: {
devShells = forAllSystems (system: pkgs: {
default = pkgs.callPackage ./shell.nix { };
});
};
+66
View File
@@ -0,0 +1,66 @@
{
lib,
stdenvNoCC,
fetchDenoDeps,
fetchFromGitHub,
buildGoModule,
deno,
esbuild,
}: let
toml = (lib.importTOML ./Cargo.toml).workspace.package;
deno-deps = fetchDenoDeps {
pname = "tranquil-frontend-deno-deps";
denoLock = ./frontend/deno.lock;
hash = "sha256-UB+E00TjWX0fTUZ7XwcwRJ/OUOSSJpz6Ss04U5i8dGI=";
};
# the esbuild in upstream nixpkgs is too old.
esbuild' = esbuild.override {
buildGoModule = args: buildGoModule (
args // (
let
version = "0.27.2";
in {
inherit version;
src = fetchFromGitHub {
owner = "evanw";
repo = "esbuild";
tag = "v${version}";
hash = "sha256-JbJB3F1NQlmA5d0rdsLm4RVD24OPdV4QXpxW8VWbESA";
};
vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ";
}
)
);
};
in stdenvNoCC.mkDerivation {
pname = "tranquil-frontend";
inherit (toml) version;
src = ./frontend;
nativeBuildInputs = [
deno
];
# tell vite (through the esbuild api) where the nix provided esbuild binary is
env.ESBUILD_BINARY_PATH = lib.getExe esbuild';
buildPhase = ''
# copy the deps to the required location
cp -r --no-preserve=mode ${deno-deps.denoDeps}/.deno ./
cp -r --no-preserve=mode ${deno-deps.denoDeps}/vendor ./
pwd
ls /build/frontend/vendor
# Now you can run the project using deps
# you need to activate [deno's vendor feature](https://docs.deno.com/runtime/fundamentals/modules/#vendoring-remote-modules)
# you need to use the `$DENO_DIR` env var, to point deno to the correct local cache
DENO_DIR=./.deno deno run --frozen --cached-only build
'';
installPhase = ''
cp -r ./dist $out
'';
}