# V2 and spacemacs

**URL:** <https://org-roam.discourse.group/t/v2-and-spacemacs/1676>\
**Category:** Requests\
**Created:** [June 8, 2021, 1:53am UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676 "2021-06-08T01:53:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnohz](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gnohz/32/803_2.png) [@gnohz](https://org-roam.discourse.group/u/gnohz)\
**Post date:** [June 8, 2021, 1:53am UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/1 "2021-06-08T01:53:39Z")

</div>

I am just wondering if anyone knows how to make v2 to work in spacemacs?  
Thanks.

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [June 8, 2021, 6:37am UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/2 "2021-06-08T06:37:59Z")

</div>

Searching this Discourse with “Spacemacs v2” hits two other items. One is about installation, the other, configuration. You might like to try this yourself and see they help you.

---

<div class="post-metadata">

**Author:** ![nickanderson](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nickanderson/32/753_2.png) [@nickanderson](https://org-roam.discourse.group/u/nickanderson)\
**Post date:** [June 16, 2021, 4:51am UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/3 "2021-06-16T04:51:56Z")

</div>

I use this [The Org-roam v2 Great Migration - #19 by nickanderson](https://org-roam.discourse.group/t/the-org-roam-v2-great-migration/1505/19) with succuss

---

<div class="post-metadata">

**Author:** ![gnohz](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gnohz/32/803_2.png) [@gnohz](https://org-roam.discourse.group/u/gnohz)\
**Post date:** [July 20, 2021, 3:47pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/4 "2021-07-20T15:47:03Z")

</div>

After several attempts, I finally make org-roam (currently v2) in Spacemacs work by creating a private layer.

First off, Spacemacs’ org layer includes the org-roam package, so we need to exclude it from org layer in dotspacemacs-configuration-layers:

```auto
(org :packeges (not org-roam))

```

Then M-x configuration-layer/create-layer, and follow the instruction to name the layer, e.g. org-roam. This will create a layer folder with a file named “packages.el”.

Delete the content in the packages.el, and paste the following (my org-roam layer):

```auto
(defconst org-roam-packages
  '(
    (org-roam :location
              (recipe :fetcher github :repo "org-roam/org-roam"))
    (org-roam-bibtex :location
                     (recipe :fetcher github :repo "org-roam/org-roam-bibtex"))))

(defun org-roam/init-org-roam ()
  (use-package org-roam
    :defer t
    :hook (after-init . org-roam-mode)
    :init
    (setq org-roam-v2-ack t)
    :custom
    (org-roam-directory "~/org/roam") ;; please change it to your path
    :config
    (progn
      (spacemacs/declare-prefix "aor" "org-roam")
      (spacemacs/declare-prefix "aord" "org-roam-dailies")
      (spacemacs/declare-prefix "aort" "org-roam-tags")
      (spacemacs/set-leader-keys
        "aordy" 'org-roam-dailies-goto-yesterday
        "aordt" 'org-roam-dailies-goto-today
        "aordT" 'org-roam-dailies-goto-tomorrow
        "aordd" 'org-roam-dailies-goto-date
        "aor/" 'org-roam-node-find
        "aorc" 'org-roam-capture
        ;; "aorg" 'org-roam-graph
        "aori" 'org-roam-node-insert
        "aorl" 'org-roam-buffer-toggle
        "aorta" 'org-roam-tag-add
        "aortd" 'org-roam-tag-delete
        "aora" 'org-roam-alias-add)

      (spacemacs/declare-prefix-for-mode 'org-mode "mr" "org-roam")
      (spacemacs/declare-prefix-for-mode 'org-mode "mrd" "org-roam-dailies")
      (spacemacs/declare-prefix-for-mode 'org-mode "mrt" "org-roam-tags")
      (spacemacs/set-leader-keys-for-major-mode 'org-mode
        "rb" 'org-roam-switch-to-buffer
        "rdy" 'org-roam-dailies-goto-yesterday
        "rdt" 'org-roam-dailies-goto-today
        "rdT" 'org-roam-dailies-goto-tomorrow
        "rdd" 'org-roam-dailies-goto-date
        "r/" 'org-roam-node-find
        "rc" 'org-roam-capture
        ;; "rg" 'org-roam-graph
        "ri" 'org-roam-node-insert
        "rl" 'org-roam-buffer-toggle
        "rta" 'org-roam-tag-add
        "rtd" 'org-roam-tag-delete
        "ra" 'org-roam-alias-add))
    (setq org-roam-mode-sections
          (list #'org-roam-backlinks-insert-section
                #'org-roam-reflinks-insert-section
                ))
    (setq org-roam-file-extensions '("org"))
    (org-roam-setup)

    ;; templates
    (setq org-roam-capture-templates
          '(
            ("d" "default" plain
             "%?"
             :if-new (file+head "${slug}.org"
                                "#+title: ${title}\n")
             :immediate-finish t
             :unnarrowed t)
            ("r" "ref" plain
             "%?"
             :if-new (file+head "./ref_notes/${slug}.org"
                                "#+title: ${title}\n")
             :unnarrowed t)))
    (setq org-roam-dailies-directory "daily/")
    (setq org-roam-dailies-capture-templates
          '(("d" "default" entry
             "* %?"
             :if-new (file+head "%<%Y-%m-%d>.org"
                                "#+title: %<%Y-%m-%d>\n"))))
))

(defun org-roam/init-org-roam-bibtex ()
  (use-package org-roam-bibtex
    :after org-roam
    :hook (org-roam-mode . org-roam-bibtex-mode)
    :bind (:map org-mode-map
                (("C-c n a" . orb-note-actions)))))

```

Let me know if this works.

---

<div class="post-metadata">

**Author:** ![Gp741](https://avatars.discourse-cdn.com/v4/letter/g/77aa72/32.png) [@Gp741](https://org-roam.discourse.group/u/Gp741)\
**Post date:** [August 15, 2021, 12:05pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/5 "2021-08-15T12:05:18Z")

</div>

Thank you very much indeed gnohz!

I spent hours without success in the configuration until I came across your post. I configured org-roam totally manually with use-package instead of creating a private layer, but org-roam was mysteriously not loaded until I added this line of code:

> [@gnohz](#):
>
> `(org :packeges (not org-roam))`

I did not know that Spacemacs’ org layer includes the org-roam package, so we need to exclude it from org layer; maybe you discovered this by digging into the source code.

Also the suggested configuration for org-roam in the official Spacemacs documentation ([4.16. Org-roam support](https://develop.spacemacs.org/layers/+emacs/org/README.html#:~:text=4.16.-,Org-roam%20support,-%C2%B6) ) was a disaster for me, I was even unable to run emacs in daemon mode. By the way, by configuring org-roam manually with use-package, everything is working fine so far.

For the benefit of other users, I share my .spacemacs conf, with org-roam-ui also already configured and working:

```auto
(defun dotspacemacs/layers ()
  "Layer configuration:
This function should only modify configuration layer settings."
  (setq-default
     (org :packages (not org-roam))
     )
   dotspacemacs-additional-packages '(
                                      (org-roam)
                                      ( simple-httpd )
                                      ( websocket )
                                      (org-roam-ui :location (recipe :fetcher github :repo "org-roam/org-roam-ui" :branch "main" :files ("*.el" "out")))
                                      )
))

(defun dotspacemacs/user-config ()

(require 'org)
(setq org-enable-roam-support t)

(use-package org-roam
  :after org
  :ensure t
  :init (setq org-roam-v2-ack t) ;; Acknowledge V2 upgrade
  :custom
  (org-roam-directory (file-truename "~/orgRoam") )
  (org-roam-completion-everywhere t)
  :config
  (org-roam-db-autosync-mode)
  ;; If using org-roam-protocol
  ;;(require 'org-roam-protocol)
  (org-roam-setup)
  :bind (("C-c n f" . org-roam-node-find)
         ("C-c n g" . org-roam-graph)
         ("C-c n r" . org-roam-node-random)
         (:map org-mode-map
               (("C-c n i" . org-roam-node-insert)
                ("C-c n o" . org-id-get-create)
                ("C-c n t" . org-roam-tag-add)
                ("C-c n a" . org-roam-alias-add)
                ("C-c n l" . org-roam-buffer-toggle))))
  )
(use-package org-roam-ui
  :after org-roam
  ;;:hook (after-init . org-roam-ui-mode)
  :config
  (setq org-roam-ui-sync-theme t
        org-roam-ui-follow t
        org-roam-ui-update-on-save t
        org-roam-ui-open-on-start t))
)

```

PS: do not forget to check that you have the path to gcc.exe and git.exe in your emacs exe-path variable.

---

<div class="post-metadata">

**Author:** ![gnohz](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gnohz/32/803_2.png) [@gnohz](https://org-roam.discourse.group/u/gnohz)\
**Post date:** [August 15, 2021, 1:34pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/6 "2021-08-15T13:34:00Z")

</div>

My pleasure. Yes, I tried it very hard too.

If we didn’t exclude the org-roam package from the org layer in Spacemacs, we will have initiation problem, specifically, that there will be two “init” by use-package. If you read the Spacemacs documentation, you will see it mentions “init”, “pre-init”, and “post-init”.

---

<div class="post-metadata">

**Author:** ![doubleloop](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/doubleloop/32/99_2.png) [@doubleloop](https://org-roam.discourse.group/u/doubleloop)\
**Post date:** [August 17, 2021, 5:48pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/7 "2021-08-17T17:48:59Z")

</div>

Out of interest, what’s the problem with the built-in org-roam layer in Spacemacs? It has recently been updated to work with v2, and seems to be working fine for me.

---

<div class="post-metadata">

**Author:** ![gnohz](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gnohz/32/803_2.png) [@gnohz](https://org-roam.discourse.group/u/gnohz)\
**Post date:** [August 17, 2021, 6:32pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/8 "2021-08-17T18:32:22Z")

</div>

Not checked recently, but it did not include orb before.

---

<div class="post-metadata">

**Author:** ![gnohz](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gnohz/32/803_2.png) [@gnohz](https://org-roam.discourse.group/u/gnohz)\
**Post date:** [August 17, 2021, 6:34pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/9 "2021-08-17T18:34:53Z")

</div>

There are some file/folder re-structure in the org-roam repository. For example, they put org-dailies into “extensions”, so accordingly, I changed the org-roam location as follows:

```auto
(org-roam :location
              (recipe :fetcher github
                      :repo "org-roam/org-roam"
                      :files (:defaults "extensions/*"))
              )

```

You might need to manually delete org-roam package first.

---

<div class="post-metadata">

**Author:** ![Gp741](https://avatars.discourse-cdn.com/v4/letter/g/77aa72/32.png) [@Gp741](https://org-roam.discourse.group/u/Gp741)\
**Post date:** [August 24, 2021, 10:50am UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/10 "2021-08-24T10:50:23Z")

</div>

When enabling the org-roam layer (org-enable-roam-support t), I was no more able to run Spacemacs in daemon mode. Similar bugs have been are already reported on github ([Emacs hangs when started in daemon mode #14477](https://github.com/syl20bnr/spacemacs/issues/14477))

---

<div class="post-metadata">

**Author:** ![jbotz](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/jbotz/32/616_2.png) [@jbotz](https://org-roam.discourse.group/u/jbotz)\
**Post date:** [August 24, 2021, 2:28pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/11 "2021-08-24T14:28:26Z")

</div>

Which version of spacemacs are you using?

---

<div class="post-metadata">

**Author:** ![Gp741](https://avatars.discourse-cdn.com/v4/letter/g/77aa72/32.png) [@Gp741](https://org-roam.discourse.group/u/Gp741)\
**Post date:** [August 24, 2021, 2:40pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/12 "2021-08-24T14:40:00Z")

</div>

v.0.300.0 develop branch

---

<div class="post-metadata">

**Author:** ![jbotz](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/jbotz/32/616_2.png) [@jbotz](https://org-roam.discourse.group/u/jbotz)\
**Post date:** [August 24, 2021, 2:51pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/13 "2021-08-24T14:51:16Z")

</div>

Hmm, it works for me with a fresh clone of latest spacemacs develop and no customization other than enabling org-enable-roam-support. You may want to try that and then adding your customizations back in little by little to see what happens. What are your OS and emacs version?

That GH issue linked to is from a time before spacemacs worked with org-roam v2, so it may not be relevant anymore. Both org-roam and the spacemacs layer code for it have changed a lot since then.

---

<div class="post-metadata">

**Author:** ![Gp741](https://avatars.discourse-cdn.com/v4/letter/g/77aa72/32.png) [@Gp741](https://org-roam.discourse.group/u/Gp741)\
**Post date:** [August 25, 2021, 1:35pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/14 "2021-08-25T13:35:47Z")

</div>

I am using Emacs 27.1 under Win 10. I will try with no customization other than enabling org-enable-roam-support.

---

<div class="post-metadata">

**Author:** ![yanboyang713](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/yanboyang713/32/918_2.png) [@yanboyang713](https://org-roam.discourse.group/u/yanboyang713)\
**Post date:** [September 11, 2021, 11:08am UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/15 "2021-09-11T11:08:42Z")

</div>

@gnohz  
Thank you very much gnohz.

When I use you above configure.

It does NOT work on my spacemacs.  
There are two Warnings show when I start up the spacemacs. The configure also did not take effect.

Do you know the reason why? Thanks  
Warnings:  
- package org-roam not initialized in layer Boyang-research, you may consider  
removing this package from the package list or use the :toggle keyword instead  
of a `when' form. - package org-roam-bibtex not initialized in layer Boyang-research, you may consider removing this package from the package list or use the :toggle keyword instead of a `when’ form.

---

<div class="post-metadata">

**Author:** ![yanboyang713](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/yanboyang713/32/918_2.png) [@yanboyang713](https://org-roam.discourse.group/u/yanboyang713)\
**Post date:** [September 11, 2021, 11:13am UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/16 "2021-09-11T11:13:03Z")

</div>

@gnohz  
This is my [configuration](https://github.com/yanboyang713/spacemacs-private/blob/develop/layers/Boyang-research/packages.el).

---

<div class="post-metadata">

**Author:** ![gnohz](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gnohz/32/803_2.png) [@gnohz](https://org-roam.discourse.group/u/gnohz)\
**Post date:** [September 11, 2021, 2:47pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/17 "2021-09-11T14:47:54Z")

</div>

Did you “remove” the org-roam package from the org-layer in spacemacs?

```auto
(org :packeges (not org-roam))

```

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [September 11, 2021, 3:10pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/18 "2021-09-11T15:10:35Z")

</div>

Adding to @gnohz ,

- I would suggest to remove usage (I see two locations) of org-roam-mode in hooks. It does not do what you probably mean.

- I’d move org-roam-setup from init to config.

- Review the latest README of Org-roam and ORB to learn what both projects recommend for configuration with use-package — e.g. you would not use org-roam-setup and ORB should be required in config of org-roam, etc.

---

<div class="post-metadata">

**Author:** ![yanboyang713](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/yanboyang713/32/918_2.png) [@yanboyang713](https://org-roam.discourse.group/u/yanboyang713)\
**Post date:** [September 14, 2021, 5:12am UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/19 "2021-09-14T05:12:49Z")

</div>

@gnohz  
Hi gnohz,

Thanks for your reply and good day to you.

I found one of my issues.  
We have different layers name, so I need to change:  
defun org-roam/init-org-roam ()  
To:  
defun my layer name/init-org-roam ()

However, There is one Error show when I start up the spacemacs.  
Error (use-package): org-roam/:config: Key sequence r d starts with non-prefix key r

Do you face the same Error msg?

Also, I found this part of the configure(at the below) did not take effect.  
(spacemacs/set-leader-keys-for-major-mode 'org-mode  
“rb” 'org-roam-switch-to-buffer  
“rdy” 'org-roam-dailies-goto-yesterday  
“rdt” 'org-roam-dailies-goto-today  
“rdT” 'org-roam-dailies-goto-tomorrow  
“rdd” 'org-roam-dailies-goto-date  
“r/” 'org-roam-node-find  
“rc” 'org-roam-capture  
;; “rg” 'org-roam-graph  
“rh” 'org-id-get-create  
“ri” 'org-roam-node-insert  
“rl” 'org-roam-buffer-toggle  
“rta” 'org-roam-tag-add  
“rtd” 'org-roam-tag-delete  
“ra” 'org-roam-alias-add))

---

<div class="post-metadata">

**Author:** ![gnohz](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gnohz/32/803_2.png) [@gnohz](https://org-roam.discourse.group/u/gnohz)\
**Post date:** [September 14, 2021, 3:08pm UTC](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/20 "2021-09-14T15:08:14Z")

</div>

See

> [@V2 and spacemacs](https://org-roam.discourse.group/t/v2-and-spacemacs/1676/9):
>
> There are some file/folder re-structure in the org-roam repository. For example, they put org-dailies into “extensions”, so accordingly, I changed the org-roam location as follows: (org-roam :location (recipe :fetcher github :repo "org-roam/org-roam" :files (:defaults "extensions/\*")) ) You might need to manually delete org-roam package first.

[Next page](https://org-roam.discourse.group/t/v2-and-spacemacs/1676.md?page=2)
