From b72293b4117052e5057a0382664f684c7004e75c Mon Sep 17 00:00:00 2001 From: "Frank Chiarulli Jr." Date: Sun, 15 Dec 2024 01:26:25 -0500 Subject: [PATCH] allow modifying display type of persistent-others --- modules/system/defaults/dock.nix | 48 +++++++++++++++++-- .../system-defaults-write/activate-user.txt | 20 ++++++++ tests/system-defaults-write.nix | 11 ++++- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/modules/system/defaults/dock.nix b/modules/system/defaults/dock.nix index bba0afb75..bafbbf352 100644 --- a/modules/system/defaults/dock.nix +++ b/modules/system/defaults/dock.nix @@ -5,6 +5,30 @@ with lib; let # Should only be used with options that previously used floats defined as strings. inherit (config.lib.defaults.types) floatWithDeprecationError; + + persistentOther = types.submodule { + options = { + path = lib.mkOption { + type = types.either types.path types.str; + description = "Path as either a path type or string"; + }; + arrangement = lib.mkOption { + type = types.nullOr types.int; + default = null; + description = "Arrangement value"; + }; + showas = lib.mkOption { + type = types.nullOr types.int; + default = null; + description = "Show-as value"; + }; + displayas = lib.mkOption { + type = types.nullOr types.int; + default = null; + description = "Display-as value"; + }; + }; + }; in { imports = [ (mkRenamedOptionModule [ "system" "defaults" "dock" "expose-group-by-app" ] [ "system" "defaults" "dock" "expose-group-apps" ]) @@ -141,16 +165,34 @@ in { }; system.defaults.dock.persistent-others = mkOption { - type = types.nullOr (types.listOf (types.either types.path types.str)); + type = types.nullOr (types.listOf (types.oneOf [ types.path types.str persistentOther ])); default = null; example = [ "~/Documents" "~/Downloads" ]; description = '' Persistent folders in the dock. ''; apply = value: - if !(isList value) + if !(lib.isList value) then value - else map (folder: { tile-data = { file-data = { _CFURLString = "file://" + folder; _CFURLStringType = 15; }; }; tile-type = if strings.hasInfix "." (last (splitString "/" folder)) then "file-tile" else "directory-tile"; }) value; + else map (folder: + let + folderPath = if builtins.isAttrs folder then toString folder.path else toString folder; + isSimplePath = !(builtins.isAttrs folder); + in { + tile-data = { + file-data = { + _CFURLString = "file://" + folderPath; + _CFURLStringType = 15; + }; + } // (if isSimplePath then {} else lib.filterAttrs (n: v: v != null) { + arrangement = folder.arrangement; + showas = folder.showas; + displayas = folder.displayas; + }); + tile-type = if lib.strings.hasInfix "." (lib.last (lib.splitString "/" folderPath)) + then "file-tile" + else "directory-tile"; + }) value; }; system.defaults.dock.scroll-to-open = mkOption { diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt index e09f689b3..2a6e37b90 100644 --- a/tests/fixtures/system-defaults-write/activate-user.txt +++ b/tests/fixtures/system-defaults-write/activate-user.txt @@ -307,6 +307,26 @@ defaults write com.apple.dock 'persistent-others' $'tile-type file-tile + + tile-data + + file-data + + _CFURLString + file://~/Applications + _CFURLStringType + 15 + + arrangement + 1 + displayas + 2 + showas + 3 + + tile-type + directory-tile + ' defaults write com.apple.dock 'scroll-to-open' $' diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index fae08de38..5a8522dfd 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -51,7 +51,16 @@ system.defaults.dock.autohide-delay = 0.24; system.defaults.dock.orientation = "left"; system.defaults.dock.persistent-apps = ["MyApp.app" "Cool.app"]; - system.defaults.dock.persistent-others = ["~/Documents" "~/Downloads/file.txt"]; + system.defaults.dock.persistent-others = [ + "~/Documents" + "~/Downloads/file.txt" + { + path = "~/Appications"; + showas = 1; + displayas = 2; + arrangement = 3; + } + ]; system.defaults.dock.scroll-to-open = false; system.defaults.finder.AppleShowAllFiles = true; system.defaults.finder.ShowStatusBar = true;