   "Add LAYER to the list which the value stored in HASH with key PKG."
   (let ((list (ht-get hash pkg)))
     (puthash pkg (add-to-list 'list layer t) hash)))
+
+(defun contribsys//add-excluded-packages (layer)
+  "Add excluded packages declared in LAYER."
+  (let ((excl-var (intern (format "%s-excluded-packages" (symbol-name layer)))))
+    (when (boundp excl-var)
+      (setq spacemacs-excluded-packages-from-layers
+            (append spacemacs-excluded-packages-from-layers
+                    (eval excl-var))))))
+
+(defsubst contribsys//filter-out-excluded-packages ()
+  "Remove excluded packages from the hash tables."
+  (mapc (lambda (h)
+          (dolist (x (ht-keys (eval h)))
+            (when (or (member x dotspacemacs-excluded-packages)
+                      (member x spacemacs-excluded-packages-from-layers))
+              (ht-remove (eval h) x))))
+        '(spacemacs-all-packages
+          spacemacs-all-pre-extensions
+          spacemacs-all-post-extensions)))
 
 (defun contribsys/read-packages-and-extensions ()
   "Load all packages and extensions declared in all layers and fill the

        (when (file-exists-p pkg-file)
          (load pkg-file)
          (dolist (pkg (eval (intern (format "%s-packages" (symbol-name sym)))))
            (unless (member pkg dotspacemacs-excluded-packages)
              (contribsys//add-layer-to-hash pkg sym spacemacs-all-packages))))
        ;; extensions
        (when (file-exists-p ext-file)
          (load ext-file)
          (dolist (pkg (eval (intern (format "%s-pre-extensions"
                                             (symbol-name sym)))))
            (unless (member pkg dotspacemacs-excluded-packages)
              (contribsys//add-layer-to-hash
               pkg sym spacemacs-all-pre-extensions)))
          (dolist (pkg (eval (intern (format "%s-post-extensions"
                                             (symbol-name sym)))))
            (unless (member pkg dotspacemacs-excluded-packages)
              (contribsys//add-layer-to-hash
               pkg sym spacemacs-all-post-extensions)))))))
  ;; number of chuncks for the loading screen
  (let ((total (+ (ht-size spacemacs-all-packages)
                  (ht-size spacemacs-all-pre-extensions)


(defun contribsys/discover-contrib-layers-in-dir (dir)
  "Fill the hash table `spacemacs-contrib-layer-paths' where the key is the
layer symbol and the value is its path for all layers found in directory DIR.

Also fill the list of excluded packages `spacemacs-excluded-packages-from-layers'
declared at the layer level."
  (message "Looking for contribution layers in %s" dir)
  (ignore-errors
    (let ((files (directory-files dir nil nil 'nosort))
          (filter-out (append spacemacs-contrib-categories '("." ".."))))
      (dolist (f files)
        (when (and (file-directory-p (concat dir f))
                   (not (member f filter-out)))
          (message "-> Discovered contribution layer: %s" f)
          (puthash (intern f) dir spacemacs-contrib-layer-paths))))))

(defun contribsys/load-layers ()
  "Load all declared layers."
