Skip to content

Instantly share code, notes, and snippets.

@antifuchs
Created October 5, 2020 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antifuchs/4d751d182296e2382fc6d86d26e0c25e to your computer and use it in GitHub Desktop.
Save antifuchs/4d751d182296e2382fc6d86d26e0c25e to your computer and use it in GitHub Desktop.
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.homebrew;
caskAppdirStatement =
if (isNull cfg.cask_args.appdir)
then ""
else "cask_args appdir: '${cfg.cask_args.appdir}'";
masStatements = values: (concatMapStrings (value: "mas '${value.name}', id: ${toString value.id}\n") values);
statements = word: values: (concatMapStrings (value: "${word} '${value}'\n") values);
brewfile = pkgs.writeTextFile {
name = "Brewfile";
text = ''
${caskAppdirStatement}
${statements "tap" cfg.taps}
${statements "cask" cfg.casks}
${statements "brew" cfg.formulae}
${masStatements cfg.mas}
'';
};
in
{
options.homebrew = {
enable = mkEnableOption "Homebrew";
taps = mkOption {
description = "taps to retrieve formulae from";
type = with types; listOf str;
example = "homebrew/cask-fonts";
};
cask_args.appdir = mkOption {
description = "path for Mac OS application bundles";
type = with types; nullOr path;
default = null;
example = "/Applications";
};
casks = mkOption {
description = "casks to be installed";
type = with types; listOf str;
default = [ ];
example = "spotify";
};
mas = mkOption {
description = "Mac App Store apps to be installed.";
type = with types; listOf (submodule {
options = {
name = lib.mkOption { type = str; };
id = lib.mkOption { type = ints.unsigned; };
};
});
default = [ ];
};
formulae = mkOption {
description = "formulae to be installed";
type = with types; listOf str;
default = [ ];
example = "openscad";
};
};
config = mkIf cfg.enable {
homebrew.taps = [ "homebrew/bundle" ];
system.activationScripts.extraUserActivation.text = ''
PATH="/usr/local/bin:$PATH" HOMEBREW_NO_AUTO_UPDATE=1 brew bundle --no-lock --file="${brewfile}"
'';
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment