Skip to content

Using Nix Develop Environment#

Install nix from shell#

sh <(curl -L --daemon

then exec bash -l reload your bash to load the nix-env

Enable Flake Feature Of Nix#

echo "experimental-features = nix-command flakes" | sudo tee -a /etc/nix/nix.conf
sudo pkill nix-daemon

NOTE: reload bash and check your nix-version first

nix --version
nix (Nix) 2.4

Nix flake feature already in emacsNg#

nix run github:emacs-ng/emacs-ng (launch emacs locally )
nix build github:emacs-ng/emacs-ng (build emacs locally)
nix develop github:emacs-ng/emacs-ng (enter develop emacs environment locally)

Also, you can run native nix commands (Nix Stable Version) under emacs-ng repo, such as


Using cachix to (download binary cache) speed up build#

  1. Without installing cachix
nix build github:emacs-ng/emacs-ng --option substituters "" --option trusted-public-keys "" -o emacsNg
ls -il emacs
#or check ./result/bin/emacs
nix-build --option substituters "" --option trusted-public-keys ""
  1. Installing cachix
nix-env -iA cachix -f #install cachix
exec bash -l
cachix use emacsng # make sure you have saw the output like: Configured binary cache in /home/test/.config/nix/nix.conf
nix build github:emacs-ng/emacs-ng -o emacsNG
ls -il emacsNG

Clone Emacs Ng By Nix-Shell And Enable Emacs Cachix#

nix-env -iA cachix -f
exec bash -l
cachix use emacsng # make sure you have saw the output like: Configured binary cache in /home/test/.config/nix/nix.conf
nix-shell -p git --command "git clone && cd emacs-ng && nix-shell"

Setting Up Rust Development Environment#

Change Rust Version#

  1. Nightly Version
  2. located nix/rust.nix modify the 2021-01-14to which your want.(rustOverlay-NightlyCheck) Example: default = pkgs.rust-bin.nightly."2021-03-23";

  3. Stable version

  4. example : default = pkgs.rust-bin.stable."1.50.0"; (rustOverlay-StableCheck)

  5. Beta version

  6. example : default = pkgs.rust-bin.beta."2021-03-06"; (rustOverlay-StableCheck)

Add Package from RustOverly#

The RustOverly supported Packages list that you can find here (packages-list)

  • located nix/rust.nix
        rustOverlaySet = mkOption {
          type = types.listOf types.str;
          default = [
            "<add other package which you can found in package-list>"
          description = "Which rust tools to pull from the rust overlay

Add rustPackages from nixpkgs channel#

  • located nix/rust.nix and the default nix expression like this rustPackages.clippy. In this cause, most of rust toolchain installed from rustOverly
    rustPackagesSet = mkOption {
      type = types.listOf types.str;
      default = [
        "<add custom Rust toolchain package>"
      description = "Which rust tools to pull from the nixpkgs channel package set
      check valid package from";

Add nixpkgs package to current Environment#

  • located nix/rust.nix

first, search for package in search-package then add the name of package to:

devshell.packages = map (tool: cfg.rustPackages.${tool}) cfg.rustPackagesSet
      ++ map (tool: cfg.rustOverlay.${tool}) cfg.rustOverlaySet ++ (with pkgs;[
      #custom nixpkgs packages
      <add package here>

## Reload all of environments when you changed something

- normally, we can re-enter `nix-shell` to reload environments. But for this project, we are using direnv to load and unload environment variables in an convenient way.

### Recommended Way -> Direnv

 Install direnv by Nix

    nix-env -i direnv

and hook direnv to your bash [direnv-hook](

- using `direnv allow`  or `direnv deny` to enable or disable load `nix-shell` in current path

- using `direnv reload` to reload `nix-shell`

- Also, you can put as follows to `~/.config/direnv/direnvrc` watching the envrs every time changes that could be reload automatically.

use_flake() {
  watch_file flake.nix
  watch_file flake.lock
  eval "$(nix print-dev-env)"

Add Direnv Support With Emacs#

Install direnv to Doom Emacs, Example

(package! envrc :recipe (:host github :repo "purcell/envrc"))
(use-package! envrc
:hook (after-init . envrc-global-mode)
then M-x typing envrv-<**> check related commands similar to native direnv-commands

Write A Custom Command Or Environment Variable#

  • locaed nix/commands.toml

  • Add custom command as following: Example

name = ""
command = "cargo build --manifest-path=./crates/codegen/Cargo.toml"
help = "cargo build codegen"
category = "rust-build"
  • Add custom env variable as following:
name = "TEST"
vale = "/bin/test"
#prefix = "$( cd "$(dirname "$\{\BASH_SOURCE [ 0 ]}")"; pwd )" can be prefix

Building Emacs-ng in development mode#

  • located flake.nix commented emacsNG-src to "./."


          #emacsNgSource = emacsNG-src;
          emacsNgSource = "./.";

then nix-build it;

Add custom configFlags to emacsNg build process#

  • located flake.nix
configureFlags = (old.configureFlags or [ ]) ++ [
        "<custom flags>"

NOTICE: nix-build action in sandbox mode. If you want to modify something or patch it, please put it this way to the corresponding step.

For example:

preConfigure = (old.preConfigure or "") + ''
  <modify shell>

patches = (old.patches or [ ]) ++ [

if everything looks good, you can run nix-build right now.

Last update: May 2, 2024