summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdback <tyler@tdback.net>2025-03-26 19:58:22 -0400
committertdback <tyler@tdback.net>2025-03-26 19:58:22 -0400
commite81da688d01dada4ab154d3068e1bb7025d3b8a1 (patch)
tree41f6b2a921897183c070beddd2bd6007adf60859
parent743e375945b9080ea70b9dd16ba839f37b32b5fe (diff)
blog: update example flake to use go. update old link
-rw-r--r--content/posts/development-environments/index.md23
1 files changed, 10 insertions, 13 deletions
diff --git a/content/posts/development-environments/index.md b/content/posts/development-environments/index.md
index ca8272d..20d576c 100644
--- a/content/posts/development-environments/index.md
+++ b/content/posts/development-environments/index.md
@@ -5,7 +5,7 @@ date = '2025-02-09T19:59:55-05:00'
draft = false
+++
-Recently I decided to fire up Emacs, [declare bankruptcy](https://www.emacswiki.org/emacs/DotEmacsBankruptcy) on my old config, and [rewrite it again from scratch](https://github.com/tdback/emacs.d). I thought I would share how I use Emacs alongside Nix to create seamless, reproducible development environments for hacking on projects.
+Recently I decided to fire up Emacs, [declare bankruptcy](https://www.emacswiki.org/emacs/DotEmacsBankruptcy) on my old config, and [rewrite it again from scratch](https://codeberg.org/tdback/emacs.d). I thought I would share how I use Emacs alongside Nix to create seamless, reproducible development environments for hacking on projects.
# Setting Things Up
The secret sauce here is [direnv](https://direnv.net/). `direnv` allows us to load and unload environment variables depending on the current directory. When paired with Nix, we can automatically handle the environment variables for per-project dependencies specified in our `flake.nix` or `shell.nix` files.
@@ -51,16 +51,16 @@ And enable the global minor mode on startup in `~/.emacs.d/init.el`:
```
# An Example Project
-Let's create a new project that will setup a development environment for working with Rust. In our example `flake.nix` file, we'll include an overlay to pull in the latest stable Rust toolchain and `rust-analyzer` for LSP support in Emacs:
+Let's create a new project that will setup a development environment for working with [Go](https://go.dev/). In our example `flake.nix` file, we'll pull in the latest `go` compiler and `gopls` language server for LSP support in Emacs:
```nix
{
+ description = "Example golang project.";
+
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
- inputs.rust-overlay.url = "github:oxalica/rust-overlay";
outputs =
{
nixpkgs,
- rust-overlay,
...
}:
let
@@ -71,18 +71,15 @@ Let's create a new project that will setup a development environment for working
devShells = eachSystem (
system:
let
- overlays = [ (import rust-overlay) ];
- pkgs = import nixpkgs {
- inherit system overlays;
- };
+ pkgs = import nixpkgs { inherit system; };
in
{
default =
with pkgs;
mkShell {
buildInputs = with pkgs; [
- rust-analyzer
- rust-bin.stable.latest.default
+ go
+ gopls
];
};
}
@@ -98,14 +95,14 @@ echo "use flake" >> .envrc && direnv allow
To load the Nix environment, all we have to do now is navigate to the directory in Emacs. When `direnv` loads the environment, it will automatically download all of our specified packages in `flake.nix` and update the respective Emacs variables `process-environment` and `exec-path` so that packages from our flake started within Emacs use the correct `$PATH` with the proper environment variables set (even when using the daemon).
-Compare this to working on the example project without `direnv`: we would first have to navigate to the project in our shell, manually run `nix develop` (or `nix-shell` if we are not using flakes) to pull in the toolchain and LSP, and then start Emacs from the shell to ensure those packages work properly.
+Compare this to working on the example project without `direnv`: we would first have to navigate to the project in our shell, manually run `nix develop` (or `nix-shell` if we are not using flakes) to pull in the compiler and language server, and then start Emacs from the shell to ensure those packages work properly.
Emacs will even display a helpful message in the minibuffer when `direnv` updates your environment variables. Here's a snippet from my `*Messages*` buffer of `direnv` loading a Nix environment when I navigate to one of my projects:
```
-direnv: +AR +AR_FOR_TARGET +AS +AS_FOR_TARGET +CC +CC_FOR_TARGET +CONFIG_SHELL +CXX +CXX_FOR_TARGET +HOST_PATH +IN_NIX_SHELL +LD +LD_FOR_TARGET +NIX_BINTOOLS +NIX_BINTOOLS_FOR_TARGET +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_BINTOOLS_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu +NIX_BUILD_CORES +NIX_CC +NIX_CC_FOR_TARGET +NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_CC_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu +NIX_CFLAGS_COMPILE +NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE +NIX_LDFLAGS +NIX_LDFLAGS_FOR_TARGET +NIX_STORE +NM +NM_FOR_TARGET +OBJCOPY +OBJCOPY_FOR_TARGET +OBJDUMP +OBJDUMP_FOR_TARGET +RANLIB +RANLIB_FOR_TARGET +READELF +READELF_FOR_TARGET +SIZE +SIZE_FOR_TARGET +SOURCE_DATE_EPOCH +STRINGS +STRINGS_FOR_TARGET +STRIP +STRIP_FOR_TARGET +__structuredAttrs +buildInputs +buildPhase +builder +cmakeFlags +configureFlags +depsBuildBuild +depsBuildBuildPropagated +depsBuildTarget +depsBuildTargetPropagated +depsHostHost +depsHostHostPropagated +depsTargetTarget +depsTargetTargetPropagated +doCheck +doInstallCheck +dontAddDisableDepTrack +mesonFlags +name +nativeBuildInputs +out +outputs +patches +phases +preferLocalBuild +propagatedBuildInputs +propagatedNativeBuildInputs +shell +shellHook +stdenv +strictDeps +system ~PATH ~XDG_DATA_DIRS (~/Projects → ~/Projects/fasten)
+direnv: +AR +AS +CC +CONFIG_SHELL +CXX +HOST_PATH +IN_NIX_SHELL +LD +NIX_BINTOOLS +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_BUILD_CORES +NIX_CC +NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_CFLAGS_COMPILE +NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE +NIX_LDFLAGS +NIX_STORE +NM +OBJCOPY +OBJDUMP +RANLIB +READELF +SIZE +SOURCE_DATE_EPOCH +STRINGS +STRIP +__structuredAttrs +buildInputs +buildPhase +builder +cmakeFlags +configureFlags +depsBuildBuild +depsBuildBuildPropagated +depsBuildTarget +depsBuildTargetPropagated +depsHostHost +depsHostHostPropagated +depsTargetTarget +depsTargetTargetPropagated +doCheck +doInstallCheck +dontAddDisableDepTrack +mesonFlags +name +nativeBuildInputs +out +outputs +patches +phases +preferLocalBuild +propagatedBuildInputs +propagatedNativeBuildInputs +shell +shellHook +stdenv +strictDeps +system ~PATH ~XDG_DATA_DIRS (~/Projects → ~/Projects/fasten)
```
And here's the snippet of `direnv` unloading the Nix environment when I navigate outside of the project:
```
-direnv: ~PATH ~XDG_DATA_DIRS -AR -AR_FOR_TARGET -AS -AS_FOR_TARGET -CC -CC_FOR_TARGET -CONFIG_SHELL -CXX -CXX_FOR_TARGET -HOST_PATH -IN_NIX_SHELL -LD -LD_FOR_TARGET -NIX_BINTOOLS -NIX_BINTOOLS_FOR_TARGET -NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu -NIX_BINTOOLS_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu -NIX_BUILD_CORES -NIX_CC -NIX_CC_FOR_TARGET -NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu -NIX_CC_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu -NIX_CFLAGS_COMPILE -NIX_ENFORCE_NO_NATIVE -NIX_HARDENING_ENABLE -NIX_LDFLAGS -NIX_LDFLAGS_FOR_TARGET -NIX_STORE -NM -NM_FOR_TARGET -OBJCOPY -OBJCOPY_FOR_TARGET -OBJDUMP -OBJDUMP_FOR_TARGET -RANLIB -RANLIB_FOR_TARGET -READELF -READELF_FOR_TARGET -SIZE -SIZE_FOR_TARGET -SOURCE_DATE_EPOCH -STRINGS -STRINGS_FOR_TARGET -STRIP -STRIP_FOR_TARGET -__structuredAttrs -buildInputs -buildPhase -builder -cmakeFlags -configureFlags -depsBuildBuild -depsBuildBuildPropagated -depsBuildTarget -depsBuildTargetPropagated -depsHostHost -depsHostHostPropagated -depsTargetTarget -depsTargetTargetPropagated -doCheck -doInstallCheck -dontAddDisableDepTrack -mesonFlags -name -nativeBuildInputs -out -outputs -patches -phases -preferLocalBuild -propagatedBuildInputs -propagatedNativeBuildInputs -shell -shellHook -stdenv -strictDeps -system (~/Projects/fasten → ~/Projects)
+direnv: ~PATH ~XDG_DATA_DIRS -AR -AS -CC -CONFIG_SHELL -CXX -HOST_PATH -IN_NIX_SHELL -LD -NIX_BINTOOLS -NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu -NIX_BUILD_CORES -NIX_CC -NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu -NIX_CFLAGS_COMPILE -NIX_ENFORCE_NO_NATIVE -NIX_HARDENING_ENABLE -NIX_LDFLAGS -NIX_STORE -NM -OBJCOPY -OBJDUMP -RANLIB -READELF -SIZE -SOURCE_DATE_EPOCH -STRINGS -STRIP -__structuredAttrs -buildInputs -buildPhase -builder -cmakeFlags -configureFlags -depsBuildBuild -depsBuildBuildPropagated -depsBuildTarget -depsBuildTargetPropagated -depsHostHost -depsHostHostPropagated -depsTargetTarget -depsTargetTargetPropagated -doCheck -doInstallCheck -dontAddDisableDepTrack -mesonFlags -name -nativeBuildInputs -out -outputs -patches -phases -preferLocalBuild -propagatedBuildInputs -propagatedNativeBuildInputs -shell -shellHook -stdenv -strictDeps -system (~/Projects/fasten → ~/Projects)
```