How do I differentiate directories between computers using org-roam?
What I’m Trying to Do
I am trying to use org-roam on Linux for my personal notes, but also have access to my work notes, and also use it on a work Windows PC with only access to my work notes. I am using syncthing to syncronize my org-roam directory with subdirectories Work/ and Personal/ and have an .stignore file with Personal listed in it so that it doesn’t get copied to my work machine.
Each machine is building and updating it’s own database, so the path is important, but the file is not.
On Linux, everything is pretty much working as far as I can tell, but Windows is pointing to the wrong folder.
Below is my org-roam config in my init.el. I am looking for a way for org-roam to point it’s directory and db-location to: "C:\Users\Zonsopkomst\Documents\Syncthing\org-roam"
while keeping keeping my setup for my Linux personal laptop and desktops intact. That being said, I wouldn’t mind being able to call some lisp that would determine which machine is using what. I have been told that maybe a (cond (<test for computer 1> (setq ...)) (<test for computer 2> (setq ...))) or conditional + system-name (function) or system-type (variable) could do the trick. Unfortunately, I am brand new to emacs, lisp, and programming in general, and truth be told am only an armchair hobbyist, more or less hacking things together and learning as I go.
My init.el org-roam Config
"org-roam"
"Org-roam is a plain-text knowledge management system. It brings some of Roam's more powerful features into the Org-mode ecosystem."
[[https://github.com/org-roam/org-roam]]
(use-package org-roam
:custom
(org-roam-directory "~/Syncthing/org-roam/")
(org-roam-db-location "~/Syncthing/org-roam/org-roam.db")
:bind (("C-c n l" . org-roam-buffer-toggle)
("C-c n f" . org-roam-node-find)
("C-c n i" . org-roam-node-insert))
:config
(org-roam-setup))
I know this isn’t correct yet, but trying to post some things as I go along and revise them:
(use-package org-roam
:custom
;; Change path for PC
(eval (if system-name *zonsopkomst*
;; use Linux path
(org-roam-directory "~/Syncthing/org-roam/")
;; otherwise use Windows path
(org-roam-directory "c:/Users/WORKUSER$/Documents/Syncthing/org-roam/")))
(eval (if system-name *zonsopkomst*
;; use Linux database
(org-roam-db-location "~/Syncthing/org-roam/org-roam.db")
;; otherwise use Windows database
(org-roam-db-location "c:/Users/WORKUSER$/Documents/Syncthing/org-roam.db")
;;(org-roam-directory "~/Syncthing/org-roam/")
;;(org-roam-db-location "~/Syncthing/org-roam/org-roam.db")
:bind (("C-c n l" . org-roam-buffer-toggle)
("C-c n f" . org-roam-node-find)
("C-c n i" . org-roam-node-insert))
:config
(org-roam-setup))
I suggest you add C:\Users\Zonsopkomst\Documents to variable HOME in your environment variable. Emacs will be able to point to it as ~, so you don’t need cond.
This is documented in the manual (online). Or in-system, evaluate (info "(efaq-w32) Location of init file") – do you know how to evaluate this? I’d put the cursor right after it and do C-x C-e, whcih is, by default, to call eval-last-sexp. I hope your set-up of Emacs has the Info documentation for you…
Below my Windows has this. C:\Users\nobiot = ~ in Emacs.
Thank you @nobiot. As of today, I have one database populated on my Linux laptop and one on my Windows work desktop. I fixed my sloppy parentheses as you pointed out and had to fix some more sloppy path and system-name issues on the Linux side, but they both at least have databases now. Next steps are for me to learn and use org-roam.
Just a note for anyone who is reading this for their issue, @nobiot 's other solution of editing the HOME environmental variables is probably the easiest way if you are running one or more Windows PC and you have access to the environmental variables.
For those managing multiple machines on different platforms: I personally wanted to learn how to declare the computers in the init.el, so that I can easily change and replicate machines. So that is why I went this route in the end.
Congratulations! And thank you for detailing your reason for the approach you took and your solution for future reference. I am sure people will benefit from your efforts.