journald-send - Library to help write logs to journald, for Python

In the last April, I made journald-send, to serve as replacement for systemd-python, for folks who want to write logs to journald, using native protocol.

It is a partial replacement, because it only offers the "write" part, not "read". That's enough because most of applications which want to talk with journald just need to "write". I made journald-send out of the frustration that systemd-python development seems to be stuck, the last release was on the beginning of 2023, when it is 2026 now, and the compatibility with Python 3.14 is uncertain. Even after I contributed some code to modernize the Python project structure, the core developers still seems to not rush to make a release.

I wrote [jounald-send] in Rust, aiming for Python 3.14 free-threaded (No GIL) mode. Because I only need to support "write" operation, I decide not to depend on the C libsystemd, and go further by using Rust pure libraries (rustix and memfd) to talk with Linux API. I learnt from tracing-journald for how to prepare data for journald protocol and which steps to do with the sockets. The difference is that tracing-journald is using libc and I use rustix, memfd.

After finishing journald-send, I updated my other libraries chameleon-log, structlog-journald to use journald-send under the hood. chameleon-log is for integrating logbook and structlog-journald is for integrating with structlog.


Define UI comprising ListView in Blueprint for modern GTK apps

In a previous post, "Define UI comprising Dropdown in Blueprint for modern GTK apps", I presented how to use DropDown in Blueprint. Now we go with a bit more complex example, with ListView widget.

This is the UI where ListView is used, in my CoBang app:

WiFi list

It shows a list of WiFi network config, for which user will pick to generate QR code. The list is accompanied with a search box, via which user will type part of Wi-Fi name to narrow down the list, to quickly find the needed Wi-Fi network.


Define UI comprising Dropdown in Blueprint for modern GTK apps

GTK is one of the GUI toolkits for building Linux desktop apps, notable for its modern visual look, and with some advanced developer experience features, like Inspector.

But one of the things that is still old-fashioned is its support for declarative UI. GTK allows developer to describe the UI separately from application code, but the language is XML which is too verbose, comparing to QT's QML or Slint. Fortunately, there is an new language, Blueprint, to describe UI for GTK app, which brings the same taste of QML, Slint to the table. But Blueprint is still young, not integrated to GTK yet (the files written in Blueprint must be compiled to Gtk.Builder XML) and the documentation is not rich enough.

This post shows you how to use Dropdown or other list widgets (like ListView, GridView) in Blueprint. The example use case and code is drawn from my application, CoBang.

List widgets follow Model-View-Controller pattern, to dislay a list of data with dynamic length. The widget is not used alone, but with other non-display components from GTK library:

...


Set a terminal emulator to be default for Ubuntu 25.04+

Ubuntu comes with a default terminal emulator, GNOME Terminal. But due to the limit of the underlying vte, many users don't want to use it. If you want to set a different program as default terminal, so that you can invoke it with Ctrl + Alt + T, here is how to do it.

Determine the desktop file of your terminal, by searching in /usr/share/applications/ or ~/.local/share/applications/. For example, kitty has one at ~/.local/share/applications/kitty.desktop, Ghostty has one at /usr/share/applications/com.mitchellh.ghostty.desktop.

Edit the ~/.config/xdg-terminals.list file (create it if it does not exist). Add the name of the desktop file at the top. For example, here is mine:

...

Make Nginx Unit controllable from non-root user

Recently I heard about Nginx Unit, a piece of software which lets you run Python web application on production with less components. It's like you let Nginx run your Python code, no longer Nginx - Gunicorn separation. So I installed it and learned how to use, but the default setup is not convenient: You have to switch to root user too often. So I share extra steps of setup to save you from it.

Nginx Unit is not configured via file like Nginx. It is done via HTTP API, which is nice because Nginx Unit can get update with new configuration without restarting, although I don't know what is the benefit over using SIGHUP signal to trigger rereading. The API communication is done via Unix domain socket, leveraging Linux authentication for restricting access, which is very reasonable because we don't have to remember port, username and password. But the issue is that, the default setup makes the socket writable by root only.

Unit control socket

The annoyance come from the combination of these factors:

...

Đồ chơi để thấy GraphQL đỡ phiền

GraphQL là một dạng thiết kế HTTP API được dùng rộng rãi. Mặt lợi của nó thì không cần bàn. Tuy nhiên mình và có thể các bạn cũng thấy hơi phiền vì nó dài dòng. Bài này sẽ giới thiệu một số phương tiện phần mềm để làm việc với nó thoải mái hơn, ở phía client.

Python: Cách dùng Pydantic để kiểm tra hợp lệ

Lấy ví dụ API của BirdWeather. Đây là kho dữ liệu của các trạm thu thập tiếng chim hót, phục vụ nghiên cứu nhận dạng chim từ tiếng hót. Ta sẽ gọi vào truy vấn stations để lấy danh sách các trạm. Một response mẫu sẽ trông như sau:

...

Cấu hình autocomplete cho Nushell

Bạn đã thích thú với Nushell, đã cài vào nhưng không thấy tính năng auto-complete? Đừng vội buồn. Đó là vì các file cài đặt Nushell hiện tại không kèm sẵn các script auto-complete. Bạn sẽ phải làm thêm tí việc tay chân để cài các script này vào.

Mặc dù yêu thích Nushell, mình phải thừa nhận rằng mức độ hỗ trợ auto-complete của Nushell chưa dồi dào bằng Fish. Nushell được thiết kế để nhận dữ liệu auto-complete từ cả các script chuyên dụng viết bằng Nu và từ cả phần mềm khác.

1. Nguồn từ phần mềm khác

Từ trong Nushell, gõ:

...

Resolve conflict of auto-completion script when installing some packages

If we have Fish installed and try to install pretty new softwares via APT package manager (on Ubuntu), we may encounter this error:

Error: error processing archive /var/cache/apt/archives/just_1.35.0-1build1_amd64.deb (--unpack):

Error: error processing archive /var/cache/apt/archives/just_1.35.0-1build1_amd64.deb (--unpack):
 trying to overwrite '/usr/share/fish/completions/just.fish', which is also in package fish 4.0b1-1~oracular
...

Grey background issue with Helix inside Byobu

I often work on a remote Linux box and like to have Byobu running so that I have tab view and status bar. But somedays in mid 2024, somethings start to break when I open Helix inside Byobu and get this annoying gray background every where:

Grey background

The root issue is that, Byobu runs Tmux with a configuration, and that configuration makes tmux disable some features which is needed to render Helix theme correctly. The key is the TERM environment variable. No matter which terminal emulator we use, after running Byobu, the TERM is set to screen-256color.

...