mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-21 11:34:13 +00:00
Merge pull request #316168 from dawidd6/systemd-user-generators
nixos/systemd: link user-generators
This commit is contained in:
commit
40066ba0d8
@ -503,8 +503,8 @@ in
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
|
||||
environment.etc = let
|
||||
# generate contents for /etc/systemd/system-${type} from attrset of links and packages
|
||||
hooks = type: links: pkgs.runCommand "system-${type}" {
|
||||
# generate contents for /etc/systemd/${dir} from attrset of links and packages
|
||||
hooks = dir: links: pkgs.runCommand "${dir}" {
|
||||
preferLocalBuild = true;
|
||||
packages = cfg.packages;
|
||||
} ''
|
||||
@ -512,7 +512,7 @@ in
|
||||
mkdir -p $out
|
||||
for package in $packages
|
||||
do
|
||||
for hook in $package/lib/systemd/system-${type}/*
|
||||
for hook in $package/lib/systemd/${dir}/*
|
||||
do
|
||||
ln -s $hook $out/
|
||||
done
|
||||
@ -562,8 +562,9 @@ in
|
||||
${cfg.sleep.extraConfig}
|
||||
'';
|
||||
|
||||
"systemd/system-generators" = { source = hooks "generators" cfg.generators; };
|
||||
"systemd/system-shutdown" = { source = hooks "shutdown" cfg.shutdown; };
|
||||
"systemd/user-generators" = { source = hooks "user-generators" cfg.user.generators; };
|
||||
"systemd/system-generators" = { source = hooks "system-generators" cfg.generators; };
|
||||
"systemd/system-shutdown" = { source = hooks "system-shutdown" cfg.shutdown; };
|
||||
});
|
||||
|
||||
services.dbus.enable = true;
|
||||
|
@ -144,6 +144,18 @@ in {
|
||||
};
|
||||
};
|
||||
|
||||
systemd.user.generators = mkOption {
|
||||
type = types.attrsOf types.path;
|
||||
default = {};
|
||||
example = { systemd-gpt-auto-generator = "/dev/null"; };
|
||||
description = ''
|
||||
Definition of systemd generators; see {manpage}`systemd.generator(5)`.
|
||||
|
||||
For each `NAME = VALUE` pair of the attrSet, a link is generated from
|
||||
`/etc/systemd/user-generators/NAME` to `VALUE`.
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.additionalUpstreamUserUnits = mkOption {
|
||||
default = [];
|
||||
type = types.listOf types.str;
|
||||
|
@ -1,5 +1,22 @@
|
||||
import ../make-test-python.nix (
|
||||
{ pkgs, lib, ... }: {
|
||||
{ pkgs, lib, ... }:
|
||||
let
|
||||
quadletContainerFile = pkgs.writeText "quadlet.container" ''
|
||||
[Unit]
|
||||
Description=A test quadlet container
|
||||
|
||||
[Container]
|
||||
Image=localhost/scratchimg:latest
|
||||
Exec=bash -c 'trap exit SIGTERM SIGINT; while true; do sleep 1; done'
|
||||
ContainerName=quadlet
|
||||
Volume=/nix/store:/nix/store
|
||||
Volume=/run/current-system/sw/bin:/bin
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
'';
|
||||
in
|
||||
{
|
||||
name = "podman";
|
||||
meta = {
|
||||
maintainers = lib.teams.podman.members;
|
||||
@ -174,6 +191,16 @@ import ../make-test-python.nix (
|
||||
with subtest("A podman non-member can not use the docker cli"):
|
||||
docker.fail(su_cmd("docker version", user="mallory"))
|
||||
|
||||
with subtest("A rootless quadlet container service is created"):
|
||||
dir = "/home/alice/.config/containers/systemd"
|
||||
rootless.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg"))
|
||||
rootless.succeed(su_cmd(f"mkdir -p {dir}"))
|
||||
rootless.succeed(su_cmd(f"cp -f ${quadletContainerFile} {dir}/quadlet.container"))
|
||||
rootless.systemctl("daemon-reload", "alice")
|
||||
rootless.systemctl("start quadlet", "alice")
|
||||
rootless.wait_until_succeeds(su_cmd("podman ps | grep quadlet"), timeout=20)
|
||||
rootless.systemctl("stop quadlet", "alice")
|
||||
|
||||
# TODO: add docker-compose test
|
||||
|
||||
'';
|
||||
|
Loading…
Reference in New Issue
Block a user