Dangerous_Moose_4765 · 2022-05-03 02:16
Has anybody successfully tried using nixshell + direnv + emacs ?
essentially I would like emacs to work within a nixshell whenever I open a buffer in a particular project.
i.e: use pythonenv in nixshell.
Has anybody tried anything similar? thanks
rajivmr · 2022-05-03 02:55
Have you tried using `nix-buffer`? I manage my emacs packages using `home-manager`, and use `nix-buffer` as and when needed.
voidee123 · 2022-05-03 03:52
I have this but for flakes and it works perfectly. If you haven't found it yet use [emacs-direnv](https://github.com/wbolster/emacs-direnv). It will automatically switch the environment when changing directories. If I change something in a flake, I need to use the `direnv-update-directory-enviornment` to get it to change but other than that just change buffers and it will figure out if you're in a new directory environment or not.
Using this I can run a project specific python (or whatever language) repl in emacs. For example, I don't actually have python installed globally, so if I try to run `run-python` somewhere, I get the error "start-process: Searching for program: No such file or directory, ipython" but open a flake with python as a dependency and I can start the python repl.
akirakom · 2022-05-03 04:27
I am currently using [envrc](https://github.com/purcell/envrc) by Purcell, and it works like a charm. I was previously using direnv-mode, which should also work.
I use flakes, so
1. Add dependencies to `buildInputs` of `devShell` (`devShells.default` since Nix 2.7) in flake.nix
2. Open vterm and run `nix develop` to fetch the dependencies
3. Create .envrc with `use flake` as its content
4. `envrc-allow`
Similar steps would work for `shell.nix`. If you don't use a flake, `.envrc` should contain `use nix`.
alcanost · 2022-05-03 18:27
I'm using [lorri](https://github.com/nix-community/lorri) and [emacs-direnv](https://github.com/wbolster/emacs-direnv) together, works perfectly fine for me.
Psionikus · 2022-06-05 16:25
{
description = "Make me a github Melpa project yesterday!";
# inputs are pinned via flake.lock. The normal way to update an individual
# version is:
# nix flake lock --update-input emacs-overlay
# Tracking can be accomplished via CI and machine commits
inputs = {
# stable branches are recommended for CI, regression spotting. Testing with
# multiple versions can be done via input overrides, such as:
# nix build .#ci --override-input nixpkgs github:nixpkgs/nixpkgs/unstable
nixpkgs.url = "github:nixos/nixpkgs?ref=release-22.05";
flake-utils.url = "github:numtide/flake-utils";
emacs-overlay.url = "github:nix-community/emacs-overlay";
# slave Emacs overlay to our nixpkgs. This doesn't do a lot except reduce
# the closure size and allow us to control both nixpkgs versions with one
# declaration.
emacs-overlay.inputs.nixpkgs.follows = "nixpkgs";
emacs-overlay.inputs.flake-utils.follows = "flake-utils";
};
outputs = inputs: with inputs;
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ emacs-overlay.overlay ];
};
runTestsShell = pkgs.mkShell {
packages = [ pkgs.emacsNativeComp ];
};
in {
# The output set, where all useful things go. If your nix flake exposes
# packages, overlays, shells, or nix utils, they can be exposed here for
# downstream consumption.
devShells = {
default = runTestsShell;
};
});
}
Contents of .envrc are `use nix` and it automagically loads the `devShells.default`