Dev environment setup

This commit is contained in:
Charlotte Van Petegem 2020-02-20 17:55:03 +01:00
parent e1afafff33
commit 36ca746b47
11 changed files with 260 additions and 166 deletions

View file

@ -0,0 +1,9 @@
# Setting up a new dev environment
* Create a new `*.nix` file in the shells directory that describes the environment (this is the hard part).
* Execute `lorri init` in the base directory of your project. This will create a `.envrc` file and `shell.nix` file.
* Edit the `shell.nix` file to just `import /home/charlotte/.local/share/nix-shells/your-new-file.nix`
* Execute `direnv allow` to load the `.envrc` file which in turn uses `lorri` to load your `shell.nix` file.

View file

@ -12,5 +12,6 @@
};
};
services.lorri.enable = true;
xdg.dataFile.nix-shells.source = ./shells;
};
}

View file

@ -0,0 +1,33 @@
let
pkgs = import <nixpkgs> {};
in
pkgs.mkShell {
buildInputs = with pkgs; [
ruby
yarn
nodejs-12_x
libmysqlclient
zlib
(pkgs.writeScriptBin "start-db" ''
#!${pkgs.zsh}/bin/zsh
_sighandler() {
docker stop dodona-db
}
trap _sighandler SIGINT
trap _sighandler SIGTERM
trap _sighandler SIGHUP
docker run --name dodona-db -p 3306:3306 --rm -v $(git rev-parse --show-toplevel)/tmp/db:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=dodona mariadb:latest &
child=$!
wait $child
# We wait two times, because the first wait exits when the process receives a signal. The process might have finished though, so we ignore errors.
wait $child 2>/dev/null
'')
];
shellHook = ''
export DATABASE_URL="mysql2://root:dodona@127.0.0.1:3306/dodona"
'';
}

View file

@ -0,0 +1,14 @@
let
pkgs = import <nixpkgs> {};
baseVimConfig = import ./vim-base.nix { inherit pkgs; };
in
pkgs.mkShell {
buildInputs = with pkgs; [
(neovim.override {
configure = {
customRC = baseVimConfig.customRC;
vam.pluginDictionaries = (baseVimConfig.vam.pluginDictionaries or []) ++ [ { name = "vim-ledger"; } ];
};
})
];
}

View file

@ -0,0 +1,13 @@
let
pkgs = import <nixpkgs> {};
in
pkgs.mkShell {
buildInputs = with pkgs; [
(neovim.override {
configure = {
customRC = baseVimConfig.customRC;
vam.pluginDictionaries = (baseVimConfig.vam.pluginDictionaries or []);
};
})
];
}

View file

@ -0,0 +1,116 @@
{ pkgs, ... }:
{
customRC = ''
set autoread
"" Theming
set background=light
"" General settings
" Undo over sessions
set undofile
set undodir=~/.cache/nvimundo
" Automatically save sessions on exit and load them on start
function! MakeSession()
let b:sessiondir = $HOME . "/.config/nvim/sessions" . getcwd()
if (filewritable(b:sessiondir) != 2)
exe 'silent !mkdir -p ' b:sessiondir
redraw!
endif
let b:filename = b:sessiondir . '/session.vim'
exe "mksession! " . b:filename
endfunction
function! LoadSession()
let b:sessiondir = $HOME . "/.config/nvim/sessions" . getcwd()
let b:sessionfile = b:sessiondir . "/session.vim"
if (filereadable(b:sessionfile))
exe 'source ' b:sessionfile
else
echo "No session loaded."
endif
endfunction
if(argc() == 0)
au VimEnter * nested :call LoadSession()
endif
au VimLeave * :call MakeSession()
"" Filetype configuration
" Base settings for all files
syntax enable
set number
set showcmd
set scrolloff=8
set expandtab
set tabstop=4
set shiftwidth=4
set linebreak
set list
set listchars=tab:·\ ,trail:·
set inccommand=split
set clipboard=unnamedplus
filetype plugin indent on
"" Plugin configuration
function! s:completedFiles(winid, filename, ...) abort
bdelete!
call win_gotoid(a:winid)
if filereadable(a:filename)
let lines = readfile(a:filename)
if !empty(lines)
exe ':e ' . lines[0]
endif
call delete(a:filename)
endif
endfunction
function! FzyFiles()
let file = tempname()
let winid = win_getid()
let cmd = split(&shell) + split(&shellcmdflag) + ["${pkgs.ripgrep.out}/bin/rg --files --hidden -g '!/.git' --smart-case | ${pkgs.fzy.out}/bin/fzy > " . file]
let F = function('s:completedFiles', [winid, file])
botright 10 new
call termopen(cmd, {'on_exit': F})
startinsert
endfunction
function! s:completedGrep(winid, filename, ...) abort
bdelete!
call win_gotoid(a:winid)
if filereadable(a:filename)
let lines = readfile(a:filename)
if !empty(lines)
let list = split(lines[0], ':')
let file = list[0]
let line = list[1]
exe ':e ' . file
exe line
endif
call delete(a:filename)
endif
endfunction
function! FzyGrep()
let file = tempname()
let winid = win_getid()
let cmd = split(&shell) + split(&shellcmdflag) + ["${pkgs.ripgrep.out}/bin/rg --vimgrep --hidden -g '!/.git' '^' | ${pkgs.fzy.out}/bin/fzy > " . file]
let F = function('s:completedGrep', [winid, file])
botright 10 new
call termopen(cmd, {'on_exit': F})
startinsert
endfunction
nnoremap <C-f> :call FzyFiles()<CR>
nnoremap <C-g> :call FzyGrep()<CR>
'';
vam.knownPlugins = pkgs.vimPlugins;
vam.pluginDictionaries = [ { name = "vim-nix"; } ];
}