From 8180a824e41e381c2d0a7148effe06ce37a2a126 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 21 Nov 2024 15:18:31 -0600 Subject: [PATCH 1/3] dock: allow setting tile-types You can create spacer tiles in the dock by passing empty tile-data with specific tile-types --- modules/system/defaults/dock.nix | 12 ++++++++---- .../system-defaults-write/activate-user.txt | 16 ++++++++++++++++ tests/system-defaults-write.nix | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/modules/system/defaults/dock.nix b/modules/system/defaults/dock.nix index bba0afb75..8eaf5ca8d 100644 --- a/modules/system/defaults/dock.nix +++ b/modules/system/defaults/dock.nix @@ -134,10 +134,14 @@ in { description = '' Persistent applications in the dock. ''; - apply = value: - if !(isList value) - then value - else map (app: { tile-data = { file-data = { _CFURLString = app; _CFURLStringType = 0; }; }; }) value; + apply = + let + tileTypes = ["spacer-tile" "small-spacer-tile"]; + toSpecialTile = type: { tile-data = {}; tile-type = type; }; + toAppTile = cfurl: { tile-data = { file-data = { _CFURLString = cfurl; _CFURLStringType = 0; }; }; }; + toTile = s: if elem s tileTypes then toSpecialTile s else toAppTile s; + in + value: if isList value then map toTile value else value; }; system.defaults.dock.persistent-others = mkOption { diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt index eda375371..aa6050029 100644 --- a/tests/fixtures/system-defaults-write/activate-user.txt +++ b/tests/fixtures/system-defaults-write/activate-user.txt @@ -273,6 +273,22 @@ defaults write com.apple.dock 'persistent-apps' $' + + tile-data + + + + tile-type + small-spacer-tile + + + tile-data + + + + tile-type + spacer-tile + ' defaults write com.apple.dock 'persistent-others' $' diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index 0b8bc0300..3f69c0bd9 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -50,7 +50,7 @@ system.defaults.dock.appswitcher-all-displays = false; 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-apps = ["MyApp.app" "Cool.app" "small-spacer-tile" "spacer-tile"]; system.defaults.dock.persistent-others = ["~/Documents" "~/Downloads/file.txt"]; system.defaults.dock.scroll-to-open = false; system.defaults.finder.AppleShowAllFiles = true; From 53cdccf5d83758dde658db766524f7addbbbd5d6 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Tue, 17 Dec 2024 18:44:48 -0600 Subject: [PATCH 2/3] dock: refactor persistent-apps option --- modules/system/defaults/dock.nix | 65 +++++++++++++++++-- .../system-defaults-write/activate-user.txt | 30 ++++++++- tests/system-defaults-write.nix | 9 ++- 3 files changed, 94 insertions(+), 10 deletions(-) diff --git a/modules/system/defaults/dock.nix b/modules/system/defaults/dock.nix index 8eaf5ca8d..0c617e453 100644 --- a/modules/system/defaults/dock.nix +++ b/modules/system/defaults/dock.nix @@ -128,18 +128,69 @@ in { }; system.defaults.dock.persistent-apps = mkOption { - type = types.nullOr (types.listOf (types.either types.path types.str)); + type = let + taggedType = types.attrTag { + app = mkOption { + description = "An application to be added to the dock."; + type = types.submodule { + options.path = mkOption { + description = "Path to the application."; + type = types.str; + }; + }; + }; + spacer = mkOption { + description = "A spacer to be added to the dock. Can be small or regular size."; + type = types.submodule { + options.small = mkOption { + description = "Whether the spacer is small."; + type = types.bool; + default = false; + }; + }; + }; + folder = mkOption { + description = "A folder to be added to the dock."; + type = types.submodule { + options.path = mkOption { + description = "Path to the folder."; + type = types.str; + }; + }; + }; + }; + + simpleType = types.either types.str types.path; + toTagged = (path: {app = {inherit path;};}); + in + types.nullOr (types.listOf (types.coercedTo simpleType toTagged taggedType)); default = null; - example = [ "/Applications/Safari.app" "/System/Applications/Utilities/Terminal.app" ]; + example = [ + { app = { path = "/Applications/Safari.app"; }; } + { spacer = { small = false; }; } + { spacer = { small = true; }; } + { folder = { path = "/System/Applications/Utilities"; }; } + ]; description = '' - Persistent applications in the dock. + Persistent applications, spacers, and folders in the dock. ''; apply = let - tileTypes = ["spacer-tile" "small-spacer-tile"]; - toSpecialTile = type: { tile-data = {}; tile-type = type; }; - toAppTile = cfurl: { tile-data = { file-data = { _CFURLString = cfurl; _CFURLStringType = 0; }; }; }; - toTile = s: if elem s tileTypes then toSpecialTile s else toAppTile s; + toTile = item: if item ? app then { + tile-data.file-data = { + _CFURLString = item.app.path; + _CFURLStringType = 0; + }; + } else if item ? spacer then { + tile-data = { }; + tile-type = if item.spacer.small then "small-spacer-tile" else "spacer-tile"; + } else if item ? folder then { + tile-data.file-data = { + _CFURLString = "file://" + item.folder.path; + _CFURLStringType = 15; + }; + tile-type = if strings.hasInfix "." (last (splitString "/" item.folder.path)) then "file-tile" else "directory-tile"; + } else item; in value: if isList value then map toTile value else value; }; diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt index aa6050029..e348461af 100644 --- a/tests/fixtures/system-defaults-write/activate-user.txt +++ b/tests/fixtures/system-defaults-write/activate-user.txt @@ -255,7 +255,7 @@ defaults write com.apple.dock 'persistent-apps' $'file-data _CFURLString - MyApp.app + /Applications/MyApp.app _CFURLStringType 0 @@ -267,7 +267,19 @@ defaults write com.apple.dock 'persistent-apps' $'file-data _CFURLString - Cool.app + /Applications/MyApp.app + _CFURLStringType + 0 + + + + + tile-data + + file-data + + _CFURLString + /Applications/Cool.app _CFURLStringType 0 @@ -289,6 +301,20 @@ defaults write com.apple.dock 'persistent-apps' $'tile-type spacer-tile + + tile-data + + file-data + + _CFURLString + file:///Applications/Utilities + _CFURLStringType + 15 + + + tile-type + directory-tile + ' defaults write com.apple.dock 'persistent-others' $' diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index 3f69c0bd9..8d57fbd0e 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -50,7 +50,14 @@ system.defaults.dock.appswitcher-all-displays = false; system.defaults.dock.autohide-delay = 0.24; system.defaults.dock.orientation = "left"; - system.defaults.dock.persistent-apps = ["MyApp.app" "Cool.app" "small-spacer-tile" "spacer-tile"]; + system.defaults.dock.persistent-apps = [ + "/Applications/MyApp.app" + { app = { path = "/Applications/MyApp.app"; }; } + { app = { path = "/Applications/Cool.app"; }; } + { spacer = { small = true; }; } + { spacer = { small = false; }; } + { folder = { path = "/Applications/Utilities"; }; } + ]; system.defaults.dock.persistent-others = ["~/Documents" "~/Downloads/file.txt"]; system.defaults.dock.scroll-to-open = false; system.defaults.finder.AppleShowAllFiles = true; From 48a6b5a9e6385fad03e95614c01a5b6438253709 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Tue, 7 Jan 2025 21:09:00 -0600 Subject: [PATCH 3/3] dock: refactor persistent-apps option --- modules/system/defaults/dock.nix | 26 ++++++------------- .../system-defaults-write/activate-user.txt | 12 --------- tests/system-defaults-write.nix | 7 +++-- 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/modules/system/defaults/dock.nix b/modules/system/defaults/dock.nix index 0c617e453..048f0bb01 100644 --- a/modules/system/defaults/dock.nix +++ b/modules/system/defaults/dock.nix @@ -132,12 +132,7 @@ in { taggedType = types.attrTag { app = mkOption { description = "An application to be added to the dock."; - type = types.submodule { - options.path = mkOption { - description = "Path to the application."; - type = types.str; - }; - }; + type = types.str; }; spacer = mkOption { description = "A spacer to be added to the dock. Can be small or regular size."; @@ -151,25 +146,20 @@ in { }; folder = mkOption { description = "A folder to be added to the dock."; - type = types.submodule { - options.path = mkOption { - description = "Path to the folder."; - type = types.str; - }; - }; + type = types.str; }; }; simpleType = types.either types.str types.path; - toTagged = (path: {app = {inherit path;};}); + toTagged = path: { app = path; }; in types.nullOr (types.listOf (types.coercedTo simpleType toTagged taggedType)); default = null; example = [ - { app = { path = "/Applications/Safari.app"; }; } + { app = "/Applications/Safari.app"; } { spacer = { small = false; }; } { spacer = { small = true; }; } - { folder = { path = "/System/Applications/Utilities"; }; } + { folder = "/System/Applications/Utilities"; } ]; description = '' Persistent applications, spacers, and folders in the dock. @@ -178,7 +168,7 @@ in { let toTile = item: if item ? app then { tile-data.file-data = { - _CFURLString = item.app.path; + _CFURLString = item.app; _CFURLStringType = 0; }; } else if item ? spacer then { @@ -186,10 +176,10 @@ in { tile-type = if item.spacer.small then "small-spacer-tile" else "spacer-tile"; } else if item ? folder then { tile-data.file-data = { - _CFURLString = "file://" + item.folder.path; + _CFURLString = "file://" + item.folder; _CFURLStringType = 15; }; - tile-type = if strings.hasInfix "." (last (splitString "/" item.folder.path)) then "file-tile" else "directory-tile"; + tile-type = if strings.hasInfix "." (last (splitString "/" item.folder)) then "file-tile" else "directory-tile"; } else item; in value: if isList value then map toTile value else value; diff --git a/tests/fixtures/system-defaults-write/activate-user.txt b/tests/fixtures/system-defaults-write/activate-user.txt index e348461af..1574c4838 100644 --- a/tests/fixtures/system-defaults-write/activate-user.txt +++ b/tests/fixtures/system-defaults-write/activate-user.txt @@ -261,18 +261,6 @@ defaults write com.apple.dock 'persistent-apps' $' - - tile-data - - file-data - - _CFURLString - /Applications/MyApp.app - _CFURLStringType - 0 - - - tile-data diff --git a/tests/system-defaults-write.nix b/tests/system-defaults-write.nix index 8d57fbd0e..86bd82202 100644 --- a/tests/system-defaults-write.nix +++ b/tests/system-defaults-write.nix @@ -51,12 +51,11 @@ system.defaults.dock.autohide-delay = 0.24; system.defaults.dock.orientation = "left"; system.defaults.dock.persistent-apps = [ - "/Applications/MyApp.app" - { app = { path = "/Applications/MyApp.app"; }; } - { app = { path = "/Applications/Cool.app"; }; } + "/Applications/MyApp.app" + { app = "/Applications/Cool.app"; } { spacer = { small = true; }; } { spacer = { small = false; }; } - { folder = { path = "/Applications/Utilities"; }; } + { folder = "/Applications/Utilities"; } ]; system.defaults.dock.persistent-others = ["~/Documents" "~/Downloads/file.txt"]; system.defaults.dock.scroll-to-open = false;