iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🌻

Building a Local Zenn Writing Environment with WSL, Nix, and VSCode

に公開
2025/09/06

Introduction

When creating articles on Zenn, you can use two methods: the browser-based editor and the local editor (requires Zenn CLI).

https://zenn.dev/zenn/articles/connect-to-github

https://zenn.dev/zenn/articles/zenn-cli-guide

Probably, many people use the browser-based editor, which allows you to write articles directly on the Zenn site.

On the other hand, the local editor has the following advantages:

  • GitHub integration
    • Version control possible
    • Convenient to see diffs when proofreading
    • Article text and images can be stored in your own repository instead of Zenn
  • Use your favorite editor
    • In my case, I use VSCode
    • Editor features such as linters and AI-assisted input are available

In this article, I will introduce how to set up the Zenn writing environment I use on a daily basis.

Target Audience

  • Those interested in creating articles using the Zenn CLI local environment
  • Those who want to see how easy it is to set up an environment with Nix
    • Recommended as an easy-to-use package manager
    • If you are interested in trying it out, there are clear introductory books available, so please take a look
  • Those using Windows or VSCode
    • Even if you use a different environment, I will introduce Zenn-specific rules and workarounds, so it might be helpful?

Environment Overview

  • Windows 11
  • WSL2
    • Ubuntu 22.04.5 LTS
  • Editor: VSCode
    • Uses Profile feature to create Zenn-specific user settings
    • Manages settings and tasks via .vscode
  • Environment setup: Nix
    • Manages Zenn-specific tools (Zenn CLI)
  • User environment management: home-manager
    • Manages general-purpose tools (git, etc.)

Folder Structure

Folder structure
zenn_contents/
├─ articles/
│   └─ 007bff63247432.md
├─ books/
├─ images/
│   └─ 007bff63247432/
│       └─ 007bff63247432-2025-8-25_1.webp
├─ .git/
├─ .gitignore
├─ .vscode/  // Place VSCode configuration files
│   ├─ settings.json  // Describe extension settings
│   └─ tasks.json  // Describe tasks
├─ flake.nix  // Define which tools to use with Nix
└─ .envrc  // Used to automatically activate the Nix environment

Article Flow

First, prepare the necessary tools for creating Zenn articles locally.

Then, perform various settings to improve convenience when writing articles in VSCode.

1. Connect Zenn and GitHub

Refer to the following official guide to create a repository and set up the connection.

https://zenn.dev/zenn/articles/connect-to-github

2. Introducing Zenn CLI

https://zenn.dev/zenn/articles/install-zenn-cli

2.1 Set Up a Development Environment for Zenn CLI with Nix

Create a flake.nix as follows:

Folder structure
zenn_contents/
  ├─ articles/
  ├─ books/
  ├─ images/
+ └─ flake.nix
flake.nix
{
  description = "Zenn CLI environment";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs =
    { nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
      in
      {
        devShells.default = pkgs.mkShell {
          packages = [ pkgs.zenn-cli ];
        };
      }
    );
}

2.2 Launching the Environment

Running nix develop will set up the environment based on flake.nix.

Bash
# Zenn CLI is not installed
$ zenn --version
zenn: command not found

# Start the environment
$ nix develop

# Zenn CLI is now available!
$ zenn --version
0.2.1

# Exit the environment
$ exit

3. Automatically Activate the Nix Environment

3.1 Introduce Required Tools with home-manager

Since it is tedious to run nix develop every time you open the Zenn environment, we will automate it with direnv and nix-direnv.

https://github.com/direnv/direnv

https://github.com/nix-community/nix-direnv

https://zenn.dev/asa1984/books/nix-hands-on/viewer/ch02-03-devshell#direnv

direnv and nix-direnv are used to set up the environment based on flake.nix, so they must be installed by a method other than writing them in flake.nix.

I manage the tools installed in the user environment of Ubuntu on WSL using home-manager.

To introduce direnv and nix-direnv with home-manager, write the following in home.nix:

home.nix
{ config, pkgs, ... }:

{
  home.username = "ryu";
  home.homeDirectory = "/home/ryu";

  home.stateVersion = "25.05";

  # Unrelated packages are omitted
  home.packages = with pkgs; [
    git
    bash
    direnv
    nix-direnv
  ];

  home.file = {
    ".gitconfig".source = git/.gitconfig;
    ".bashrc".source = bash/.bashrc;
    ".profile".source = bash/.profile;
  };

  programs.home-manager.enable = true;
}

