Qt6 application using Nim language

I dont know if this is the correct place.
Not as easy as it sounds.
Just give guidelines,

To build easy,

nix-build default.nix

The hard part,
cat default.nix

{ pkgs ? import <nixpkgs> {} }:

let
  # Importeer de lokale Nimble cache map en geef het een geldige naam voor de Nix store
  seaqtPkg = builtins.path {
    path = /. + "/home/x/.nimble/pkgcache/githubcom_seaqtnimseaqt_#qt-6.4";
    name = "seaqt-source";
  };

in pkgs.stdenv.mkDerivation rec {
  pname = "hello3";
  version = "0.1.0";

  # De huidige map met je test.nim
  src = ./.;

  nativeBuildInputs = with pkgs; [ 
    nim 
    pkg-config 
    qt6.qtbase.dev 
    qt6.wrapQtAppsHook 
  ];

  buildInputs = with pkgs; [ 
    qt6.qtbase 
  ];

  buildPhase = ''
    runHook preBuild

    # 1. SeaQt broncode voorbereiden in de sandbox
    mkdir -p seaqt_internal
    cp -r ${seaqtPkg}/* seaqt_internal/
    chmod -R +w seaqt_internal
    
    # 2. De QVariantConstPointer hack
    # We maken de map aan waar de C++ wrapper naar zoekt
    mkdir -p seaqt_internal/seaqt/QtCore
    touch seaqt_internal/seaqt/QtCore/QVariantConstPointer

    # 3. Omgevingsvariabelen voor Nim
    export HOME=$TMPDIR
    IMPORT_ROOT=$(pwd)/seaqt_internal
    
    # 4. Compileren
    # We voegen expliciet de QtCore map toe aan de C++ include paden (-I)
    nim cpp \
      --path:"$IMPORT_ROOT" \
      --passC:"$(pkg-config --cflags Qt6Widgets)" \
      --passC:"-I$IMPORT_ROOT/seaqt" \
      --passC:"-I$IMPORT_ROOT/seaqt/QtCore" \
      --passC:"-fPIC" \
      -d:SRCPATH="$IMPORT_ROOT/seaqt" \
      --mm:orc \
      --threads:on \
      -o:hello3 \
      test.nim

    runHook postBuild
  '';

  installPhase = ''
    # Maak de output map aan en kopieer de executable
    mkdir -p $out/bin
    cp hello3 $out/bin/
  '';
}

The easy,
cat test.nim

# ./test.nim
import std/strformat, seaqt/[qapplication, qpushbutton, qlineedit, qlabel, qvboxlayout, qwidget]

let
  _ = QApplication.create()
  window = QWidget.create()
  layout = QVBoxLayout.create(window)
 
  label = QLabel.create("Ready...")
  edit = QLineEdit.create()
  btn = QPushButton.create("Hello seaqt!")

layout.addWidget(label)
layout.addWidget(edit)
layout.addWidget(btn)

var counter = 0

btn.onPressed(
  proc() {.closure.} =
    counter += 1
    btn.setText(&"Clicks: {counter}")
)

# Fix: Match the signature 'openArray[char]'
edit.onTextChanged(
  proc(text: openArray[char]) {.closure.} =
    # Convert openArray[char] to string for the label
    label.setText("Input: " & $text)
)

window.setMinimumSize(320, 200)
window.show()

quit QApplication.exec().int

Not really how I’d go about it; we already have buildNimPackage etc. Manually writing out buildPhase is usually an antipattern, as is using random folders in your home dir that aren’t properly fetched with nix.

See https://nixos.org/manual/nixpkgs/unstable/#sec-language-nim.

Is this ok ? Please advise ?,

cat default2.nix


{ pkgs ? import <nixpkgs> {} }:

pkgs.buildNimPackage (finalAttrs: {
  pname = "hello3";
  version = "0.1.0";

  src = ./.;

  # Zorg dat je lock.json up-to-date is via:
  # nix-shell -p nim_lk jq --run "nim_lk . | jq --sort-keys > lock.json"
  lockFile = ./lock.json;

  nativeBuildInputs = with pkgs; [ 
    pkg-config 
    qt6.wrapQtAppsHook 
  ];

  buildInputs = with pkgs; [ 
    qt6.qtbase 
  ];

  nimFlags = [
    "--backend:cpp"
    "--mm:orc"
    "--threads:on"
    "--passC:-fPIC"
  ];

  preBuild = ''
    # Zorg dat Qt vlaggen correct worden doorgegeven
    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE $(pkg-config --cflags Qt6Widgets)"
    
    # SeaQt QVariantConstPointer hack voor de sandbox
    find . -name "seaqt" -type d -exec mkdir -p {}/QtCore \;
    find . -name "seaqt" -type d -exec touch {}/QtCore/QVariantConstPointer \;
  '';

  # De flexibele installPhase die de 'test' of 'hello3' binary oppakt
  installPhase = ''
    runHook preInstall
    mkdir -p $out/bin

    if [ -f hello3 ]; then
      echo "hello3 gevonden, installeren..."
      cp hello3 $out/bin/hello3
    elif [ -f test ]; then
      echo "Binary heet 'test', installeren als 'hello3'..."
      cp test $out/bin/hello3
    else
      echo "FOUT: Geen executable gevonden in $(pwd)"
      ls -F
      exit 1
    fi

    runHook postInstall
  '';

  # De wrapQtAppsHook zorgt hierna automatisch voor de juiste paden voor de GUI
})

I think you are more likely to receive help on specific, concrete issues.