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
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:
- Install nix on your system.
- Have
direnv
installed on your system (follow their instructions). Ideally usenix-direnv
for faster and more persistent caching. You do not need NixOS as the Nix package manager can be installed anywhere, as canhome-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;
};
}
- 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 - Enter the repository folder.
- Modify the flake to include what you want.
- Run
direnv allow .
and it will drop you into the containerised environment.
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.- Default packages:
numpy, scipy, matplotlib
. - Option for
Jupyter
. - Uses black for code formatting, mypy for static type analysis and flake8 for linting.
- Default packages:
Node/JS/TS
with pre-installed packages fornodejs, yarn
.- The packages installed here are minimal since I prefer to use
package.json
s for each individual project. - Uses Prettier for code formatting of HTML/Markdown/JS/TS/JSON etc. by default.
- The packages installed here are minimal since I prefer to use
TeXLive 2022 Full
, withLTeX-LS
and VSCode settings forLaTeX Workshop
andLTeX
extensions/- Easy modification of development environments for each language.
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".
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 insideflake.nix
to be consumed bydevShells
.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 disablereproducibleBuild
for potential speedups
- For example, configuring python311 to
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).
Currently this is WIP, and my main goal is making sure this flake works well with VSCode.
- 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.
Untested, I don't use vim for serious development, so I'm unaware of many solutions.
- Install vim-direnv with your plugin manager.
- Install emacs-direnv.
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.