Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

targets/darwin: add more options for configuring macOS #1753

Merged
merged 5 commits into from
Feb 3, 2021

Conversation

midchildan
Copy link
Contributor

Description

This adds the following new options:

  • targets.darwin.defaults

    This adds options for configuring macOS through the defaults(1) system. This option can be used to manipulate a vast majority of user settings for macOS and its applications.

    This is implemented using freeform modules and includes additional descriptions and type information for some useful options.

  • targets.darwin.keybindings

    This adds options for configuring the default keybindings for macOS text fields.

  • targets.darwin.search

    This adds options for configuring the default search engine for macOS.

Checklist

  • Change is backwards compatible.

  • Code formatted with ./format.

  • Code tested through nix-shell --pure tests -A run.all.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

@midchildan midchildan requested a review from rycee as a code owner January 28, 2021 15:41
@berbiche
Copy link
Member

Are the feature implemented here overlapping with Nix Darwin?

@midchildan
Copy link
Contributor Author

midchildan commented Jan 28, 2021

Perhaps yes, though I'm not aware of the specifics of what nix-darwin provides. The features introduced here are solely focused on settings for the current user, so I believe this falls within the scope of Home Manager.

targets.darwin.defaults in particular is the macOS equivalent of the dconf module and would be useful as a base to configure macOS applications.

@midchildan
Copy link
Contributor Author

midchildan commented Jan 29, 2021

I've now added another new option:

* targets.darwin.defaultsSchema:

This option takes a list of modules and allows users to specify additional descriptions, type information, and default values for individual options in targets.darwin.defaults.

reverted

Copy link
Member

@berbiche berbiche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution

modules/targets/darwin/default.nix Outdated Show resolved Hide resolved
modules/targets/darwin/default.nix Outdated Show resolved Hide resolved
modules/targets/darwin/keybindings.nix Outdated Show resolved Hide resolved
modules/modules.nix Show resolved Hide resolved
modules/targets/darwin/options.nix Outdated Show resolved Hide resolved
This option would make it possible to add additional descriptions, type
infomation, and default values for individual options in
'targets.darwin.defaultSchema'.
modules/targets/darwin/keybindings.nix Outdated Show resolved Hide resolved
modules/targets/darwin/search.nix Outdated Show resolved Hide resolved
modules/targets/darwin/options.nix Outdated Show resolved Hide resolved
modules/targets/darwin/options.nix Outdated Show resolved Hide resolved
modules/targets/darwin/options.nix Outdated Show resolved Hide resolved
modules/targets/darwin/search.nix Show resolved Hide resolved
modules/targets/darwin/default.nix Outdated Show resolved Hide resolved
modules/targets/darwin/default.nix Outdated Show resolved Hide resolved
@berbiche
Copy link
Member

berbiche commented Feb 3, 2021

Few things left to change and it's good to go!

Comment on lines +8 to +20
toDefaultsFile = domain: attrs:
pkgs.writeText "${domain}.plist" (lib.generators.toPlist { } attrs);

toActivationCmd = domain: attrs:
"$DRY_RUN_CMD defaults import ${escapeShellArg domain} ${
toDefaultsFile domain attrs
}";

nonNullDefaults =
mapAttrs (domain: attrs: (filterAttrs (n: v: v != null) attrs))
cfg.defaults;
writableDefaults = filterAttrs (domain: attrs: attrs != { }) nonNullDefaults;
activationCmds = mapAttrsToList toActivationCmd writableDefaults;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the logic here a little so that it won't perform a defaults import when the target domain includes only null values. So for example, when a user has the following configuration, it won't perform a defaults import com.apple.desktopservices:

{ "com.apple.desktopservices".DSDontWriteNetworkStores = null; }

The previous behavior should be harmless, but it might confuse users running Home Manager with verbose output.

@berbiche berbiche merged commit 9dad146 into nix-community:master Feb 3, 2021
@berbiche
Copy link
Member

berbiche commented Feb 3, 2021

Thanks for the contribution!

@midchildan midchildan deleted the feat/darwin branch February 4, 2021 01:39
midchildan added a commit to midchildan/dotfiles that referenced this pull request Feb 4, 2021
@bphenriques
Copy link

bphenriques commented Feb 15, 2021

Perhaps yes, though I'm not aware of the specifics of what nix-darwin provides. The features introduced here are solely focused on settings for the current user, so I believe this falls within the scope of Home Manager.

I kind off hoped that this would be defined nix-darwin instead to avoid further fragmentation. I see home-manager as a way to define packages and its dotfiles and nix-darwin to set macOS specific settings. Nix is already harder as it is and having this in both places doesn't help, both in the user's perspective as it generates confusion and in the dev's perspective as we now have have to maintain both places if want to have some level of feature parity and consistency in the nix ecosystem. The same can be said in nix-darwin's repo that attempts to do some of the work already being done by home-manager 😆 😕

Note that this is an opinion from a recent user's point of view.

Edit: This is more of my take on nix-darwin/home-manager interactions and not specific to this PR 🙂
Edit2: Asking this on the discord channel as well as this is comment's scope is bigger than this PR 🤷‍♂️ : https://discord.com/channels/568306982717751326/741347063077535874/810859238850953236

malte-v pushed a commit to malte-v/home-manager that referenced this pull request Feb 24, 2021
…#1753)

Add new options Darwin options:

- `targets.darwin.defaults`
  This adds options for configuring macOS through the `defaults(1)` system.
  This option can be used to manipulate a vast majority of user settings for macOS
  and its applications.

  This is implemented using freeform modules and includes additional descriptions
  and type information for some useful options.

- `targets.darwin.keybindings`
  This adds options for configuring the default keybindings for macOS text fields.

- `targets.darwin.search`
  This adds options for configuring the default search engine for macOS.
aakropotkin pushed a commit to aakropotkin/home-manager that referenced this pull request Feb 28, 2021
…#1753)

Add new options Darwin options:

- `targets.darwin.defaults`
  This adds options for configuring macOS through the `defaults(1)` system.
  This option can be used to manipulate a vast majority of user settings for macOS
  and its applications.

  This is implemented using freeform modules and includes additional descriptions
  and type information for some useful options.

- `targets.darwin.keybindings`
  This adds options for configuring the default keybindings for macOS text fields.

- `targets.darwin.search`
  This adds options for configuring the default search engine for macOS.
cab404 pushed a commit to cab404/home-manager that referenced this pull request Apr 23, 2021
…#1753)

Add new options Darwin options:

- `targets.darwin.defaults`
  This adds options for configuring macOS through the `defaults(1)` system.
  This option can be used to manipulate a vast majority of user settings for macOS
  and its applications.

  This is implemented using freeform modules and includes additional descriptions
  and type information for some useful options.

- `targets.darwin.keybindings`
  This adds options for configuring the default keybindings for macOS text fields.

- `targets.darwin.search`
  This adds options for configuring the default search engine for macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants