Skip to content
/ development-flake Public template

Simple setup for direnv and C/C++/Python/JS/LaTeX

Notifications You must be signed in to change notification settings

chpxu/development-flake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Development Template with direnv

Opinionated flake for development of various things I work on using multiple languages/frameworks/tools. Uses flake-utils, direnv and nix-direnv. The motivation for this is to create an environment which is easy to use

Workflow

This flake is intended to fit with my workflow, which is with Visual Studio Code, NixOS and direnv. This project is not intended to be a replacement or alternative to excellent projects such as direnv, devenv, lorri etc. The flake setups up a reproducible development environment for different programming contexts, and aims to be as declarative as possible whilst allowing some flexibility.

To use it:

  1. Install nix on your system.
  2. Have direnv installed on your system (follow their instructions). Ideally use nix-direnv for faster and more persistent caching. You do not need NixOS as the Nix package manager can be installed anywhere, as can home-manager. Example configurations:
## home-manager example configuration
# e.g. home.nix
programs = {
    direnv = {
      enable = true;
      enableZshIntegration = true;
      nix-direnv.enable = true;
    };

    zsh.enable = true;
  };

# ====
# System (NixOS) example configuration:
{
  programs.direnv = {
    enable = true;
    nix-direnv.enable = true;
  };
}
  1. Click "Use this template" on GitHub, then "Create a new repository". Follow the steps there, then clone your repository to somewhere locally on your own system
  2. Enter the repository folder.
  3. Modify the flake to include what you want.
  4. Run direnv allow . and it will drop you into the containerised environment.

Features

  • C/C++ based off fufexan's config
    • Summary: GCC or Clang/LLVM C/C++ development environment.
  • Python with pre-installed packages intended for scientific work and visualisation.
  • Node/JS/TS with pre-installed packages for nodejs, yarn.
    • The packages installed here are minimal since I prefer to use package.jsons for each individual project.
    • Uses Prettier for code formatting of HTML/Markdown/JS/TS/JSON etc. by default.
  • TeXLive 2022 Full, with LTeX-LS and VSCode settings for LaTeX Workshop and LTeX extensions/
  • Easy modification of development environments for each language.

Configuring for your own use

To minimise clutter with projects, the majority of configuration is done inside the nix folder, with the flake.nix (and corresponding lockfile) left in the root of the directory. This section of the README can be considered to be the "Documentation".

Modifying flake.nix

The flake.nix file brings all the configuration together and initialises the development shell: that is its only function. You might want to modify it if you want it to build a derivation for your use case specifically, or change what is installed, for example.

The nix folder structure looks something like this:

.
└── nix/
    ├── default.nix
    ├── packages/
    │   ├── c/
    │   │   ├── c.nix
    │   │   └── # other c/c++ configuration files
    │   ├── python/
    │   │   ├── python.nix
    │   │   └── # other python configuration files
    │   ├── js/
    │   │   ├── js.nix
    │   │   └── # other js configuration files
    │   └── #  other languages
    ├── overlays/
    │   └── default.nix
    └── misc/
        ├── write_vscode_settings.nix
        ├── helper.nix
        └── # other files
  • default.nix is the file which imports and includes everything from all the other files and sets up package configuration, shellHook, vscode configuration etc. This file is then included inside flake.nix to be consumed by devShells.
  • packages/<language> folders contain nix files that detail the relevant packages to be installed.
  • overlays folder contains, well, any overlays you might want to use.
    • For example, configuring python311 to enableOptimisations and disable reproducibleBuild for potential speedups
  • misc folder contains any general functions written to be used across the project (helper.nix), and any configuration that does not directly impact the shell itself (e.g. editor settings).

Editor/IDE Integration

Currently this is WIP, and my main goal is making sure this flake works well with VSCode.

Visual Studio Code

  1. Have the direnv extension installed (either globally or in your workspace). Ensure you trust your workspace so it can execute shell scripts.

The repository contains a file misc/write_vscode_settings.nix which converts sets of Nix expressions to a JSON string, and then writes to .vscode/settings.json in the directory where the flake is located. The file created is editable which means you can mess around with settings after the original file is created, however the file is not prettified and you may want external tools like jq or an extension like Prettier to auto-format it back to a readable state.

(Neo)Vim

Untested, I don't use vim for serious development, so I'm unaware of many solutions.

  1. Install vim-direnv with your plugin manager.

Emacs

  1. Install emacs-direnv.

Contributing

Thanks for viewing this repo!

I don't really use anything other than NixOS and VSCode. I don't do development on Windows anymore. Extending the flake to cope with some other editors or platforms would be greatly appreciated and would help a bunch of others if they ever happen to come across this.

Other niceties

About

Simple setup for direnv and C/C++/Python/JS/LaTeX

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published