From ad80be721be5bf60f69f0a244f882bb00edaf269 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Wed, 6 Nov 2024 14:09:41 +0900 Subject: [PATCH] nix: improve start script Zsh store path in shebang. Replace writeShellScript with writeScript since runtimeShell is not overridable. Signed-off-by: Ophestra Umiker --- README.md | 4 +++- nixos.nix | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 092b4e8..5d62b0f 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,9 @@ This adds the `environment.fortify` option: * `id`, the freedesktop application ID, primarily used by dbus, null to disable. - * `command`, the command to run as the target user. Defaults to launcher name. + * `script`, application launch script. + + * `command`, the command to run as the target user. Defaults to launcher name. Has no effect when script is set. * `dbus.session`, D-Bus session proxy custom configuration. diff --git a/nixos.nix b/nixos.nix index 32fab1f..9f700c3 100644 --- a/nixos.nix +++ b/nixos.nix @@ -64,12 +64,21 @@ in ''; }; + script = mkOption { + type = nullOr str; + default = null; + description = '' + Application launch script. + ''; + }; + command = mkOption { type = nullOr str; default = null; description = '' Command to run as the target user. Setting this to null will default command to wrapper name. + Has no effect when script is set. ''; }; @@ -298,6 +307,7 @@ in system_bus = launcher.dbus.system; }; command = if launcher.command == null then name else launcher.command; + script = if launcher.script == null then ("exec " + command + " $@") else launcher.script; enablements = (if wayland then 1 else 0) + (if x11 then 2 else 0) @@ -307,8 +317,10 @@ in inherit (launcher) id method; inherit user; command = [ - "/run/current-system/sw/bin/zsh" - (pkgs.writeShellScript "${name}-start" ("exec " + command + " $@")) + (pkgs.writeScript "${name}-start" '' + #!${pkgs.zsh}${pkgs.zsh.shellPath} + ${script} + '') ]; confinement = { sandbox = {