mirror of
https://github.com/LnL7/nix-darwin.git
synced 2025-03-15 13:07:45 +00:00
launchd: add script option for services
This commit is contained in:
parent
fa03cd4939
commit
7ca9f3d5bb
2 changed files with 32 additions and 28 deletions
|
@ -5,6 +5,8 @@ with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
inherit (pkgs) stdenv;
|
||||||
|
|
||||||
cfg = config.launchd;
|
cfg = config.launchd;
|
||||||
|
|
||||||
toEnvironmentText = name: value: {
|
toEnvironmentText = name: value: {
|
||||||
|
@ -51,6 +53,12 @@ let
|
||||||
description = "Command executed as the service's main process.";
|
description = "Command executed as the service's main process.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
script = mkOption {
|
||||||
|
type = types.lines;
|
||||||
|
default = "";
|
||||||
|
description = "Shell commands executed as the service's main process.";
|
||||||
|
};
|
||||||
|
|
||||||
# preStart = mkOption {
|
# preStart = mkOption {
|
||||||
# type = types.lines;
|
# type = types.lines;
|
||||||
# default = "";
|
# default = "";
|
||||||
|
@ -75,6 +83,12 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
command = mkIf (config.script != "") (pkgs.writeScript "${name}-start" ''
|
||||||
|
#! ${stdenv.shell}
|
||||||
|
|
||||||
|
${config.script}
|
||||||
|
'');
|
||||||
|
|
||||||
serviceConfig.Label = mkDefault "org.nixos.${name}";
|
serviceConfig.Label = mkDefault "org.nixos.${name}";
|
||||||
serviceConfig.ProgramArguments = mkIf (cmd != "") [ "/bin/sh" "-c" "exec ${cmd}" ];
|
serviceConfig.ProgramArguments = mkIf (cmd != "") [ "/bin/sh" "-c" "exec ${cmd}" ];
|
||||||
serviceConfig.EnvironmentVariables = mkIf (env != {}) env;
|
serviceConfig.EnvironmentVariables = mkIf (env != {}) env;
|
||||||
|
@ -85,7 +99,6 @@ in
|
||||||
|
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
launchd.envVariables = mkOption {
|
launchd.envVariables = mkOption {
|
||||||
type = types.attrsOf (types.either types.str (types.listOf types.str));
|
type = types.attrsOf (types.either types.str (types.listOf types.str));
|
||||||
default = {};
|
default = {};
|
||||||
|
@ -161,7 +174,6 @@ in
|
||||||
5. When the user logs out, it sends a SIGTERM signal to all of the user agents that it started.
|
5. When the user logs out, it sends a SIGTERM signal to all of the user agents that it started.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
|
@ -8,9 +8,23 @@ let
|
||||||
|
|
||||||
cfg = config.services.activate-system;
|
cfg = config.services.activate-system;
|
||||||
|
|
||||||
activateScript = pkgs.writeScript "activate-system" ''
|
in
|
||||||
#! ${stdenv.shell}
|
|
||||||
|
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
services.activate-system.enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to activate system at boot time.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
|
launchd.daemons.activate-system = {
|
||||||
|
script = ''
|
||||||
# Make this configuration the current configuration.
|
# Make this configuration the current configuration.
|
||||||
# The readlink is there to ensure that when $systemConfig = /system
|
# The readlink is there to ensure that when $systemConfig = /system
|
||||||
# (which is a symlink to the store), /run/current-system is still
|
# (which is a symlink to the store), /run/current-system is still
|
||||||
|
@ -22,28 +36,6 @@ let
|
||||||
|
|
||||||
${config.system.activationScripts.nix.text}
|
${config.system.activationScripts.nix.text}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in
|
|
||||||
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
services.activate-system = {
|
|
||||||
|
|
||||||
enable = mkOption {
|
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
description = ''
|
|
||||||
Whether to activate system at boot time.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
|
|
||||||
launchd.daemons.activate-system = {
|
|
||||||
command = activateScript;
|
|
||||||
serviceConfig.RunAtLoad = true;
|
serviceConfig.RunAtLoad = true;
|
||||||
serviceConfig.KeepAlive.SuccessfulExit = false;
|
serviceConfig.KeepAlive.SuccessfulExit = false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue