Our Personal Data Server from scratch! tranquil.farm
oauth atproto pds rust postgresql objectstorage fun

feat(nix): derivation for frontend #11

merged opened by nel.pet targeting main from nix-fixes
Labels

None yet.

assignee
Participants 1
AT URI
at://did:plc:h5wsnqetncv6lu2weom35lg2/sh.tangled.repo.pull/3mdisr24wx722
+100 -6
Diff #0
+18 -1
flake.lock
··· 16 16 "type": "github" 17 17 } 18 18 }, 19 + "nixpkgs-fetch-deno": { 20 + "locked": { 21 + "lastModified": 1766410835, 22 + "narHash": "sha256-dRhVt0aFDyTqppyzRLxiO1JZEAoIA2fUnaeyJTe+UwU=", 23 + "owner": "aMOPel", 24 + "repo": "nixpkgs", 25 + "rev": "c9801acc8c4fac6377d076bc1c102b15bd9cfa6f", 26 + "type": "github" 27 + }, 28 + "original": { 29 + "owner": "aMOPel", 30 + "ref": "feat/fetchDenoDeps", 31 + "repo": "nixpkgs", 32 + "type": "github" 33 + } 34 + }, 19 35 "root": { 20 36 "inputs": { 21 - "nixpkgs": "nixpkgs" 37 + "nixpkgs": "nixpkgs", 38 + "nixpkgs-fetch-deno": "nixpkgs-fetch-deno" 22 39 } 23 40 } 24 41 },
+16 -5
flake.nix
··· 1 1 { 2 - inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 3 - outputs = { self, nixpkgs, ... }: let 2 + inputs = { 3 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 4 + 5 + # tranquil frontend uses deno as its package manager and build time runtime. 6 + # nixpkgs does not have deno support yet but its being worked on in https://github.com/NixOS/nixpkgs/pull/419255 7 + # for now we important that PR as well purely for its fetchDenoDeps 8 + nixpkgs-fetch-deno.url = "github:aMOPel/nixpkgs/feat/fetchDenoDeps"; 9 + }; 10 + 11 + outputs = { self, nixpkgs, ... } @ inputs : let 4 12 forAllSystems = 5 13 function: 6 14 nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed ( 7 - system: function nixpkgs.legacyPackages.${system} 15 + system: (function system nixpkgs.legacyPackages.${system}) 8 16 ); 9 17 in { 10 - packages = forAllSystems (pkgs: { 18 + packages = forAllSystems (system: pkgs: { 11 19 tranquil-pds = pkgs.callPackage ./default.nix { }; 20 + tranquil-frontend = pkgs.callPackage ./frontend.nix { 21 + inherit (inputs.nixpkgs-fetch-deno.legacyPackages.${system}) fetchDenoDeps; 22 + }; 12 23 default = self.packages.${pkgs.stdenv.hostPlatform.system}.tranquil-pds; 13 24 }); 14 25 15 - devShells = forAllSystems (pkgs: { 26 + devShells = forAllSystems (system: pkgs: { 16 27 default = pkgs.callPackage ./shell.nix { }; 17 28 }); 18 29 };
+66
frontend.nix
··· 1 + { 2 + lib, 3 + stdenvNoCC, 4 + 5 + fetchDenoDeps, 6 + fetchFromGitHub, 7 + 8 + buildGoModule, 9 + 10 + deno, 11 + esbuild, 12 + }: let 13 + toml = (lib.importTOML ./Cargo.toml).workspace.package; 14 + deno-deps = fetchDenoDeps { 15 + pname = "tranquil-frontend-deno-deps"; 16 + denoLock = ./frontend/deno.lock; 17 + hash = "sha256-UB+E00TjWX0fTUZ7XwcwRJ/OUOSSJpz6Ss04U5i8dGI="; 18 + }; 19 + # the esbuild in upstream nixpkgs is too old. 20 + esbuild' = esbuild.override { 21 + buildGoModule = args: buildGoModule ( 22 + args // ( 23 + let 24 + version = "0.27.2"; 25 + in { 26 + inherit version; 27 + src = fetchFromGitHub { 28 + owner = "evanw"; 29 + repo = "esbuild"; 30 + tag = "v${version}"; 31 + hash = "sha256-JbJB3F1NQlmA5d0rdsLm4RVD24OPdV4QXpxW8VWbESA"; 32 + }; 33 + vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ"; 34 + } 35 + ) 36 + ); 37 + }; 38 + in stdenvNoCC.mkDerivation { 39 + pname = "tranquil-frontend"; 40 + inherit (toml) version; 41 + 42 + src = ./frontend; 43 + 44 + nativeBuildInputs = [ 45 + deno 46 + ]; 47 + # tell vite (through the esbuild api) where the nix provided esbuild binary is 48 + env.ESBUILD_BINARY_PATH = lib.getExe esbuild'; 49 + 50 + buildPhase = '' 51 + # copy the deps to the required location 52 + cp -r --no-preserve=mode ${deno-deps.denoDeps}/.deno ./ 53 + cp -r --no-preserve=mode ${deno-deps.denoDeps}/vendor ./ 54 + 55 + pwd 56 + ls /build/frontend/vendor 57 + 58 + # Now you can run the project using deps 59 + # you need to activate [deno's vendor feature](https://docs.deno.com/runtime/fundamentals/modules/#vendoring-remote-modules) 60 + # you need to use the `$DENO_DIR` env var, to point deno to the correct local cache 61 + DENO_DIR=./.deno deno run --frozen --cached-only build 62 + ''; 63 + installPhase = '' 64 + cp -r ./dist $out 65 + ''; 66 + }

History

1 round 0 comments
sign up or login to add to the discussion
nel.pet submitted #0
1 commit
expand
feat(nix): derivation for frontend
expand 0 comments
pull request successfully merged