From 36ca746b47b5262c67555bb11e91476dc0bf3020 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Thu, 20 Feb 2020 17:55:03 +0100 Subject: [PATCH] Dev environment setup --- profiles/graphical/default.nix | 10 +- programs/direnv/README.md | 9 ++ programs/direnv/default.nix | 1 + programs/direnv/shells/dodona.nix | 33 ++++++ programs/direnv/shells/ledger.nix | 14 +++ programs/direnv/shells/nix.nix | 13 +++ programs/direnv/shells/vim-base.nix | 116 +++++++++++++++++++ programs/neovim/default.nix | 168 ++-------------------------- programs/sway/default.nix | 6 +- programs/tmux/default.nix | 1 + programs/tmux/dodona.yml | 55 +++++++++ 11 files changed, 260 insertions(+), 166 deletions(-) create mode 100644 programs/direnv/README.md create mode 100644 programs/direnv/shells/dodona.nix create mode 100644 programs/direnv/shells/ledger.nix create mode 100644 programs/direnv/shells/nix.nix create mode 100644 programs/direnv/shells/vim-base.nix create mode 100644 programs/tmux/dodona.yml diff --git a/profiles/graphical/default.nix b/profiles/graphical/default.nix index de6432e4..f862f344 100644 --- a/profiles/graphical/default.nix +++ b/profiles/graphical/default.nix @@ -40,18 +40,16 @@ ]; }; - users.users.charlotte.extraGroups = [ "networkmanager" "video" "input" ]; + virtualisation.docker.enable = true; + + users.users.charlotte.extraGroups = [ "docker" "video" "input" ]; environment.systemPackages = with pkgs; [ eid-mw ]; system.autoUpgrade.enable = true; home-manager.users.charlotte = { pkgs, ... }: { - nixpkgs = { - config = { - allowUnfree = true; - }; - }; + nixpkgs.config.allowUnfree = true; home = { packages = with pkgs; [ chromium diff --git a/programs/direnv/README.md b/programs/direnv/README.md new file mode 100644 index 00000000..4e355988 --- /dev/null +++ b/programs/direnv/README.md @@ -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. diff --git a/programs/direnv/default.nix b/programs/direnv/default.nix index f13f698e..87278a04 100644 --- a/programs/direnv/default.nix +++ b/programs/direnv/default.nix @@ -12,5 +12,6 @@ }; }; services.lorri.enable = true; + xdg.dataFile.nix-shells.source = ./shells; }; } diff --git a/programs/direnv/shells/dodona.nix b/programs/direnv/shells/dodona.nix new file mode 100644 index 00000000..4553e16b --- /dev/null +++ b/programs/direnv/shells/dodona.nix @@ -0,0 +1,33 @@ +let + pkgs = import {}; +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" + ''; + } diff --git a/programs/direnv/shells/ledger.nix b/programs/direnv/shells/ledger.nix new file mode 100644 index 00000000..628b5bfe --- /dev/null +++ b/programs/direnv/shells/ledger.nix @@ -0,0 +1,14 @@ +let + pkgs = import {}; + 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"; } ]; + }; + }) + ]; + } diff --git a/programs/direnv/shells/nix.nix b/programs/direnv/shells/nix.nix new file mode 100644 index 00000000..efd2cffa --- /dev/null +++ b/programs/direnv/shells/nix.nix @@ -0,0 +1,13 @@ +let + pkgs = import {}; +in + pkgs.mkShell { + buildInputs = with pkgs; [ + (neovim.override { + configure = { + customRC = baseVimConfig.customRC; + vam.pluginDictionaries = (baseVimConfig.vam.pluginDictionaries or []); + }; + }) + ]; + } diff --git a/programs/direnv/shells/vim-base.nix b/programs/direnv/shells/vim-base.nix new file mode 100644 index 00000000..4ad432e3 --- /dev/null +++ b/programs/direnv/shells/vim-base.nix @@ -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 :call FzyFiles() + nnoremap :call FzyGrep() + ''; + vam.knownPlugins = pkgs.vimPlugins; + vam.pluginDictionaries = [ { name = "vim-nix"; } ]; +} diff --git a/programs/neovim/default.nix b/programs/neovim/default.nix index ad44e47a..9739c9e2 100644 --- a/programs/neovim/default.nix +++ b/programs/neovim/default.nix @@ -1,160 +1,14 @@ with import {}; -let - neovim = pkgs.neovim.override { - configure = { - 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 - - " Filetype specific settings - - autocmd FileType javascript call TwoSpaces() - autocmd FileType less call TwoSpaces() - autocmd FileType css call TwoSpaces() - autocmd FileType scss call TwoSpaces() - autocmd FileType html call TwoSpaces() - autocmd FileType ruby call TwoSpaces() - autocmd FileType yaml call TwoSpaces() - autocmd FileType eruby call TwoSpaces() - autocmd FileType haskell call TwoSpaces() - autocmd FileType json call TwoSpaces() - autocmd FileType typescript call TwoSpaces() - - function TwoSpaces() - setlocal tabstop=2 - setlocal shiftwidth=2 - setlocal softtabstop=2 - endfunction - - "" 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 :call FzyFiles() - nnoremap :call FzyGrep() - ''; - - vam.knownPlugins = pkgs.vimPlugins; - vam.pluginDictionaries = [ - { - names = [ - "vim-ledger" - "vim-nix" - ]; - } - ]; - }; - }; -in - { - home-manager.users.charlotte = { pkgs, ... }: { - nixpkgs = { - config = { - packageOverrides = pkgs: { - neovim = neovim; - }; +{ + home-manager.users.charlotte = { pkgs, ... }: { + nixpkgs.overlays = [ + (self: super: { + neovim = super.neovim.override { + configure = (import ../direnv/shells/vim-base.nix { pkgs = self; }) ; }; - }; - home.packages = [ pkgs.neovim ]; - }; - } + }) + ]; + home.packages = [ pkgs.neovim ]; + }; +} diff --git a/programs/sway/default.nix b/programs/sway/default.nix index 5f513f1c..e2c996c0 100644 --- a/programs/sway/default.nix +++ b/programs/sway/default.nix @@ -207,9 +207,9 @@ in }; home-manager.users.charlotte = { pkgs, ... }: { - nixpkgs.config.packageOverrides = pkgs: { - waybar = pkgs.waybar.override { pulseSupport = true; mpdSupport = false; }; - }; + nixpkgs.overlays = [ + (self: super: { waybar = super.waybar.override { pulseSupport = true; mpdSupport = false; }; }) + ]; home.packages = [ color-picker ]; xdg.configFile."sway/config".text = '' # Config for sway diff --git a/programs/tmux/default.nix b/programs/tmux/default.nix index cee795a5..4e418a16 100644 --- a/programs/tmux/default.nix +++ b/programs/tmux/default.nix @@ -15,6 +15,7 @@ }; xdg.configFile = { "tmuxinator/accentor.yml".source = ./accentor.yml; + "tmuxinator/dodona.yml".source = ./dodona.yml; }; }; } diff --git a/programs/tmux/dodona.yml b/programs/tmux/dodona.yml new file mode 100644 index 00000000..091104de --- /dev/null +++ b/programs/tmux/dodona.yml @@ -0,0 +1,55 @@ +# /home/charlotte/.config/tmuxinator/dodona.yml + +name: dodona +root: ~/repos/dodona/dodona + +# Optional tmux socket +# socket_name: foo + +# Note that the pre and post options have been deprecated and will be replaced by +# project hooks. + +# Project hooks +# Runs on project start, always +# on_project_start: command +# Run on project start, the first time +# on_project_first_start: command +# Run on project start, after the first time +# on_project_restart: command +# Run on project exit ( detaching from tmux session ) +# on_project_exit: command +# Run on project stop +# on_project_stop: command + +# Runs in each window and pane before window/pane specific commands. Useful for setting up interpreter versions. +# pre_window: rbenv shell 2.0.0-p247 + +# Pass command line options to tmux. Useful for specifying a different tmux.conf. +# tmux_options: -f ~/.tmux.mac.conf + +# Change the command to call tmux. This can be used by derivatives/wrappers like byobu. +# tmux_command: byobu + +# Specifies (by name or index) which window will be selected on project startup. If not set, the first window is used. +# startup_window: editor + +# Specifies (by index) which pane of the specified window will be selected on project startup. If not set, the first pane is used. +# startup_pane: 1 + +# Controls whether the tmux session should be attached to automatically. Defaults to true. +# attach: false + +windows: + - editor: + layout: main-vertical + panes: + - nvim + - git status + - server: + layout: even-horizontal + panes: + - bundle exec rails s + - bundle exec rails jobs:work + - ./bin/webpack-dev-server + - logs: tail -f log/development.log + - db: start-db