Please refer to the following for how to use home-manager.
We will omit the details in this article.

https://zenn.dev/kuu/articles/20250204_introduce-home-manager

https://zenn.dev/trifolium/articles/642043cbae5f21

3.2 Configure direnv

Create an .envrc file as follows:

Folder structure
zenn_contents/
  ├─ articles/
  ├─ books/
  ├─ images/
  ├─ flake.nix
+ └─ .envrc
.envrc
use flake

Move to zenn_contents and then run direnv allow.

Bash
cd your_path/zenn_contents
direnv allow

Now, whenever you move to zenn_contents, the environment defined by Nix will automatically start.

4. VSCode Settings

4.1 Define a Zenn-specific Environment with Profiles

Using the Profile feature, you can define extensions, settings, etc., all at once, making it easy to create a dedicated environment for a specific purpose.

Zenn Profile screen

4.1.1 Open the Settings Screen

Go to File > Preferences > Profiles > Profiles to open the profile settings screen.

Open Profile settings screen

4.1.2 Create a Profile

Select New Profile, enter "Zenn" (or any name) in the Name field, and click Create.

Create a profile for Zenn

4.1.3 Open the Profile

Go to File > Preferences > Profiles, and you will see the profile you just created available in addition to the Default profile.

Open Profile settings screen

I named mine Zenn.
Clicking on Zenn will make VSCode remember to use the Zenn profile for the currently open workspace.

4.1.4 Customize

Immediately after creating a profile, extensions and settings should be in a blank state.

If you install a new extension while in this state, it will not be installed in other environments (workspaces using the default profile).
This way, even if you install extensions only used for Zenn, you won't pollute other environments.

This behavior applies to settings and keyboard shortcuts as well.
(Convenient!)

There is also a feature to specify extensions/settings to apply across all profiles.
For details, please refer to the following:

https://code.visualstudio.com/docs/configure/profiles

https://zenn.dev/hacobell_dev/articles/52b383c05ab408

The extensions used for the convenient features introduced here are as follows:
(How to set up and use each extension will be explained in subsequent sections)

extensions.json
{
    "recommendations": [
        "mkhl.direnv",
        "nodamushi.udon",
        "negokaz.zenn-editor"
    ]
}

4.2 Improved Explorer Display & Preview Functionality

Use the Zenn Editor extension.

https://marketplace.visualstudio.com/items?itemName=negokaz.zenn-editor

4.2.1 Explorer Display

Normally, article filenames are managed by Slug, like 007bff63247432.md, making it hard to tell which article is which.

Explorer display before installing Zenn Editor

With the extension, the title is displayed.

Explorer display after installing Zenn Editor

4.2.2 Preview Functionality

Normally, you use Zenn CLI's "preview in browser" feature to check your articles.

With the Zenn Editor extension, you can preview directly in VSCode.

Preview screen with Zenn Editor extension

As a specification of Zenn, the following rules are defined for handling images:

  • Image files are placed in the /images directory directly under the repository
  • The path to an image file is written as ![](/images/~)

https://zenn.dev/zenn/articles/deploy-github-images

To easily insert images into articles, I use the Udon extension.

https://marketplace.visualstudio.com/items?itemName=nodamushi.udon

https://zenn.dev/nodamushi/articles/db57ccd5a6d5ba

Isn't another method (extension) good enough?

After trying various options, the Udon extension was the best for the WSL environment.

If you're interested in the evaluation process, please check here.

https://zenn.dev/trifolium/articles/c983fc42a138cf

4.3.1 Extension Settings

Add the following to settings.json:

Folder structure
zenn_contents/
  ├─ articles/
  ├─ books/
  ├─ images/
  ├─ flake.nix
  ├─ .envrc
+ └─ .vscode/
+      └─ settings.json
settings.json
{
    "udon.baseDirectories": [
        ["articles/*.md", "${workspaceFolder}/images/$fileBasenameNoExtension"]
    ],
    "udon.rule": [
        ["articles/*.md", "![](/${relImage:${workspaceFolder}})"],
        ["*.md", "![](${relImage})"],
        ["*", "${relImage:${workspaceFolder}}"]
    ]
}

4.3.2 Usage

By pressing Ctrl + Alt + V, you can insert an image as follows:

