webview: replace dream2nix by buildNpm from nixpkgs to save inputs

This commit is contained in:
Johannes Kirschbauer 2024-05-21 15:50:52 +02:00
parent e9b0ce6a78
commit 21104a0465
Signed by: hsjobeki
SSH Key Fingerprint: SHA256:vX3utDqig7Ph5L0JPv87ZTPb/w7cMzREKVZzzLFg9qU
4 changed files with 26 additions and 128 deletions

View File

@ -20,28 +20,6 @@
"type": "github"
}
},
"dream2nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"purescript-overlay": "purescript-overlay",
"pyproject-nix": "pyproject-nix"
},
"locked": {
"lastModified": 1716143526,
"narHash": "sha256-Pk77RzfAlrr1iR81zFJA/puxr2OeBifd0Yb0ETWMVKE=",
"owner": "nix-community",
"repo": "dream2nix",
"rev": "f28d1cc6898532ac331a1625628090dc7c5b02e2",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "dream2nix",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
@ -151,49 +129,9 @@
"type": "github"
}
},
"purescript-overlay": {
"inputs": {
"nixpkgs": [
"dream2nix",
"nixpkgs"
],
"slimlock": "slimlock"
},
"locked": {
"lastModified": 1696022621,
"narHash": "sha256-eMjFmsj2G1E0Q5XiibUNgFjTiSz0GxIeSSzzVdoN730=",
"owner": "thomashoneyman",
"repo": "purescript-overlay",
"rev": "047c7933abd6da8aa239904422e22d190ce55ead",
"type": "github"
},
"original": {
"owner": "thomashoneyman",
"repo": "purescript-overlay",
"type": "github"
}
},
"pyproject-nix": {
"flake": false,
"locked": {
"lastModified": 1702448246,
"narHash": "sha256-hFg5s/hoJFv7tDpiGvEvXP0UfFvFEDgTdyHIjDVHu1I=",
"owner": "davhau",
"repo": "pyproject.nix",
"rev": "5a06a2697b228c04dd2f35659b4b659ca74f7aeb",
"type": "github"
},
"original": {
"owner": "davhau",
"ref": "dream2nix",
"repo": "pyproject.nix",
"type": "github"
}
},
"root": {
"inputs": {
"disko": "disko",
"dream2nix": "dream2nix",
"flake-parts": "flake-parts",
"nixos-generators": "nixos-generators",
"nixos-images": "nixos-images",
@ -202,28 +140,6 @@
"treefmt-nix": "treefmt-nix"
}
},
"slimlock": {
"inputs": {
"nixpkgs": [
"dream2nix",
"purescript-overlay",
"nixpkgs"
]
},
"locked": {
"lastModified": 1688610262,
"narHash": "sha256-Wg0ViDotFWGWqKIQzyYCgayeH8s4U1OZcTiWTQYdAp4=",
"owner": "thomashoneyman",
"repo": "slimlock",
"rev": "b5c6cdcaf636ebbebd0a1f32520929394493f1a6",
"type": "github"
},
"original": {
"owner": "thomashoneyman",
"repo": "slimlock",
"type": "github"
}
},
"sops-nix": {
"inputs": {
"nixpkgs": [

View File

@ -21,8 +21,7 @@
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
dream2nix.url = "github:nix-community/dream2nix";
dream2nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =

View File

@ -1,9 +1,14 @@
{ dream2nix, config, src, ... }:
{
dream2nix,
config,
src,
...
}:
{
imports = [ dream2nix.modules.dream2nix.WIP-nodejs-builder-v3 ];
mkDerivation = {
inherit src ;
inherit src;
};
deps =
@ -14,6 +19,7 @@
WIP-nodejs-builder-v3 = {
packageLockFile = "${config.mkDerivation.src}/package-lock.json";
# config.groups.all.packages.${config.name}.${config.version}.
};
public.out = {
checkPhase = ''

View File

@ -1,53 +1,30 @@
{ inputs, ... }:
{ ... }:
{
perSystem =
{ pkgs, config, ... }:
{
system,
pkgs,
config,
...
}:
let
node_modules-dev = config.packages.webview-ui.prepared-dev;
packages.webview-ui = pkgs.buildNpmPackage {
pname = "clan-webview-ui";
version = "0.0.1";
src_with_api = pkgs.stdenv.mkDerivation {
name = "with-api";
src = ./app;
buildInputs = [ pkgs.nodejs ];
installPhase = ''
mkdir -p $out
mkdir -p $out/api
cat ${config.packages.clan-ts-api} > $out/api/index.ts
cp -r $src/* $out
ls -la $out/api
'';
};
in
{
packages.webview-ui = inputs.dream2nix.lib.evalModules {
specialArgs = {
src = src_with_api ;
# npmDepsHash = "sha256-bRD2vzijhdOOvcEi6XaG/neSqhkVQMqIX/8bxvRQkTc=";
npmDeps = pkgs.fetchNpmDeps {
src = ./app;
hash = "sha256-bRD2vzijhdOOvcEi6XaG/neSqhkVQMqIX/8bxvRQkTc=";
};
packageSets.nixpkgs = inputs.dream2nix.inputs.nixpkgs.legacyPackages.${system};
modules = [ ./default.nix ];
# The prepack script runs the build script, which we'd rather do in the build phase.
npmPackFlags = [ "--ignore-scripts" ];
preBuild = ''
mkdir -p api
cat ${config.packages.clan-ts-api} > api/index.ts
'';
};
devShells.webview-ui = pkgs.mkShell {
inputsFrom = [ config.packages.webview-ui.out ];
inputsFrom = [ config.packages.webview-ui ];
shellHook = ''
ID=${node_modules-dev}
currID=$(cat .dream2nix/.node_modules_id 2> /dev/null)
mkdir -p .dream2nix
if [[ "$ID" != "$currID" || ! -d "app/node_modules" ]];
then
${pkgs.rsync}/bin/rsync -a --chmod=ug+w --delete ${node_modules-dev}/node_modules/ ./app/node_modules/
echo -n $ID > .dream2nix/.node_modules_id
echo "Ok: node_modules updated"
fi
mkdir -p ./app/api
cat ${config.packages.clan-ts-api} > ./app/api/index.ts
'';