mirror of
https://github.com/LnL7/nix-darwin.git
synced 2024-12-14 11:57:34 +00:00
improve launchd activation scripts
This commit is contained in:
parent
d82c472ab0
commit
fecd4bc368
3 changed files with 16 additions and 40 deletions
|
@ -11,6 +11,7 @@ let
|
||||||
./modules/system/activation-scripts.nix
|
./modules/system/activation-scripts.nix
|
||||||
./modules/system/defaults
|
./modules/system/defaults
|
||||||
./modules/system/etc.nix
|
./modules/system/etc.nix
|
||||||
|
./modules/system/launchd.nix
|
||||||
./modules/environment
|
./modules/environment
|
||||||
./modules/launchd
|
./modules/launchd
|
||||||
./modules/programs/tmux.nix
|
./modules/programs/tmux.nix
|
||||||
|
|
|
@ -7,17 +7,16 @@ let
|
||||||
|
|
||||||
cfg = config.launchd;
|
cfg = config.launchd;
|
||||||
|
|
||||||
|
toEnvironmentText = name: value: {
|
||||||
|
name = "${value.serviceConfig.Label}.plist";
|
||||||
|
value.text = toPLIST value.serviceConfig;
|
||||||
|
};
|
||||||
|
|
||||||
launchdConfig = import ./launchd.nix;
|
launchdConfig = import ./launchd.nix;
|
||||||
|
|
||||||
serviceOptions =
|
serviceOptions =
|
||||||
{ config, name, ... }:
|
{ config, name, ... }:
|
||||||
{ options = {
|
{ options = {
|
||||||
plist = mkOption {
|
|
||||||
internal = true;
|
|
||||||
type = types.path;
|
|
||||||
description = "The generated plist.";
|
|
||||||
};
|
|
||||||
|
|
||||||
serviceConfig = mkOption {
|
serviceConfig = mkOption {
|
||||||
type = types.submodule launchdConfig;
|
type = types.submodule launchdConfig;
|
||||||
example =
|
example =
|
||||||
|
@ -34,12 +33,12 @@ let
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
serviceConfig.Label = mkDefault "org.nixos.${name}";
|
serviceConfig.Label = mkDefault "org.nixos.${name}";
|
||||||
|
|
||||||
plist = pkgs.writeText "${config.serviceConfig.Label}.plist" (toPLIST config.serviceConfig);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
in {
|
in
|
||||||
|
|
||||||
|
{
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
launchd.agents = mkOption {
|
launchd.agents = mkOption {
|
||||||
|
@ -54,35 +53,12 @@ in {
|
||||||
description = "Definition of launchd daemons.";
|
description = "Definition of launchd daemons.";
|
||||||
};
|
};
|
||||||
|
|
||||||
launchd.user.agents = mkOption {
|
|
||||||
default = {};
|
|
||||||
type = types.attrsOf (types.submodule serviceOptions);
|
|
||||||
description = "Definition of launchd per-user agents.";
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
system.build.launchd = pkgs.stdenvNoCC.mkDerivation {
|
environment.launchAgents = mapAttrs' toEnvironmentText cfg.agents;
|
||||||
name = "launchd-library";
|
environment.launchDaemons = mapAttrs' toEnvironmentText cfg.daemons;
|
||||||
preferLocalBuild = true;
|
|
||||||
|
|
||||||
buildCommand = ''
|
|
||||||
mkdir -p $out/Library/LaunchDaemons
|
|
||||||
ln -s ${cfg.daemons.nix-daemon.plist} $out/Library/LaunchDaemons/${cfg.daemons.nix-daemon.serviceConfig.Label}.plist
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
system.activationScripts.launchd.text = ''
|
|
||||||
# Set up launchd services in /Library/LaunchAgents, /Library/LaunchDaemons and ~/Library/LaunchAgents
|
|
||||||
echo "setting up launchd services..."
|
|
||||||
|
|
||||||
launchctl unload '/Library/LaunchDaemons/${cfg.daemons.nix-daemon.serviceConfig.Label}.plist'
|
|
||||||
ln -sfn '${cfg.daemons.nix-daemon.plist}' '/Library/LaunchDaemons/${cfg.daemons.nix-daemon.serviceConfig.Label}.plist'
|
|
||||||
launchctl load '/Library/LaunchDaemons/${cfg.daemons.nix-daemon.serviceConfig.Label}.plist'
|
|
||||||
|
|
||||||
'';
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
{ lib, mkTextDerivation }:
|
{ lib, mkTextDerivation }:
|
||||||
|
|
||||||
|
{ config, name, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
{ config, name, ... }:
|
|
||||||
let
|
let
|
||||||
|
|
||||||
sourceDrv = mkTextDerivation name config.text;
|
sourceDrv = mkTextDerivation name config.text;
|
||||||
|
@ -16,8 +17,8 @@ in
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = ''
|
description = ''
|
||||||
Whether this /etc file should be generated. This
|
Whether this file should be generated.
|
||||||
option allows specific /etc files to be disabled.
|
This option allows specific files to be disabled.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,9 +34,7 @@ in
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = name;
|
default = name;
|
||||||
description = ''
|
description = ''
|
||||||
Name of symlink (relative to
|
Name of symlink. Defaults to the attribute name.
|
||||||
<filename>/etc</filename>). Defaults to the attribute
|
|
||||||
name.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue