summaryrefslogtreecommitdiff
path: root/tests/homebrew.nix
blob: d7fdeabc730a2e6e12f940ebc2a73b73b09c4881 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{ config, lib, ... }:

let
  mkTest = filter: result: ''
    if ! echo "$bf" | grep -F '${filter}' | grep -F '${result}' > /dev/null; then
      echo Expected:
      echo '${result}'
      echo Actual:
      echo "$bf" | grep -F '${filter}'
      exit 1
    fi
  '';
in

{
  homebrew.enable = true;

  # Examples taken from https://github.com/Homebrew/homebrew-bundle
  homebrew.taps = [
    "homebrew/cask"
    {
      name = "user/tap-repo1";
      clone_target = "https://user@bitbucket.org/user/homebrew-tap-repo1.git";
    }
    {
      name = "user/tap-repo2";
      clone_target = "https://user@bitbucket.org/user/homebrew-tap-repo2.git";
      force_auto_update = true;
    }
  ];

  homebrew.caskArgs = {
    appdir = "~/Applications";
    require_sha = true;
  };

  homebrew.brews = [
    "imagemagick"
    {
      name = "denji/nginx/nginx-full";
      args = [ "with-rmtp" ];
      restart_service = "changed";
    }
    {
      name = "mysql@5.6";
      restart_service = true;
      link = true;
      conflicts_with = [ "mysql" ];
    }
  ];

  homebrew.casks = [
    "google-chrome"
    {
      name = "firefox";
      args = { appdir = "~/my-apps/Applications"; };
    }
    {
      name = "opera";
      greedy = true;
    }
  ];

  homebrew.masApps = {
    "1Password for Safari" = 1569813296;
    Xcode = 497799835;
  };

  homebrew.whalebrews = [
    "whalebrew/wget"
  ];

  test = ''
    bf=${lib.escapeShellArg config.homebrew.brewfile}

    echo "checking tap entries in Brewfile" >&2
    ${mkTest "homebrew/cask" ''tap "homebrew/cask"''}
    ${mkTest "user/tap-repo1" ''tap "user/tap-repo1", "https://user@bitbucket.org/user/homebrew-tap-repo1.git"''}
    ${mkTest "user/tap-repo2" ''tap "user/tap-repo2", "https://user@bitbucket.org/user/homebrew-tap-repo2.git", force_auto_update: true''}

    echo "checking cask_args entry in Brewfile" >&2
    ${mkTest "cask_args" ''cask_args appdir: "~/Applications", require_sha: true''}

    echo "checking brew entries in Brewfile" >&2
    ${mkTest "imagemagick" ''brew "imagemagick"''}
    ${mkTest "denji/nginx/nginx-full" ''brew "denji/nginx/nginx-full", args: ["with-rmtp"], restart_service: :changed''}
    ${mkTest "mysql@5.6" ''brew "mysql@5.6", conflicts_with: ["mysql"], link: true, restart_service: true''}

    echo "checking cask entries in Brewfile" >&2
    ${mkTest "google-chrome" ''cask "google-chrome"''}
    ${mkTest "firefox" ''cask "firefox", args: { appdir: "~/my-apps/Applications" }''}
    ${mkTest "opera" ''cask "opera", greedy: true''}

    echo "checking mas entries in Brewfile" >&2
    ${mkTest "1Password for Safari" ''mas "1Password for Safari", id: 1569813296''}
    ${mkTest "Xcode" ''mas "Xcode", id: 497799835''}

    echo "checking whalebrew entries in Brewfile" >&2
    ${mkTest "whalebrew/wget" ''whalebrew "whalebrew/wget"''}
  '';
}