{
  config,
  pkgs,
  lib,
  home-manager,
  ...
}:

let
  user = "olaf";
  # Define the content of your file as a derivation
  myEmacsLauncher = pkgs.writeScript "emacs-launcher.command" ''
    #!/bin/sh
    emacsclient -c -n &
  '';
  sharedFiles = import ../shared/files.nix { inherit config pkgs; };
  additionalFiles = import ./files.nix { inherit user config pkgs; };
in
{
  imports = [
    ./dock
  ];

  # It me
  users.users.${user} = {
    name = "${user}";
    home = "/Users/${user}";
    isHidden = false;
    shell = pkgs.zsh;
  };

  homebrew = {
    enable = true;
    casks = pkgs.callPackage ./casks.nix { };
    # onActivation.cleanup = "uninstall";

    # These app IDs are from using the mas CLI app
    # mas = mac app store
    # https://github.com/mas-cli/mas
    #
    # $ nix shell nixpkgs#mas
    # $ mas search <app name>
    #
    # If you have previously added these apps to your Mac App Store profile (but not installed them on this system),
    # you may receive an error message "Redownload Unavailable with This Apple ID".
    # This message is safe to ignore. (https://github.com/dustinlyons/nixos-config/issues/83)

    masApps = {
      "wireguard" = 1451685025;
    };
  };

  # Enable home-manager
  home-manager = {
    useGlobalPkgs = true;
    users.${user} =
      {
        pkgs,
        config,
        lib,
        ...
      }:
      {
        home = {
          enableNixpkgsReleaseCheck = false;
          packages = pkgs.callPackage ./packages.nix { };
          file = lib.mkMerge [
            sharedFiles
            additionalFiles
            { "emacs-launcher.command".source = myEmacsLauncher; }
          ];

          stateVersion = "23.11";
        };
        programs = { } // import ../shared/home-manager.nix { inherit config pkgs lib; };

        # Marked broken Oct 20, 2022 check later to remove this
        # https://github.com/nix-community/home-manager/issues/3344
        manual.manpages.enable = false;
      };
  };

  # Fully declarative dock using the latest from Nix Store
  local = {
    dock = {
      enable = true;
      entries = [
        { path = "/System/Applications/Mail.app/"; }
        { path = "/Applications/MailMate.app/"; }
        { path = "/Applications/1Password.app/"; }
        { path = "/Applications/Firefox.app/"; }
        { path = "/Applications/Slack.app/"; }
        {
          path = "/Applications/zoom.us.app/";
          options = " -l Zooom";
        }
        { path = "/System/Applications/Messages.app/"; }

        { path = "/Applications/iTerm.app/"; }
        { path = "/Applications/Fantastical.app/"; }
        #        { path = "${pkgs.alacritty}/Applications/Alacritty.app/"; }
        { path = "/Applications/Spotify.app/"; }
        { path = "/Applications/Safari.app/"; }
        { path = "/System/Applications/Photos.app/"; }
        { path = "/System/Applications/System Settings.app/"; }
        { path = "/Applications/Signal.app/"; }
        { path = "/Applications/WhatsApp.app/"; }

        {
          path = "/Applications/Jellyfin Media Player.app/";
          options = "-l Jellyfin";
        }
        { path = "/Applications/Visual Studio Code.app/"; }
        { path = "/Applications//Home Assistant.app/"; }
        { path = "/Applications//Remarkable.app/"; }
        { path = "/Applications/LibreOffice.app/"; }
        { path = "/Applications/Microsoft Word.app/"; }
        { path = "/Applications/Microsoft Powerpoint.app/"; }
        { path = "/Applications/Microsoft Teams.app/"; }
        { path = "/System/Applications/Utilities/Screen Sharing.app/"; }
        {
          path = "/Applications/";
          section = "others";
          options = "--sort name --view grid --display stack";
        }
        {
          path = toString myEmacsLauncher;
          section = "others";
          options = "-l EmacsLauncher";
        }
        {
          path = "${config.users.users.${user}.home}/.local/share/";
          section = "others";
          options = "--sort name --view grid --display folder";
        }
        {
          #          path = "${config.users.users.${user}.home}/.local/share/downloads";
          path = "${config.users.users.${user}.home}/Downloads";
          section = "others";
          options = "--sort name --view grid --display stack";
        }

      ];
    };
  };
}