Packaging ChartDB

Hello everyone!

I require help to package ChartDB

It is a recent but very popular database diagrams and schema editor TypeScript web application distributed as a cloud SaaS and a docker container image (the frontend being displayed in a localhost web browser interface)

It surely might be possible to wrap it in a nixpkgs / nix flake from source without docker, but I have no idea how


After digging a bit deeper, it seems that it is static (doesn’t require a backend Node.js server) and architectured as a single page application (SPA).
The Docker container part is just to make Nginx serve static files and injecting environment variables through a script at runtime.

I’m not saying it’s good, I’m saying I spent about 10m on it. I have no idea if it has other problems, but if you run this, localhost:8080 has stuff on it.

let
  sources = import ./npins;
  pkgs = import sources.nixpkgs { };
  inherit (pkgs) lib;
  package =
    {
      buildNpmPackage,
      lib,
    }:
    buildNpmPackage rec {
      pname = "chartdb";
      version = lib.removePrefix src.release_prefix src.version;
      src = sources.chartdb;
      npmDepsHash = "sha256-nreu9QeT2lyJNkVomueifviE608YbuwesusdqGhWZqM=";
      installPhase = ''
        runHook preInstall
        mv dist $out
        runHook postInstall
      '';
    };
  chart-db = pkgs.callPackage package { };
  nginxConf = pkgs.writeText "nginx.conf" ''
    daemon off;

    events {
      worker_connections 128;
      ${lib.optionalString pkgs.hostPlatform.isLinux "use epoll;"}
      ${lib.optionalString pkgs.hostPlatform.isDarwin "use kqueue;"}
    }
    http {
      access_log /dev/stdout;
      include ${pkgs.nginx}/conf/mime.types;
      server {
        listen 8080;
        root ${chart-db};
        location / {
          try_files $uri /index.html;
        }
      }
    }
  '';
in
pkgs.writeShellScriptBin "chart-db" ''
  pid=$(mktemp)
  exec ${lib.getExe pkgs.nginx} -c ${nginxConf} -e /dev/stderr -g "pid $pid;"
''

EDIT:

❯ npins show
chartdb: (git release tag)
    repository: https://github.com/chartdb/chartdb.git
    pre_releases: false
    release_prefix: v
    submodules: false
    version: v1.18.1
    revision: 34b1a60737ac7a166f63539cf114b6d634d647b1
    hash: 02jladfmxbqj861km7yf008cxjdwwqmg2hfb59s453rivmlh0f0y
    frozen: false

nixpkgs: (Nix channel)
    name: nixpkgs-unstable
    url: https://releases.nixos.org/nixpkgs/nixpkgs-26.05pre905319.f720de590661/nixexprs.tar.xz
    hash: 07n4hhch0j6n69b0zchdjg0l80z2xrdk7k57ykv90cvhklim5dz1
    frozen: false
1 Like