All posts

rss icon RSS

How to run Incus on Void Linux

2024-07-23

Incus is the replacement of LXD one should use. For some reason it won't work well on Void out of the box after a while, and incus start <container-name> might stop doing anything. How do we fix it?

Looking at /usr/share/doc/incus/README.voidlinux it suggests the following:

Some container configurations may require that the `CGROUP_MODE`
variable in `/etc/rc.conf` be set to `unified`.

One way to solve it is that. I did another solution however, which I found at this github issue. I did the following:

I created this Perl script, called enable_incus somewhere:

#!/usr/bin/env perl

use v5.38;

! -d '/sys/fs/cgroup/systemd' or say("Incus already enabled. Skipping."), exit;

system('sudo mkdir /sys/fs/cgroup/systemd');
system('sudo mount -t cgroup -o none,name=systemd systemd /sys/fs/cgroup/systemd');

say 'OK';

Then I edited /etc/sv/incus/run and added this line near the top:

/path/to/enable_incus

...so that my script gets executed just before incus is launched.

This fixed the problem.

I managed to restore my backed-up LXD/Incus containers!

2024-07-22

Until now I've never managed to do it. Every time LXD complained that the backup I'm trying to restore is configured in an incompatible way with our system. Different bridge interface name, static IP is out of range of this machine's network pool, and other such stuff. So I was ending up creating new LXD containers from scratch instead of restoring my backups, whenever I re-installed Linux on my laptop.

Not this time though. The backup was a tar.gz file, so I uncompressed it, edited its two configuration files in there (backup/index.yaml and backup/container/backup.yaml) to my liking, re-compressed, and managed to import it.

Incus rocks!

How to use perl v5.40's boolean builtins in Mojo::Pg queries

2024-07-13

Perl v5.40 introduced native true and false keywords. Unfortunately not all CPAN modules are ready to use them. One of those not yet ready is Mojo::Pg.

Normally you'd want to pass booleans to your queries as just 1's and 0's. However, since Mojo::JSON's true & false stringify to 1 and 0, my 5.38-using codebase is full of Mojo::Pg queries with Mojo::JSON's true and false as arguments.

This is a problem if I want to upgrade the perl interpreter of that project to Perl v5.40, because if I write "use v5.40;" in the file that contains those boolean keywords, Perl's builtin booleans will be used instead, which don't stringify to 1 and 0, but to 1 and the empty string, which can't be used by DBD::Pg in boolean fields and makes DBD::Pg throw an exception.

The solution I found was to subclass Mojo::Pg::Database, and wrap the query method, so that if Perl's builtin booleans are found, they are replaced in the query with native Pg booleans.

This is the subclass:

package Local::My::Pg::Database;

use v5.40;
use Mojo::Base 'Mojo::Pg::Database';

use DBD::Pg ':pg_types';

use experimental 'builtin';

sub query {
    my ($self, $query) = (shift, shift);
    my $cb = ref $_[-1] eq 'CODE' ? pop : undef;
    my @args = map { builtin::is_bool($_) ? { type => PG_BOOL, value => $_ ? 1 : 0 } : $_ } @_;

    return $self->SUPER::query($query, @args, $cb // ());
}

...which requires the Mojo::Pg object to be told to use it:

$pg->database_class('Local::My::Pg::Database');

This solved my problem.

The other module I had problems with on Perl v5.40 is Mojolicious::Plugin::OpenAPI, which doesn't let the builtin booleans to be used in the API spec. I wrote a patch for that, and might submit it to the author.

Other than those, Mojo::JSON does not stringify builtin booleans to booleans, but to 1 and "" UNLESS Cpanel::JSON::XS is installed, then it works fine.

Have you found other CPAN modules that need to be updated for Perl v5.40's booleans?

Today I learned... #1: variable scoping in if-else blocks

2024-07-04

This block of code is valid Perl:

if (my $var1 = calc1()) {
    say $var1;
} elsif (my $var2 = calc2()) {
    say "$var1, $var2";
}

As you can see, $var1, which is declared in the if clause, is visible inside the elsif clause too.

Perl never ceases to amaze me!

Spam και Νέα Δημοκρατία

2024-03-16

Σ' αυτό το σημείο, κι αφού η Άννα-Μισέλ παραιτήθηκε και το θέμα του spam δείχνει νά' χει ενδιαφέρον, να υπενθυμίσουμε ότι ο Κυριάκος Μητσοτάκης όταν ξεκίνησε τη πολιτική του καριέρα είχε πάρει τη λίστα των emails όλων των αποφοίτων του Κολλεγίου Αθηνών απ' το σάιτ του ΣΑΚΑ (σύλλογος αποφοίτων κολλεγίου αθηνών) και μας σπάμαρε ανελέητα για πολλά χρόνια.

Κατά παράβαση του νόμου που ήδη υπήρχε για προσωπικά δεδομένα, και τον οποίον είχε ψηφίσει και η ΝΔ, ο οποίος μας προστάτευε και από το σπαμ (το έβλεπε ως παράνομη επεξεργασία προσωπικών δεδομένων).

Έτσι: νόμους βγάζουνε για να τους τηρείς εσύ κι εγώ, όχι αυτοί. Γιατί εσείς είστε τα κορόιδα, ενώ αυτοί όχι!

*σημείωση: ξέρω ότι τα email τα πήρε απ' το σάιτ του ΣΑΚΑ, γιατί μου έστελνε στο saka@<some domain> που είχα χρησιμοποιήσει μόνο για να γραφτώ σ' αυτό το σάιτ.

Η ΝΔ δεν τα πήγαινε καλά με το νόμο για σπαμ όμως, ούτε αργότερα. Το Μάιο 2018, όταν τέθηκε σε εφαρμογή ο νόμος GDPR για τα προσωπικά δεδομένα, η ΝΔ (όπως και όλες οι εταιρείες) όφειλε να λάβει opt-in επιβεβαίωση απ' τα μέλη της αν ήθελε να συνεχίσει να τους στέλνει ενημερωτικά emails, ευχές στις γιορτές, κλπ. Δεν τό' κανε. Οι βουλευτες της συνέχισαν να στέλνουν τακτικά στα μέλη της ΝΔ χωρίς κανείς τους να πάρει την απαιτούμενη συγκατάθεση.

Η ιστορία του κόσμου σε μία παράγραφο

2024-02-29

Κάποτε ο κόσμος ήταν καλός και κυβερνούσαν οι καλοί, αλλά σε κάποια φάση ήρθαν οι κακοί στην εξουσία με ύπουλες μεθοδεύσεις. Αυτό είχε σα συνέπεια ο κόσμος να πάει να καταστραφεί και μόνος τρόπος να σωθεί είναι να ξανάρθουν στα πράγματα οι καλοί. Φυσικά αυτό δε γίνεται με δημοκρατικές μεθόδους, γιατί οι κακοί έχουν φροντίσει να αποβλακώσουν το κόσμο, οπότε αναγκαστικά θα έρθουμε στα πράγματα πραξικοπιματικά.

Ετοιμαστείτε.

This is my new blog

2023-11-29

Welcome. As you will hopefully find out in this blog, Perl is the best language in the world.

#!/usr/bin/env perl

print "Hello, world!\n";