{ config, pkgs, lib, ... }: with lib; let cfg = config.local.dock; stdenv = pkgs.stdenv; in { options = { local.dock.enable = mkOption { description = "Enable dock"; default = stdenv.isDarwin; example = false; }; local.dock.entries = mkOption { description = "Entries on the Dock"; default = [ ]; type = with types; listOf (submodule { options = { url = lib.mkOption { type = str; }; path = lib.mkOption { type = str; }; section = lib.mkOption { type = str; default = "apps"; }; options = lib.mkOption { type = str; default = ""; }; }; }); readOnly = true; }; }; config = mkIf (cfg.enable) ( let dockutil = (import ./dockutil.nix); du = "env PYTHONIOENCODING=utf-8 ${dockutil}/bin/dockutil"; wantURIs = concatMapStrings (entry: "${entry.url}\n") cfg.entries; createEntries = concatMapStrings (entry: "${du} --no-restart --add '${entry.path}' --section ${entry.section} ${entry.options}\n") cfg.entries; in { system.activationScripts.postUserActivation.text = '' echo >&2 "Setting up persistent dock items..." haveURIs="$(${du} --list | ${pkgs.coreutils}/bin/cut -f2)" if ! diff -wu <(echo -n "$haveURIs") <(echo -n '${wantURIs}') >&2 ; then echo >&2 "Resetting Dock." ${du} --no-restart --remove all ${createEntries} killall Dock else echo >&2 "Dock is how we want it." fi ''; } ); }