diff options
| author | Malo Bourgon <mbourgon@gmail.com> | 2020-12-17 14:42:07 -0800 |
|---|---|---|
| committer | Malo Bourgon <mbourgon@gmail.com> | 2020-12-17 14:42:07 -0800 |
| commit | 9961b72463f0f0ba60f435424117d8ac98e70e8d (patch) | |
| tree | 4391d5efe23bd24c6f821bf1c9191e9d556958f8 /modules/homebrew.nix | |
| parent | e1425db70d27980293623675af0ca93431edec95 (diff) | |
Make better use of optional(s) functions in homebrew module
Diffstat (limited to 'modules/homebrew.nix')
| -rw-r--r-- | modules/homebrew.nix | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/modules/homebrew.nix b/modules/homebrew.nix index 2d142b0..f67945f 100644 --- a/modules/homebrew.nix +++ b/modules/homebrew.nix @@ -7,32 +7,30 @@ with lib; let cfg = config.homebrew; - brewfileSection = heading: type: entries: - if entries != [] then - "# ${heading}\n" + (concatMapStrings (name: "${type} \"${name}\"\n") entries) + "\n" - else ""; - - masBrewfileSection = entries: - if entries != {} then - "# Mac App Store apps\n" + - concatStringsSep "\n" (mapAttrsToList (name: id: ''mas "${name}", id: ${toString id}'') entries) + - "\n" - else ""; + brewfileSection = heading: type: entries: optionalString (entries != []) + "# ${heading}\n" + (concatMapStrings (name: "${type} \"${name}\"\n") entries) + "\n"; + + masBrewfileSection = entries: optionalString (entries != {}) ( + "# Mac App Store apps\n" + + concatStringsSep "\n" (mapAttrsToList (name: id: ''mas "${name}", id: ${toString id}'') entries) + + "\n" + ); brewfile = pkgs.writeText "Brewfile" ( - (brewfileSection "Taps" "tap" cfg.taps) + - (brewfileSection "Brews" "brew" cfg.brews) + - (brewfileSection "Casks" "cask" cfg.casks) + - (masBrewfileSection cfg.masApps) + - (brewfileSection "Docker contrainers" "whalebrew" cfg.whalebrews) + - (if cfg.extraConfig != "" then "# Extra config\n" + cfg.extraConfig else "") + brewfileSection "Taps" "tap" cfg.taps + + brewfileSection "Brews" "brew" cfg.brews + + brewfileSection "Casks" "cask" cfg.casks + + masBrewfileSection cfg.masApps + + brewfileSection "Docker contrainers" "whalebrew" cfg.whalebrews + + optionalString (cfg.extraConfig != "") ("# Extra config\n" + cfg.extraConfig) ); - brew-bundle-command = - (if cfg.autoUpdate then "" else "HOMEBREW_NO_AUTO_UPDATE=1 ") + - "brew bundle --file='${brewfile}' --no-lock" + - (if cfg.cleanup == "uninstall" || cfg.cleanup == "zap" then " --cleanup" else "") + - (if cfg.cleanup == "zap" then " --zap" else ""); + brew-bundle-command = concatStringsSep " " ( + optional (!cfg.autoUpdate) "HOMEBREW_NO_AUTO_UPDATE=1" ++ + [ "brew bundle --file='${brewfile}' --no-lock" ] ++ + optional (cfg.cleanup == "uninstall" || cfg.cleanup == "zap") "--cleanup" ++ + optional (cfg.cleanup == "zap") "--zap" + ); in @@ -211,8 +209,8 @@ in optional (cfg.whalebrews != []) "whalebrew"; environment.variables = mkIf cfg.enable ( - (if cfg.userConfig.brewfile then { HOMEBREW_BUNDLE_FILE = "${brewfile}"; } else {}) // - (if cfg.userConfig.noLock then { HOMEBREW_BUNDLE_NO_LOCK = "1"; } else {}) + optionalAttrs cfg.userConfig.brewfile { HOMEBREW_BUNDLE_FILE = "${brewfile}"; } // + optionalAttrs cfg.userConfig.noLock { HOMEBREW_BUNDLE_NO_LOCK = "1"; } ); system.activationScripts.homebrew.text = mkIf cfg.enable '' |
