diff --git a/config.nix b/config.nix index 42884bec..ddda92f3 100644 --- a/config.nix +++ b/config.nix @@ -11,6 +11,7 @@ let ./modules/system/activation-scripts.nix ./modules/system/defaults ./modules/system/etc.nix + ./modules/system/launchd.nix ./modules/environment ./modules/launchd ./modules/programs/tmux.nix diff --git a/modules/launchd/default.nix b/modules/launchd/default.nix index 8ff69331..5d1fc699 100644 --- a/modules/launchd/default.nix +++ b/modules/launchd/default.nix @@ -7,17 +7,16 @@ let cfg = config.launchd; + toEnvironmentText = name: value: { + name = "${value.serviceConfig.Label}.plist"; + value.text = toPLIST value.serviceConfig; + }; + launchdConfig = import ./launchd.nix; serviceOptions = { config, name, ... }: { options = { - plist = mkOption { - internal = true; - type = types.path; - description = "The generated plist."; - }; - serviceConfig = mkOption { type = types.submodule launchdConfig; example = @@ -34,12 +33,12 @@ let config = { serviceConfig.Label = mkDefault "org.nixos.${name}"; - - plist = pkgs.writeText "${config.serviceConfig.Label}.plist" (toPLIST config.serviceConfig); }; }; -in { +in + +{ options = { launchd.agents = mkOption { @@ -54,35 +53,12 @@ in { description = "Definition of launchd daemons."; }; - launchd.user.agents = mkOption { - default = {}; - type = types.attrsOf (types.submodule serviceOptions); - description = "Definition of launchd per-user agents."; - }; - }; config = { - system.build.launchd = pkgs.stdenvNoCC.mkDerivation { - name = "launchd-library"; - 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' - - ''; + environment.launchAgents = mapAttrs' toEnvironmentText cfg.agents; + environment.launchDaemons = mapAttrs' toEnvironmentText cfg.daemons; }; } diff --git a/modules/system/write-text.nix b/modules/system/write-text.nix index 1fc97dd6..4ffc0818 100644 --- a/modules/system/write-text.nix +++ b/modules/system/write-text.nix @@ -1,8 +1,9 @@ { lib, mkTextDerivation }: +{ config, name, ... }: + with lib; -{ config, name, ... }: let sourceDrv = mkTextDerivation name config.text; @@ -16,8 +17,8 @@ in type = types.bool; default = true; description = '' - Whether this /etc file should be generated. This - option allows specific /etc files to be disabled. + Whether this file should be generated. + This option allows specific files to be disabled. ''; }; @@ -33,9 +34,7 @@ in type = types.str; default = name; description = '' - Name of symlink (relative to - /etc). Defaults to the attribute - name. + Name of symlink. Defaults to the attribute name. ''; };