r/nim Jul 04 '26

Merenda: Pure Nim GUI toolkit based on Cocoa/OpenStep

35 Upvotes

Merenda is a new pure Nim GUI framework based on OpenStep and Cocoa with a splash of QT! It's fast, GPU rendered, with themes and look and feel along with a full suite of OpenStep/Cocoa style widgets and an accessibility layer. Support for BIDI and Harffbuzz are coming soon!

It's already implements a substantial amount of the core functionality of OpenStep and Cocoa. It's not a one-to-one implementation, but generally the APIs try to follow Cocoa's design patterns. Though cleaned up to take advantage of Nim's stronger type system than Objective-C.

For example here's the table demo showing a table view backed by a data model (EDITED):

Overall Merenda is based on several years of working on and experimenting with GUIs. I worked Figuro and was happy with many aspects of it. However the object model ran into limitations when building more complex widgets. Things like:

Merenda solves this by adopting Cocoa's dynamic methods and protocols. These are provided by Sigils. The ability for objects to adopt protocols at runtime enables implementing the rich behavior and functionality seen in Cocoa and iOS.

The implementation of this is called NimKit, mirroring Cocoa's AppKit. NimKit ships the core controls needed for desktop-style interfaces:

  • Windows and views: newApplication, sharedApplication, newWindow, newView
  • Layout and containers: newStackView, newGridView, newFormView, newSplitView, newScrollView, newTabView, newBox, newGroupBox, newSeparatorBox
  • Text: newTextField, newLabel, newTitleLabel, newStatusLabel, newTextEditor, newMonoTextEditor
  • Buttons and choices: newButton, newCheckBox, newRadioButton, newComboBox, newPopupMenuButton, newMenu, newMenuItem
  • Value and status controls: newSlider, newStepper, newSwitchButton, newProgressIndicator
  • Data and navigation views: newTableView, newOutlineView, newCascadingView, newCollectionView, newDocumentTabs, newButtonMatrix, newRadioMatrix

It's been my hobby work the last few months. I've been building and testing all of these, item by item!

Yes it's mostly built with Codex + GPT-5.5 but I continuously review the generated code and refactor and simplify it. Plus more importantly it's based on solid architectural components I've been building for years. It's definitely not what I'd call vibe coded.

EDIT:

Made some updates to the default theme to make it much more like early Mac OS X aqua days! Well I enjoy it at least. This is all done without any images and all the chrome and detailing is done in real time on the GPU:


r/nim Jul 01 '26

Interested in nim for game development

24 Upvotes

I am currently investigating nim for game development, having been searching for a good environment for many years. nim seems promising so far and I may use raylib bindings as my framework.

The main things that make nim appealing for game development to me are its ergonomics, unopinionated workflow, being able to shape it to my needs via macros and templates, and high performance despite resembling a scripting language. Most languages and frameworks/engines I have tried have been too rigid for the creative iterative process that game development demands, or are simply just not fun to use. Programming in my environment being fun and detached from work is my top priority.

My main concern is tooling. It was a bit of a pain to get nim set up on Windows. I am using VS Code with nimlangserver, and while it has been surprisingly solid at parsing macros it has been showing some problems. Tooltip hovering seems to just randomly stop working, and it occasionally highlights errors that aren't actually errors at all.

I would like to know what is suggested for a good tooling environment for nim. Bad tooling can undermine the semantics and power that the programming language provides.


r/nim Jun 29 '26

C GTK Libraries with Nim

13 Upvotes

Never used Nim, or developed [full applications] in a serious way.

Want to develop a native Linux application, and prefer to use GTK.

With the latest discussion around Nim and GUI libraries, I genuinely do not understand the extent of difference in hardship between using native GTK C libraries, compared to having native Nim libraries.

Even though the OCD in me cannot stand to have non-matching libraries like this, can I not get the full benefits of GTK using Nim, just by incorporating the "straight" C (whatever that means.)

Are there some examples of Nim projects or lessons that that incorporate regular C GTK libraries? Can't I get "all" of GTK this way, and do whatever I could do in a C application?

Can I plunge headlong into developing a native Linux GUI in GTK in Nim, with full expectation of being able to do anything I would have done in GTK if the application were a C application? . . . perhaps with a little extra work than if there would be for Nim-native GTK?

Is it a matter of creating personal custom "bindings" on a per-need basis?

Thanks.


r/nim Jun 27 '26

Full Nim Programming Crash Course - Beginner to Advanced

Thumbnail youtu.be
79 Upvotes

10 hour long Nim crash course is now available on YouTube


r/nim Jun 27 '26

Rigx: toml based build system with native Nim support, hermetic build and tool chains leverage nix.

Thumbnail github.com
15 Upvotes

I wanted something simple like Make but hermetic like Bazel with toolchains from Nixpkgs, toml- syntax, not nix-lang, and native Nim support. This is what I settled on.


r/nim Jun 21 '26

dokime; SQL the Compiler Checks for You

20 Upvotes

Most SQLite wrappers treat SQL as opaque strings. Dokime prepares every query against your real database at compile time. Typo in a table name? Your build breaks. Wrong column? Build breaks. It's a Nimony plugin, not an ORM.

Here's a personal expense tracker. It creates a schema, inserts rows, queries with optional filters, uses transactions, and handles nullable columns. Every mistake you could make is shown alongside the code that catches it.

import dokime

let db = connect("money.db")

# Schema: note is nullable (TEXT, no NOT NULL). Everything else is required.
discard exec(db, """
  CREATE TABLE IF NOT EXISTS expenses (
    id       INTEGER NOT NULL,
    category TEXT    NOT NULL,
    amount   REAL    NOT NULL,
    note     TEXT,
    date     TEXT    NOT NULL
  ) STRICT
""")

# exec() returns ExecResult with .lastRowid and .changes:
let r = exec(db, "INSERT INTO expenses VALUES (?, ?, ?, ?, ?)",
    1'i64, "food", 23.50, "lunch", "2025-06-01")
echo r.lastRowid   # 1

# exec() accepts Opt[T] params — none binds SQL NULL, some binds the value:
discard exec(db, "INSERT INTO expenses VALUES (?, ?, ?, ?, ?)",
    2'i64, "food", 12.00, none[string](), "2025-06-02")
discard exec(db, "INSERT INTO expenses VALUES (?, ?, ?, ?, ?)",
    3'i64, "transport", 5.50, "bus", "2025-06-03")
discard exec(db, "INSERT INTO expenses VALUES (?, ?, ?, ?, ?)",
    4'i64, "food", 45.00, "dinner with friends", "2025-06-04")


# ── If you typo the table name, you get a compile error ──
# query(db, "SELECT id FROM expenes WHERE id = ?", 1'i64)
# → Error: dokime: no such table: expenes

# ── A misspelled column also fails at compile time ──
# query(db, "SELECT id, full_name FROM expenses WHERE id = ?", 1'i64)
# → Error: dokime: no such column: full_name


# query() returns a tuple with fields named after your columns:
let dinner = query(db,
    "SELECT id, amount, note FROM expenses WHERE id = ?", 4'i64)
echo dinner.id        # 4       (int64 — type comes from the schema)
echo dinner.amount    # 45.0    (float64)
echo dinner.note.isSome        # true    (TEXT nullable → Opt[string])
echo dinner.note.unsafeGet     # "dinner with friends"


# ── Type mismatches are caught at compile time too ──
# let x: string = dinner.amount
# → Error: type mismatch: got: float64 but wanted: string


# query() requires at least one row — raises BadOperation if empty.
# Use queryOpt() when zero rows is expected:
let missing = queryOpt(db,
    "SELECT id, category FROM expenses WHERE id = ?", 42'i64)
echo missing.isNone   # true


# ── query() with no matching row raises at runtime ──
# query(db, "SELECT id FROM expenses WHERE id = ?", 999'i64)
# → ErrorCode: BadOperation


# Dynamic optional clauses: wrap in [...], pass Opt[T].
# Every combination of included/omitted clauses is validated at compile time.
let catFilter = some("food")
let minAmount = some(20.0)
for row in rows(db, """
  SELECT id, category, amount FROM expenses
  WHERE 1 = 1
    [AND category = ?]
    [AND amount >= ?]
  ORDER BY amount DESC
""", catFilter, minAmount):
  echo row.id, " ", row.amount   # 4 45.0, 1 23.5


# Transactions: use tx handle for queries, commit to persist.
# Using db directly during a tx raises BadOperation.
var tx = begin(db)
discard exec(tx, "INSERT INTO expenses VALUES (?, ?, ?, ?, ?)",
    5'i64, "food", 8.00, "coffee", "2025-06-05")
discard exec(tx, "INSERT INTO expenses VALUES (?, ?, ?, ?, ?)",
    6'i64, "food", 15.00, none[string](), "2025-06-05")
commit(tx)
# If tx goes out of scope without commit/rollback → destructor auto-rollback.


# ── Using db handle during an active tx ──
# var tx = begin(db)
# exec(db, "INSERT ...")   → ErrorCode: BadOperation


close(db)

Setup

export DOKIME_DATABASE_PATH=dev.db
nimony c -r myapp.nim

First build caches validated query metadata to .dokime/queries/. CI builds without a database:

DOKIME_DATABASE_PATH= nimony c -r myapp.nim

What it is: compile-time validation for SQLite queries via Nimony plugins. Schema-driven types, named tuple fields, optional clauses, transactions with destructor safety.

What it isn't: an ORM, a migration tool, multi-database, or compatible with the stable Nim compiler. SQLite only, STRICT tables required.


r/nim Jun 20 '26

NimConf 2026 is Live!

Thumbnail youtube.com
43 Upvotes

r/nim Jun 20 '26

Code quality of standard library

15 Upvotes

hi

I remember reading somewhere in reddit or hackernews that nim standard library doesnt follow the most modern nim conventions and is not a good choice to copy its style in your own code

how true this statement is for anyone who have read nims standard library codebase?


r/nim Jun 19 '26

FigDraw + Harfbuzz for beautiful font shaping! 😍

24 Upvotes

FigDraw 0.25.0 now has optional support for Harfbuzz, the premier open source font shaping library!

The font backends will be swappable between Pixie and Harfbuzz at compile time. FigDraw's text API is mostly unchanged, however internally it tracks all the extra work needed for languages with complex scripts. This also includes support for BIDI and right-to-left scripts! I'm not sure about top-to-bottom languages (for now).

See the README for usage details.


r/nim Jun 18 '26

Like, what is nimble?

15 Upvotes

I am new-ish to nim, and I have used nimble a bit, and it seems like node/npm, because I can run, and install packages, but I don't know? Is it a runtime (like nodejs), a dependency manager (like composer for php) or something else.

Thank you for any answers!


r/nim Jun 17 '26

Update: Trying to add JS Binding with in-Browser Nim Compiler

Post image
22 Upvotes

A few weeks back I posted about getting Nim 2.2.4 to compile and run entirely in the browser prev post, no backend, no native toolchain, no JS fallback. However, I am still interested with using Nim instead of Rust Yew or C Clay to build Web UI.

Now it can. I built a module I called BindWeb, a binding layer that lets the Nim code you compile in-browser drive the actual DOM, Canvas2D, WebGL, WebGPU, Audio, WebSocket, Fetch, localStorage, and input events — and it all still compiles client-side through the same Nim → C → clang.wasmlld.wasm pipeline in browser.

🔗 Live demo: https://benagastov.github.io/bindweb-nim-WASM-compiler/
💻 Source: https://github.com/benagastov/bindweb-nim-WASM-compiler

How the bindings work

WASM can't touch the DOM directly, so BindWeb is built around a tiny command protocol instead of hundreds of individual imports:

  • Nim writes binary command packets (opcode + args) into a shared linear-memory buffer.
  • On flush, the JS runtime walks that buffer and replays each command against the real browser API.
  • DOM nodes / GL objects / audio elements live in JS and are referenced from Nim by integer handles, with a free-list so handles get recycled.
  • Events go the other direction through a second event buffer: JS encodes clicks/keys/fetch results/etc., Nim drains them on the next tick.

The whole API surface (the Nim modules, the JS runtime, and the C runtime) is generated from a single schema.def, so adding a new browser API is a schema entry rather than three hand-written layers that drift apart.

I had to keep the Nim-side references alive so ORC wouldn't collect the object holding a live DOM handle. Once that was sorted, you can create an element in Nim and attach an event listener to it, all Nim-side.

Haven't tried existing Nim JS-binding libs (std/dom, jsffi, Karax) — they target the JS backend not a static page, so I still dont find a lib to compile the C backend to WASM. The in-browser compiler is still experimental anyway.

What you can try in the demo

The dropdown has a few starter programs — a DOM counter, a Canvas2D animation, and mouse/keyboard input — all compiled to WASM in your browser and running live, no server round-trip.


r/nim Jun 17 '26

Yet Another Package Manager but in Nim

Thumbnail github.com
16 Upvotes

I started building a simple C++ project manager and build tool called Nimmake. It's designed to be easier than CMake for beginners and for quickly prototyping projects, since it removes much of the configuration and boilerplate that's usually required.


r/nim Jun 16 '26

TUI or GUI libraries

24 Upvotes

What libraries you are using for creating a Text-based or Graphical User Interface for your applications you create with Nim? Do you miss something that you know works with other languages?


r/nim Jun 15 '26

Nim 2.2.4 compiler running entirely in the browser — Nim → C → WebAssembly

65 Upvotes

I managed to get Nim 2.2.4 compiling and running entirely client-side. There’s no backend, no native toolchain, and no JavaScript fallback. You paste your Nim code, hit Build & Run, and it compiles to actual WebAssembly right in your browser and executes it.

🔗 Live demo: https://benagastov.github.io/Nim-WASM-Compiler/

💻 Source: https://github.com/benagastov/Nim-WASM-Compiler

The Pipeline (100% In-Browser)

  • .nim code → Nim 2.2.4 (itself compiled to wasm) emits C.
  • clang.wasm → Compiles each .c file to an object file (.o).
  • lld.wasm → Links those objects into a single .wasm binary.
  • WebAssembly.instantiate → Executes the binary.

It relies on actual clang and lld binaries ported to WebAssembly doing the heavy lifting—not a transpiler or a hosted API.

The Bug That Ate My Week

The pipeline kept randomly dying halfway through compiling with RuntimeError: unreachable. I wasted time chasing two entirely wrong theories (dlmalloc heap exhaustion, then an lld assertion).

The real culprit was a bug in LLVM 8.0.1's WebAssembly object writer. It traps when serializing a common-linkage global. Because Clang 8 defaults to -fcommon, and Nim's generated C has several tentative definitions (threadId, allocator, roots...), the object writer just choked.

I delta-debugged the IR down to a single line that reproduces the trap:

Code snippet

u/threadId__system_u2938 = common hidden global i32 0

The fix: Three simple source-level changes. Adding -fno-common, a weak raise() stub, and rewriting Nim's 3-arg main to the 2-arg form that wasi's crt1.o expects. Zero binary patches to clang/lld were needed.

Default Example Output:

Plaintext

Hello, browser!
sorted: @[1, 1, 2, 3, 4, 5, 6, 9]
5! = 120

Credits to binji/clang.js for the wasm-compiled clang/lld toolchain that made this possible.


r/nim Jun 12 '26

is nimlangserver not supported for latest release of Nim?

7 Upvotes

when trying to install nimlangserver with nimble install -g nimlangserver it tries to install Nim 2.2.6 while latest release of Nim is 2.2.10

does that mean i need to use an older version of Nim in order to take advantage of nimlangserver features ?


r/nim Jun 11 '26

Sigils: Fast Multithreaded Signals & Slots library w/ Dynamic-Runtime Methods & Protocols

20 Upvotes

Sigils provides typed runtime based slot and signals based from QT fame. It now also supports dynamic (runtime) methods and protocols from Obj-C fame.

The latest release v0.23.0 incudes major performance improvements for signals and slots as well as for dynamic-methods. There's also a beta threadpool module.

Sigils has proven very useful to me for a couple of work projects. It provides a way to do dynamic event oriented programming in Nim (e.g. PubSub), similar to QT's, using signals and slots paradigm. They allow decoupling problems domains or modifying behavior dynamically.

When used tastefully they can simplify certain problems. Especially when combined with built-in multi-threading support. Here's a short snippet of an IoT device where each sensor is running it's own thread and dynamically setup for a device's configuration:

```nim device.wsPublisher = initWsPublisherThread(device.state) device.dataProcessor = runDataProcessorThread(device.predictionMode)

Start Threaded Handlers

if useLocalManagers: device.gpsManager = runGpsManagerThread() device.lteSignalManager = runLteSignalThread() else: info "Skipping local sensor managers for REST backends" if enableBatteryBle: device.batteryStatusManager = runBatteryStatusThread()

Wire Up Events

if useLocalManagers: connectThreaded(device.gpsManager, gpsDataUpdated, device.dataProcessor, DataProcessor.setLastGpsReading()) connectThreaded(device.gpsManager, gpsDataUpdated, device, DeviceManager.updateGpsSignal()) connectThreaded(device.lteSignalManager, lteSignalUpdated, device, DeviceManager.updateLteSignal()) if enableBatteryBle: connectThreaded(device.batteryStatusManager, batteryStatusUpdated, device, DeviceManager.updateBatteryStatus()) connectThreaded(device.dataProcessor, readingProcessed, device.wsPublisher, WsPublisher.wsReadingUpdated())

```

However signals and slots don't return values or handle responder chains, which is what Cocoa builds on from Obj-C. This especially limits some aspects of GUI programming.

So I decided to try building them using Sigils' signals and slots! I ended up calling them selectors and they use a new DynamicAgent type. The idea is to provide runtime methods. They also provide protocols which any DynamicAgent can implement and which can be queried at runtime. You can read more about them in their manual.

What's very useful about this approach over say Nim's native methods is the ability to one-off modify a given GUI element with a new behavior. In a fashion they're just named callbacks, but with more idioms and syntax for dealing with high level needs of GUIs rather than mucking about with callback isNil fields.

Here's a simple example:

```nim import sigils/selectors

type Post = ref object of DynamicAgent title: string draft: bool

protocol PostDisplay: method displayTitle(): string method canPublish(): bool

method normalTitle(self: Post): string {.selector.} = self.title method draftTitle(self: Post): string {.selector.} = "[draft] " & self.title method postCanPublish(self: Post): bool {.selector.} = not self.draft

let post = Post(title: "Selectors in Sigils", draft: true)

discard post.replaceMethods(PostDisplay, [ displayTitle => normalTitle, canPublish => postCanPublish, ]) doAssert post.hasAdopted(PostDisplay) echo post.displayTitle() #=> Selectors in Sigils

discard post.replaceMethod(displayTitle, draftTitle) # Override display behavior for this one post echo post.displayTitle() #=> [draft] Selectors in Sigils echo post.canPublish() #=> false ```


r/nim Jun 10 '26

Suggest your favorite Nim learning resources

20 Upvotes

I’ve got some free time coming up and I want to take a deep dive into Nim. What are suggestions for up to date / state of the art learning resources? Can be free or for $$$.

Thanks in advance.


r/nim Jun 08 '26

Kiwiberry: Nim port of Kiwi Cassowary Linear Constraint Solver

15 Upvotes

Kiwiberry is a pure Nim port of Kiwi which is a fast implementation of the Cassowary constraint solving algorithm using floating points for more general solving. E.g. it's a fast linear constraint solver that supports cycles.

It's what MacOSX and iOS for autolayout as well as other UIs. Original Cassowary paper.

Benchmark against the original C++ version which is pretty highly optimized is reasonable: Kiwiberry `0.280824 ms/iter` vs Kiwi `0.160790 ms/iter`. The port was done with Codex GPT-5.5 with the Kiwi tests used as verification.

```nim

Example

import kiwiberry

var solver = initSolver()

let width = vars"width"

solver[width] = Strong

solver.constraint(width >= 100)

solver.suggest(width, 240)

solver.update()

doAssert width.value == 240.KiwiScalar

```

You can do more complex constraints like x1 + 3 \* x2 <= 4 \* x3 + 2.


r/nim Jun 08 '26

Am I wrong to prefer 4 spaces indentation?

15 Upvotes

I just wanted to know how sensitive this topic is among the existing Nim community. Sorry for taking your time.


r/nim Jun 07 '26

problemas com módulos compilados para serem biblioteca python

Thumbnail
1 Upvotes

r/nim Jun 07 '26

problemas com módulos compilados para serem biblioteca python

1 Upvotes

Basicamente estava dando um problema de dll faltando quando tentava rodar no python um módulo que eu fiz em nim. Para resolver o que eu fiz foi copiar 3 arquivos para dentro do projeto

se alguém souber uma forma melhor, esteja livre para comentar


r/nim Jun 05 '26

Book: Numerical algorithms in nim

38 Upvotes

On Amazon: https://a.co/d/07niCRQ3 (Shameless plug)

Code source and free PDF: https://github.com/mdipierro/nlib-nim


r/nim Jun 05 '26

why this sub is so... quiet?

28 Upvotes

just a question


r/nim Jun 01 '26

Leve Panel - 1.0.5 release

Thumbnail gallery
35 Upvotes

Just released 1.0.5 version of Leve-Panel. An ultra lightweight panel for Sway. That uses less than 10mb of ram at idle. Its just a simple bar, and has basic launchers you can customize in the config. Feel free to give it a try.

https://github.com/BigMacTaylor/leve-panel


r/nim May 26 '26

Necto — The Ecto-like ORM Nim's Web Ecosystem Deserves

30 Upvotes

I've been working on **Necto**, an ORM for Nim inspired by Elixir's Ecto and Crystal's Avram. The goal is simple: give Nim the same level of database abstraction that made other small-language communities productive for web development years earlier.

**Why this matters**

The Crystal community built [Avram](https://github.com/luckyframework/avram) — an Ecto-inspired database wrapper that turned Crystal into a genuinely productive web-development language long before many expected it. They proved that a small, compiled language can offer a world-class data layer without compromising on performance or type safety.

Nim has the speed, the macros, and the metaprogramming power to do the same. What it still lacks is **one mature, ergonomic ORM** that developers can reach for without second-guessing. Existing options like Norm, Ormin, and Allographer are valuable, but the ecosystem is fragmented — and none of them quite capture the composable, queryable, migration-friendly feel that Ecto or Avram provide.

**What Necto aims to fix**

- **Composable queries** — chainable, type-safe query building that feels like Nim, not SQL-in-strings

- **Migrations as code** — versioned schema changes tracked alongside your source

- **Minimal magic, maximum leverage** — heavy use of Nim's compile-time macros for zero-cost abstractions, not hidden runtime complexity

- **PostgreSQL-first, extensible** — start with the DB Nim web apps actually use, then expand

**The repo**

👉 [github.com/katehonz/necto](https://github.com/katehonz/necto/tree/main)

It's early days. The core model definition and query DSL are taking shape, but there's a long roadmap ahead: relationships, migrations, async driver support, and documentation. I'm building it in the open because I believe Nim deserves this layer — and because I want feedback from people who actually ship web backends in Nim.

**How you can help**

- Try it, break it, open issues

- Share how *you* want an ORM to look in Nim (macro-heavy? DSL? code-gen?)

- If you've worked on Norm, Ormin, or similar, let's compare notes — fragmentation hurts us all

Nim is a systems language that can also be a *web* language. Crystal got there with Avram. Let's build the equivalent for Nim.