Skip to content

Instantly share code, notes, and snippets.

@meditans
Last active March 14, 2020 03:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meditans/9214316a273b2ae835e39df4520c04f6 to your computer and use it in GitHub Desktop.
Save meditans/9214316a273b2ae835e39df4520c04f6 to your computer and use it in GitHub Desktop.
emacs direnv intro

Hai questo problema, diciamo che test/shell.nix sia:

{ pkgs ? import <nixpkgs> {} }:
with pkgs; mkShell { buildInputs = [ pkgs.hello ]; }

tu fai:

> cd test

test> hello
The program ‘hello’ is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix-env -iA nixos.hello
  nix-env -iA nixos.mbedtls
  nix-env -iA nixos.perkeep

test> nix-shell

test (nix-shell)> hello
hello, world

test (nix-shell)> emacs .

-------- dentro emacs --------
M-x shell

> hello
The program ‘hello’ is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix-env -iA nixos.hello
  nix-env -iA nixos.mbedtls
  nix-env -iA nixos.perkeep

In tal caso potresti essere interessato a direnv. Devi:

  1. installare direnv nel tuo /etc/nixos/configuration.nix.
  2. aggiungere l’hook nella tua $SHELL come qui.
  3. nella tua configurazione privata di doom-emacs (SPC f p) nel file init.el attiva direnv (sotto :tools).

Ora crea il file test/.envrc contenente:

use_nix

dai, in test, il comando

direnv allow

ora apri emacs. Se lavori su un qualunque file nella directory test, emacs leggerà la configurazione di direnv, impostata in questo caso per leggere nix-shell, quindi se parti una shell M-x shell avrai il comando disponibile.

ps. emacs aprilo normalmente, non hai bisogno di partirlo dalla nix-shell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment