Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions checks/systemd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ let
}
);

readUserService = drv: name: builtins.readFile "${drv}/systemd/user/${name}.service";
readSystemService = drv: name: builtins.readFile "${drv}/systemd/system/${name}.service";
readUserTimer = drv: name: builtins.readFile "${drv}/systemd/user/${name}.timer";
readSystemTimer = drv: name: builtins.readFile "${drv}/systemd/system/${name}.timer";
readUserService = drv: name: builtins.readFile "${drv}/lib/systemd/user/${name}.service";
readSystemService = drv: name: builtins.readFile "${drv}/lib/systemd/system/${name}.service";
readUserTimer = drv: name: builtins.readFile "${drv}/lib/systemd/user/${name}.timer";
readSystemTimer = drv: name: builtins.readFile "${drv}/lib/systemd/system/${name}.timer";
in
pkgs.runCommand "systemd-test" { } ''
echo "Testing systemd module..."
Expand Down Expand Up @@ -314,14 +314,14 @@ pkgs.runCommand "systemd-test" { } ''

# Test 3: Service name from binName
echo "Test 3: Service name from binName"
test -f "${customBinName.outputs.systemd-user}/systemd/user/my-hello.service" || {
test -f "${customBinName.outputs.systemd-user}/lib/systemd/user/my-hello.service" || {
echo "FAIL: user service file should be named my-hello.service"
ls -la "${customBinName.outputs.systemd-user}/systemd/user/"
ls -la "${customBinName.outputs.systemd-user}/lib/systemd/user/"
exit 1
}
test -f "${customBinName.outputs.systemd-system}/systemd/system/my-hello.service" || {
test -f "${customBinName.outputs.systemd-system}/lib/systemd/system/my-hello.service" || {
echo "FAIL: system service file should be named my-hello.service"
ls -la "${customBinName.outputs.systemd-system}/systemd/system/"
ls -la "${customBinName.outputs.systemd-system}/lib/systemd/system/"
exit 1
}
echo "PASS: service name from binName"
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/systemd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let
mkOutput =
type:
let
unitDir = if type == "user" then "systemd/user" else "systemd/system";
unitDir = if type == "user" then "lib/systemd/user" else "lib/systemd/system";

serviceFile = pkgs.writeTextDir "${unitDir}/${serviceName}.service" (systemdLib.serviceToUnit svc)
.text;
Expand Down
49 changes: 46 additions & 3 deletions modules/niri/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ let
in
{
_class = "wrapper";
imports = [ wlib.modules.systemd ];
options = {
settings = lib.mkOption {
type = lib.types.submodule {
Expand Down Expand Up @@ -304,13 +305,55 @@ in
'';
};
};
# Drop the upstream user unit; we ship our own (below) with ExecReload
# wired up to the niri IPC. Keep the desktop entry patched so display
# managers still pick up the wrapper's binary.
config.filesToExclude = [
"lib/systemd/user/niri.service"
"share/systemd/user/niri.service"
];
config.filesToPatch = [
"share/applications/*.desktop"
"share/systemd/user/niri.service"
];
config.package = config.pkgs.niri;
config.env = {
NIRI_CONFIG = toString config."config.kdl".path;

# Shell-launched wrapper: same behaviour as upstream -- niri reads the
# immutable, build-pinned config straight from /nix/store.
config.env.NIRI_CONFIG = toString config."config.kdl".path;

Comment on lines +319 to +323
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Shell-launched wrapper: same behaviour as upstream -- niri reads the
# immutable, build-pinned config straight from /nix/store.
config.env.NIRI_CONFIG = toString config."config.kdl".path;
config.env.NIRI_CONFIG = toString config."config.kdl".path;

this should be obvious. no point in having a LLM comment for it

# Systemd-launched session: bootstrap a mutable runtime copy under
# $XDG_RUNTIME_DIR (systemd specifier %t) and point niri at it via
# `--config`. ExecReload re-stamps that file with the latest immutable
# snapshot and asks niri to re-read it via IPC, so config-only switches
# apply without dropping the session.
Comment on lines +324 to +328
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Systemd-launched session: bootstrap a mutable runtime copy under
# $XDG_RUNTIME_DIR (systemd specifier %t) and point niri at it via
# `--config`. ExecReload re-stamps that file with the latest immutable
# snapshot and asks niri to re-read it via IPC, so config-only switches
# apply without dropping the session.

no longer relevant

config.systemd = {
description = "A scrollable-tiling Wayland compositor";
bindsTo = [ "graphical-session.target" ];
before = [
"graphical-session.target"
"xdg-desktop-autostart.target"
];
wants = [
"graphical-session-pre.target"
"xdg-desktop-autostart.target"
];
after = [ "graphical-session-pre.target" ];
serviceConfig = {
Slice = "session.slice";
Type = "notify";
ExecStartPre = "${config.pkgs.coreutils}/bin/install -Dm644 ${config."config.kdl".path} %t/niri/config.kdl";
ExecStart = "${config.exePath} --session --config %t/niri/config.kdl";
ExecReload = [
"${config.pkgs.coreutils}/bin/install -Dm644 ${config."config.kdl".path} %t/niri/config.kdl"
"${config.exePath} msg action load-config-file"
];
Comment on lines +344 to +349
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ExecStartPre = "${config.pkgs.coreutils}/bin/install -Dm644 ${config."config.kdl".path} %t/niri/config.kdl";
ExecStart = "${config.exePath} --session --config %t/niri/config.kdl";
ExecReload = [
"${config.pkgs.coreutils}/bin/install -Dm644 ${config."config.kdl".path} %t/niri/config.kdl"
"${config.exePath} msg action load-config-file"
];
ExecStart = "${config.exePath} --session --config ${config."config.kdl".path}";
ExecReload = "${config.exePath} msg action load-config-file --path ${config."config.kdl".path}";

with niri 26.05 there is no reason to do mutable copies at the config file can just be relocated (infact i implemented that feature exactly for this reason in niri :) )

};
# Tell NixOS's switch-to-configuration to convert every "needs
# restart" verdict into `systemctl --user reload niri.service`, so
# config-only switches reload the live session via ExecReload instead
# of killing it. The flag is read out of the unit's [Service] section
# at switch time (X-ReloadIfChanged=true).
reloadIfChanged = true;
};
config.meta.maintainers = [
lib.maintainers.zimward
Expand Down
Loading