Support for Go library and utilities#36914
Conversation
Signed-off-by: Morten Linderud <morten@linderud.pw>
Allow users to configure their whole system using one rc.conf, the true UNIX way. Heavily inspired by https://github.com/teg/initscripts-arch/ Co-authored-by: Jelle van der Waa <jelle@vdwaa.nl> Signed-off-by: Morten Linderud <morten@linderud.pw>
Using the power of go modules(!) directly talk to the system bus and enable/disable daemons with it! *poof* magic!
Go is good, we need go for building.
YHNdnzj
left a comment
There was a problem hiding this comment.
Excellent work, thanks! LGTM and definitely makes systemd more future-proof 😄
bluca
left a comment
There was a problem hiding this comment.
The CI is red, but that's probably because it's not memory safe
| require github.com/coreos/go-systemd/v22 v22.5.0 | ||
|
|
||
| require ( | ||
| github.com/foxboron/go-uefi v0.0.0-20241219185318-19dc140271bf // indirect |
There was a problem hiding this comment.
Is this a bad rebase maybe? I don't understand why that pulls uefi here.
There was a problem hiding this comment.
@baloo Ah sorry, I was originally going to rewrite some ASN1 sbsign code :)
Will fix tomorrow with CI failures!
| # - prefix a daemon with a ! to disable it | ||
| # - prefix a daemon with a @ to start it up in the background | ||
| # | ||
| DAEMONS=(nginx @sshd !lvm2-monitor) |
There was a problem hiding this comment.
One of the most valuable features ever observed in this tracker. Why ever work with elaborate and convoluted configs when you had everything presented in a single file. Units? Drop-ins? Never heard of them.
Small nit though: arrays are bashism. To give people 100% original flavor let's embrace posix sh
|
100% on board with this. First, the choice of language: It's clear that Rust isn't the future... I'm glad we chose a reasonable systems-level language like golang instead! Second, the functionality: I love how much this simplified the config file formats! Just awesome! We can start deleting all the bloat, like systemd-datetime, hostnamed, networkd, and all those other pointless services Bravo. Once CI is green we should merge ASAP, to make it in time for v258 |
| } | ||
|
|
||
| // Should all be well formed configs | ||
| parts := strings.Split(line, "=") |
There was a problem hiding this comment.
Seems like strings.Cut is better suited for this task.
yuwata
left a comment
There was a problem hiding this comment.
Adding go as a second language is OK.
But, I am not a fan of introducing rc-generator.
We already deprecate rc-local-generator, and rc-generator added by this PR looks something similar.
| '.') | ||
|
|
||
| libsystemd_includes = [basic_includes, include_directories( | ||
| 'src/go', |
There was a problem hiding this comment.
Why? I cannot find any reasons. Please drop.
| subdir('src/shared') | ||
| subdir('src/libudev') | ||
|
|
||
|
|
There was a problem hiding this comment.
Please drop unnecessary empty line insertion.
There was a problem hiding this comment.
Disagree, please insert more empty lines
| subdir('src/run') | ||
| subdir('src/run-generator') | ||
| subdir('src/sbsign') | ||
| subdir('src/gobuildversion') |
There was a problem hiding this comment.
Please sort if there is no particular reason.
| command: ['go', 'build', | ||
| '-C', meson.current_source_dir(), | ||
| '-buildmode=c-archive', '-o', meson.current_build_dir() / 'go_library.a' , '.'], |
There was a problem hiding this comment.
Not a big matter, but spurious indentation.
Please break line after [
| '-buildmode=c-archive', '-o', meson.current_build_dir() / 'go_library.a' , '.'], | ||
| ) | ||
|
|
||
| libgo_dep = declare_dependency (sources: libgo) |
| ], | ||
| 'sources' : files('sbsign.c'), | ||
| 'dependencies' : libopenssl, | ||
| 'dependencies' : [libopenssl, libgo_dep], |
| libbasic_static, | ||
| libsystemd_static], | ||
| libsystemd_static, | ||
| libgo], |
| } | ||
|
|
||
|
|
||
| static int verb_version(int argc, char *argv[], void *userdata) { |
There was a problem hiding this comment.
Please rename to verb_generate() or so.
|
|
||
| static int run(int argc, char *argv[]) { | ||
| static const Verb verbs[] = { | ||
| { "help", VERB_ANY, VERB_ANY, 0, help }, |
There was a problem hiding this comment.
Please drop help from verb.
But support -h/--help and --version.
| diffutils | ||
| erofs-utils | ||
| git | ||
| go |
There was a problem hiding this comment.
Maybe also add go dependency for opensuse and centos ?
|
CodeQL passes, so we know the code is good. This is the most important part. |
|
lgtm |
I embrace the idea, but just one nitpick: I think it should use XML, the One True Format For Everything. It's not just more flexible and modern than shell, but also more readable: <?xml version="1.0" encoding="utf-8"?>
<!--
/etc/rc.conf - Main Configuration for Modern Linux
-->
<rc xmlns="urn:io.systemd.system1.rc.conf">
<!-- Localization -->
<!--
locale: available languages can be listed with the 'locale -a' command
timezone: timezones are found in /usr/share/zoneinfo
keymap: keymaps are found in /usr/share/kbd/keymaps
-->
<localization>
<locale>en_US.UTF-8</locale>
<timezone>Europe/Berlin</timezone>
<keymap>us</keymap>
</localization>
<!-- Networking -->
<!-- hostname: Hostname of machine. Should also be put in /etc/hosts -->
<network hostname="myhost">
<!--
Use 'ip addr' or 'ls /sys/class/net/' to see all available interfaces.
Wired network setup
- interface: name of device (required)
- address: IP address (leave blank for DHCP)
- netmask: subnet mask (ignored for DHCP) (optional, defaults to 255.255.255.0)
- broadcast: broadcast address (ignored for DHCP) (optional)
- gateway: default route (ignored for DHCP)
Static IP example
interface=eth0
address=192.168.0.2
netmask=255.255.255.0
broadcast=192.168.0.255
gateway=192.168.0.1
DHCP example
interface=eth0
address=
netmask=
gateway=
-->
<interface/>
<address/>
<netmask/>
<broadcast/>
<gateway/>
</network>
<!-- Daemons -->
<!--
Daemons to start at boot-up (in this order)
-->
<daemons>
<daemon>nginx</daemon>
<daemon start="background">sshd</daemon>
<daemon action="disable">lvm2-monitor"</daemon>
</daemons>
</rc>
|
|
Nah, S-Expressions are the way to go. |
|
100% agree with @dtardon 👍🏾 |
Conan-Kudo
left a comment
There was a problem hiding this comment.
We can close up shop folks, all problems solved!
|
Thanks everyone :) ❤️ |
This PR introduces two new changes.
A Go Library
systemd is an important set of libraries and utilities on modern Linux systems. The need to remove C in favour of memory-safe alternative is of peak priority.
Rust has been a hot contender for this for a while, but after several attempts at getting support for object file creation in
rustchas failed, Rust falls short of integration into existing codebases.A popular, and memory-safe, alternative with proper C interop is needed and the natural choice is of course to use Go.
Go enables systemd to leverage state-of-the-art concurrency primitives with a garbage collected runtime. This will enable systemd developers to accelerate their work for towards more awesome features.
The Go runtime is built with the shared systemd library. The size difference is negligible.
/etc/rc.confgeneratorAs PLT peaked in the 90s, we also wanted to reintroduce init service as they where meant to be handled, with a unified
/etc/rc.conf.systemd-rc-conf-generatorsupports enabling locale, keymaps, timezone, network configuraiton, job initialization and hostname configuration. All written in a terse 200 lines of go code.Systemd interaction is also enabled with the help of
coreos/go-systemdlibrary through dbus calls.We thank @teg for all his wisdom over the years, now we can finally manage our system from one central file like the good ol' days.
All functionalities are written in Pure 100% Go, and then called from the proper C-binaries as you would expect from the systemd codebase.