007bff63247432.md
Press `Ctrl + Alt + V` to insert an image.
![](/images/007bff63247432/007bff63247432-2025-8-25_2.webp)
Folder structure
 zenn_contents/
 ├─ articles/
 │   └─ 007bff63247432.md
 └─ images/
       └─ 007bff63247432/
            ├─ 007bff63247432-2025-8-25.webp
            ├─ 007bff63247432-2025-8-25_1.webp
+           └─ 007bff63247432-2025-8-25_2.webp

On Windows, you can take a screenshot with Windows Key + Shift + S and save it to the clipboard.

With this state, pasting it into an article (.md file) using Ctrl + Alt + V creates the image file, saves it, and sets the link all at once – very convenient.

4.4 Auto-Start Browser Preview

With the Zenn CLI feature, you can preview in the browser.

https://zenn.dev/zenn/articles/zenn-cli-guide#プレビューする

Specifically, the steps are as follows:

  • Run zenn preview in the terminal
  • Open localhost:8000 in the browser

It is tedious to run zenn preview every time you open the Zenn workspace in VSCode.
Therefore, I use VSCode's task feature.

https://code.visualstudio.com/docs/debugtest/tasks

https://zenn.dev/k_tabuchi/articles/13993a7653486d

4.4.1 Task Settings

Add the following to tasks.json:

Folder structure
zenn_contents/
  ├─ articles/
  ├─ books/
  ├─ images/
  ├─ flake.nix
  ├─ .envrc
  └─ .vscode/
       ├─ settings.json
+      └─ tasks.json
tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "auto-run my command",
            "type": "shell",
            "command": "zenn preview",
            "isBackground": true,
            "presentation": {
                "reveal": "never",
                "panel": "new",
                "focus": false
            },
            "runOptions": { "runOn": "folderOpen" }
        }
    ]
}

4.4.2 Verification

Close VSCode and reopen the Zenn workspace. You will see that zenn preview is automatically executed via auto-run my command.

Terminal immediately after startup

Detail screen of auto-run my command

You can preview articles by opening localhost:8000 in your browser.

Article preview in browser

Miscellaneous: My Usual Article Creation Workflow

For reference, here is my typical article writing routine while reviewing the usage of each feature introduced in this article.

  • Create a git branch

Create a branch with a name that roughly represents the article topic.

Bash
git checkout -b zenn-nix
  • Create an article file

Press the button below to create a new article file.

New article creation button

  • Write the article

Screenshot: Windows Key + Shift + s
Paste image: Ctrl + Alt + V

  • git commit
  • Send the full text to a chat AI (e.g., ChatGPT) for review
  • Restructure/correct the article
  • After corrections, git commit
  • Use a linter to unify the text format

I plan to write a separate article on linter settings when I have time.


Added on 2025/9/6.
I wrote it.

https://zenn.dev/trifolium/articles/5b01a68b80808b


  • Set publish time, git commit

Set published to true and write the desired publication date and time in published_at.

For topics, click on a topic displayed on the Zenn article in the browser and look for the notation "To specify this topic, enter ooo".

article.md
# Immediately after creating a new article
---
title: ""
emoji: "😽"
type: "tech" # tech: technical article / idea: idea
topics: []
published: false
---

# At time of publication
---
title: "Creating a Zenn Local Writing Environment with WSL × Nix × VSCode"
emoji: "💮"
type: "tech" # tech: technical article / idea: idea
topics: [nix, direnv, vscode, wsl, zenncli]
published: true
published_at: "2025-08-26 20:00"
---
  • git push
  • Create a PR on GitHub and merge to main branch
  • Article publication is confirmed!

Conclusion

In this article, I introduced the steps to build a local Zenn writing environment using Nix, home-manager, direnv, and VSCode (profiles, extensions, tasks).

With this setup, you can apply Zenn-specific extensions and settings without polluting other projects or your user environment.
It also makes it easier to utilize editor support such as automatic image insertion and text proofreading.


Previously, I built my environment with Dev Containers, but for the purpose of an "isolated environment where Zenn CLI works," I felt containers were a bit overkill and switched to Nix.

devShells is convenient because it keeps Zenn CLI in a contained environment while still allowing you to use existing tools.
It is fast to start and simple to configure.

https://zenn.dev/trifolium/articles/5e7cd43586b68a

I hope this article is helpful to you.


Added on 2025/9/6.
I wrote an article about linters.
It is a continuation of this article.

https://zenn.dev/trifolium/articles/5b01a68b80808b

Discussion