about summary refs log tree commit diff
path: root/nixos/modules/system
diff options
context:
space:
mode:
authorJanne Heß <dasJ@users.noreply.github.com>2022-08-09 20:28:49 +0200
committerGitHub <noreply@github.com>2022-08-09 20:28:49 +0200
commit1120326a5b224189863b1f40d2b6ab6cdc8eeb54 (patch)
treed667f513e1c80ff666a1ab9a39ce9b4558e814f8 /nixos/modules/system
parent62ca0f7a189543b8d2f0f890ef0e3507f0890cce (diff)
parent4c2764c69c094d6917ff857aa4667f8886ef8d5e (diff)
downloadnixlib-1120326a5b224189863b1f40d2b6ab6cdc8eeb54.tar
nixlib-1120326a5b224189863b1f40d2b6ab6cdc8eeb54.tar.gz
nixlib-1120326a5b224189863b1f40d2b6ab6cdc8eeb54.tar.bz2
nixlib-1120326a5b224189863b1f40d2b6ab6cdc8eeb54.tar.lz
nixlib-1120326a5b224189863b1f40d2b6ab6cdc8eeb54.tar.xz
nixlib-1120326a5b224189863b1f40d2b6ab6cdc8eeb54.tar.zst
nixlib-1120326a5b224189863b1f40d2b6ab6cdc8eeb54.zip
Merge pull request #185067 from stigtsp/refactor/stc-no-net-debus
nixos/switch-to-configuration: replace Net::DBus with busctl
Diffstat (limited to 'nixos/modules/system')
-rwxr-xr-xnixos/modules/system/activation/switch-to-configuration.pl28
-rw-r--r--nixos/modules/system/activation/top-level.nix2
2 files changed, 23 insertions, 7 deletions
diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl
index 3f0d976e70b8..f39549db883d 100755
--- a/nixos/modules/system/activation/switch-to-configuration.pl
+++ b/nixos/modules/system/activation/switch-to-configuration.pl
@@ -18,7 +18,8 @@ use Config::IniFiles;
 use File::Path qw(make_path);
 use File::Basename;
 use File::Slurp qw(read_file write_file edit_file);
-use Net::DBus;
+use JSON::PP;
+use IPC::Cmd;
 use Sys::Syslog qw(:standard :macros);
 use Cwd qw(abs_path);
 
@@ -124,12 +125,29 @@ EOF
 # virtual console 1 and we restart the "tty1" unit.
 $SIG{PIPE} = "IGNORE";
 
+# Replacement for Net::DBus that calls busctl of the current systemd, parses
+# it's json output and returns the response using only core modules to reduce
+# dependencies on perlPackages in baseSystem
+sub busctl_call_systemd1_mgr {
+    my (@args) = @_;
+    my $cmd = [
+        "$cur_systemd/busctl", "--json=short", "call", "org.freedesktop.systemd1",
+        "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
+        @args
+    ];
+
+    my ($ok, $err, undef, $stdout) = IPC::Cmd::run(command => $cmd);
+    die $err unless $ok;
+
+    my $res = decode_json(join "", @$stdout);
+    return $res;
+}
+
 # Asks the currently running systemd instance via dbus which units are active.
 # Returns a hash where the key is the name of each unit and the value a hash
 # of load, state, substate.
 sub get_active_units {
-    my $mgr = Net::DBus->system->get_service("org.freedesktop.systemd1")->get_object("/org/freedesktop/systemd1");
-    my $units = $mgr->ListUnitsByPatterns([], []);
+    my $units = busctl_call_systemd1_mgr("ListUnitsByPatterns", "asas", 0, 0)->{data}->[0];
     my $res = {};
     for my $item (@{$units}) {
         my ($id, $description, $load_state, $active_state, $sub_state,
@@ -149,9 +167,7 @@ sub get_active_units {
 # Takes the name of the unit as an argument and returns a bool whether the unit is active or not.
 sub unit_is_active {
     my ($unit_name) = @_;
-
-    my $mgr = Net::DBus->system->get_service("org.freedesktop.systemd1")->get_object("/org/freedesktop/systemd1");
-    my $units = $mgr->ListUnitsByNames([$unit_name]);
+    my $units = busctl_call_systemd1_mgr("ListUnitsByNames", "as", 1, $unit_name)->{data}->[0];
     if (scalar(@{$units}) == 0) {
         return 0;
     }
diff --git a/nixos/modules/system/activation/top-level.nix b/nixos/modules/system/activation/top-level.nix
index 87ff1d97d8fa..0ceaed9ea6ff 100644
--- a/nixos/modules/system/activation/top-level.nix
+++ b/nixos/modules/system/activation/top-level.nix
@@ -124,7 +124,7 @@ let
     configurationName = config.boot.loader.grub.configurationName;
 
     # Needed by switch-to-configuration.
-    perl = pkgs.perl.withPackages (p: with p; [ ConfigIniFiles FileSlurp NetDBus ]);
+    perl = pkgs.perl.withPackages (p: with p; [ ConfigIniFiles FileSlurp ]);
   };
 
   # Handle assertions and warnings