Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spacemacs setup instructions #237

Closed
wants to merge 9 commits into from
Closed

Conversation

@srid
Copy link
Contributor

srid commented Feb 10, 2018

This PR supersedes #235 with the primary improvement being supporting standalone Emacs process (run independent of nix-shell environment).

Markdown Preview

@srid srid mentioned this pull request Feb 10, 2018
4 of 5 tasks complete
ryantrinkle and others added 4 commits Feb 10, 2018
Without this dante will not be enabled. And without dante flycheck won't
select the working checker (based on dante) and thus fail.
@srid

This comment has been minimized.

Copy link
Contributor Author

srid commented Feb 10, 2018

@ryantrinkle This PR is now complete. (and flycheck is disabled by default)

@srid

This comment has been minimized.

Copy link
Contributor Author

srid commented Feb 11, 2018

In future we can make two improvements:

  • Improve dante to better work with reflex projects and then obviate the need for project setup (creation of shell.nix and .dir-locals.el files)

  • Create a spacemacs layer just for Reflex projects (nix + cabal new-style + reflex-platform project), so that all the user is required to do is to add a line in their .spacemacs file.

srid added a commit to srid/Belvedere that referenced this pull request Feb 12, 2018
@srid srid mentioned this pull request Feb 12, 2018
@dalaing

This comment has been minimized.

Copy link

dalaing commented Feb 15, 2018

This is working pretty well for me at the moment.

I've added:

  ;; Configure hoogle to use Nix
  (setq haskell-hoogle-command
        (nix-executable-find (nix-current-sandbox) "hoogle"))

to mine and it has given me the ability to browse the locally generated hoogle db / haddocks via , h H (with this to work around Firefox's local links restrictions).

@srid

This comment has been minimized.

Copy link
Contributor Author

srid commented Feb 15, 2018

@dalaing Thanks for trying it out. The hoogle part doesn't work for me. I think the setting of haskell-hoogle-command needs to be in .dir-locals.el, but that doesn't help anyway - as haskell-mode is not using that variable to start the server; it directly does executable-find though it should be trivial to fix...

Using that nix-buffer thing of #240 is probably the better way to address issues like this, as it sets the PATH variable itself to that of nix environment ...

@dalaing

This comment has been minimized.

Copy link

dalaing commented Feb 15, 2018

It's working for me, but it seems that's because a) I have hoogle installed globally and b) I have nix generating the hoogle db for my dependencies. Without the above config it doesn't work for me, and now it works (and works if I am working in different projects with different hoogle DBs).

If it's going to be fragile / if it's fighting the currently hoogle.el file then it's probably not something that should be included in this PR. I'm mostly just happy it works for me, and dropping breadcrumbs in the comments in case it works for some other folks as well :)

@ali-abrar ali-abrar requested review from luigy and danharaj Mar 10, 2018
@parenthetical

This comment has been minimized.

Copy link

parenthetical commented Mar 10, 2018

Thanks for writing this guide. I've followed the instructions for my reflex-platform project setup, but I'm getting this error:

error: attempt to call something which is not a function but a set, at shell.nix:1:2

This is my default.nix:

(import ./reflex-platform {}).project ({ pkgs, ... }: {
  packages = {
    common = ./common;
    app = ./app;
  };
shells = {
    ghc = ["common" "app"];
  };
})

And my shell.nix:

(import ./. {}).shells.ghc

What might be wrong?

@srid

This comment has been minimized.

Copy link
Contributor Author

srid commented Mar 10, 2018

@parenthetical I think this is because your default.nix is not returning a function. See https://github.com/ElvishJerricco/reflex-project-skeleton/blob/master/default.nix#L1

Alternatively you can just remove the {} from your shell.nix I think.

@parenthetical

This comment has been minimized.

Copy link

parenthetical commented Mar 10, 2018

@srid Thanks, both of those fixed the problem with launching a Nix shell.

@adetokunbo

This comment has been minimized.

Copy link
Contributor

adetokunbo commented Mar 14, 2018

Thank you for writing this up!

On my MacBook Pro, the spacemacs develop branch kept crashing with bugs not related to reflex; but I think I have most of this working on the spacemacs master branch. I also made the flycheck-* variables file local, e.g

  (make-local-variable 'flycheck-command-wrapper-function)
  (make-local-variable 'flycheck-executable-find)
  (setq flycheck-command-wrapper-function
        (lambda (cmd) (apply 'nix-shell-command (nix-current-sandbox) cmd))
        flycheck-executable-find
        (lambda (cmd) (nix-executable-find (nix-current-sandbox) cmd)))

Full details in this gist

@adetokunbo

This comment has been minimized.

Copy link
Contributor

adetokunbo commented Mar 20, 2018

I updated the gist with some changes to move some of the config that is suggested for .dir-locals.el to another hook added to 'hack-local-variables-hook in the .spacemacs file:

;; Setup the dante project values according to the proposed layout for
;; shared common code, i.e
;;
;; dante-project-root === <immediate folder with a shell.nix>
;; dante-repl-command-line === cabal new-repl <dante-target> --buildir=dist/dante
(defun reflex-set-dante-locals ()
  (make-local-variable 'dante-project-root)
  (make-local-variable 'dante-repl-command-line)
  (setq dante-project-root
        (locate-dominating-file buffer-file-name "shell.nix"))
  (if dante-target
      (let ((cabal-cmd
             (concat "cabal new-repl " dante-target " --builddir=dist/dante")))
        (setq dante-repl-command-line (list "nix-shell" "--run" cabal-cmd)))
    nil))

With this addition, the .dir_locals.el files only need to set dante-target: e.g,

  • frontend/.dir_locals.el: ((nil . ((dante-target . "frontend"))))
  • backend/.dir_locals.el: ((nil . ((dante-target . "backend"))))
@srid

This comment has been minimized.

Copy link
Contributor Author

srid commented Mar 25, 2018

For more candy, one can run ghcid in an Emacs buffer (set to compilation-mode) and get free hot-reloading (almost) as well. See ElvishJerricco/reflex-project-skeleton#14

@endgame

This comment has been minimized.

Copy link

endgame commented Jun 26, 2018

Remark: You can set a single, toplevel .dir-locals.el with content like:

(("frontend" . ((nil . ((dante-target . "frontend")))))
 ("backend" . ((nil . ((dante-target . "backend")))))
 ("common" . ((nil . ((dante-target . "common"))))))
@endgame

This comment has been minimized.

Copy link

endgame commented Jun 26, 2018

Additional remark: If you push a shell.nix into each subdirectory with contents roughly like:

(import ./..).shells.ghc

Then you can set which shell to use per-project, and you don't have to use the eval in .dir-locals.el (which emacs considers unsafe).

There is more wrangling required to teach dante to use ghcjs and the ghcjs project file. I don't have time to think about this right now.

@benkolera

This comment has been minimized.

Copy link

benkolera commented Jul 31, 2018

Hi! This is great stuff! I do note that this breaks my fresh obelisk project, though. Is this known and is there a work around?

$ ob -v run
Starting Obelisk </nix/store/4clpxvj72afcx7f60dl6xd1ylsv9891f-obelisk-command-0.1/bin/ob> args=["-v","run"] logging-level=Debug
Handing off to project obelisk ./.obelisk/impl/.attr-cache/command.out/bin/ob
Starting Obelisk </nix/store/4clpxvj72afcx7f60dl6xd1ylsv9891f-obelisk-command-0.1/bin/ob> args=["--no-handoff","-v","run"] logging-level=Debug
Not handing off
Creating process runNixShellAttr: RawCommand "nix-shell" ["-A","shells.ghc","--run","/nix/store/4clpxvj72afcx7f60dl6xd1ylsv9891f-obelisk-command-0.1/bin/ob --no-handoff --verbose internal run-static-io 482578dd15cac88e0846aa6ec3edf676"]
error: attribute ‘shells’ in selection path ‘shells.ghc’ not found

I can hack around this with a separate shell.nix for emacs, but I just wanted to write this here unless it was pebcak (my obleisk could be a week old) or there was a better fix in the works. 🙂

Edit: FYI: Putting the shell.nix down in frontend and backend did the trick in an obelisk project.

ryantrinkle and others added 2 commits Sep 4, 2018
@dmp1ce

This comment has been minimized.

Copy link

dmp1ce commented Nov 13, 2018

I ran into two issues with these instructions.

  1. I couldn't get dante working when overriding a package in the default.nix
  2. I couldn't get dante working with Obelisk
@hSloan hSloan added the enhancement label Jan 22, 2019
@willbush

This comment has been minimized.

Copy link

willbush commented Jan 28, 2019

I found that buffer-file-name from .dir-locals.el returns nil when navigating into the frontend or backend folders using dired, which results in an error. I think it can be replaced with ".", but it's probably better to change it to what @endgame was suggesting to avoid eval in the first place.

@willbush

This comment has been minimized.

Copy link

willbush commented Feb 11, 2019

I'd like to mention a lot of this can be simplified by using obelisk. See the following issue: obsidiansystems/obelisk#184

@ali-abrar

This comment has been minimized.

Copy link
Member

ali-abrar commented Mar 16, 2019

Is the documentation here still up-to-date?

@srid

This comment has been minimized.

Copy link
Contributor Author

srid commented Mar 16, 2019

Is the documentation here still up-to-date?

Probably not. I don't use Spacemacs anymore, and haven't been as interested anymore in editor integration due to obelisk's ghcid reporting being satisfyingly sufficient.

@ali-abrar ali-abrar closed this Mar 18, 2019
matthewbauer pushed a commit that referenced this pull request Nov 20, 2019
Obelisk.CliApp.Process: reconstruct commands on display
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.