Rework common profile into module system

This commit is contained in:
Charlotte Van Petegem 2020-12-05 13:39:22 +01:00
parent 9d2e54547c
commit 9fdec35027
No known key found for this signature in database
GPG key ID: 019E764B7184435A
29 changed files with 288 additions and 214 deletions

21
modules/bluetooth.nix Normal file
View file

@ -0,0 +1,21 @@
{ config, lib, pkgs, ... }:
{
options.chvp.bluetooth.enable = lib.mkOption {
default = false;
example = true;
};
config = lib.mkIf config.chvp.bluetooth.enable {
chvp.zfs.systemLinks = [{ path = "/var/lib/bluetooth"; type = "cache"; }];
hardware.bluetooth.enable = true;
services.blueman.enable = true;
hardware.pulseaudio.extraModules = [ pkgs.pulseaudio-modules-bt ];
hardware.pulseaudio.package = pkgs.pulseaudioFull;
home-manager.users.charlotte = lib.mkIf config.chvp.bluetooth.enable ({ ... }: {
services.blueman-applet.enable = true;
});
};
}

View file

@ -3,13 +3,20 @@
{
imports = [
./default/secret.nix
./bluetooth.nix
./docker.nix
./eid.nix
./git.nix
./global-mailer.nix
./neovim.nix
./nix.nix
./nginx.nix
./ovh.nix
./smartd.nix
./ssh.nix
./sshd.nix
./syncthing-server.nix
./tmux.nix
./zfs.nix
./zsh.nix
];
@ -54,6 +61,18 @@
ripgrep
];
i18n = {
defaultLocale = "en_IE.UTF-8";
extraLocaleSettings = {
LC_TIME = "en_GB.UTF-8";
};
};
console = {
font = "Lat2-Terminus16";
keyMap = "us";
};
users = {
mutableUsers = false;
defaultUserShell = pkgs.zsh;
@ -62,7 +81,7 @@
isNormalUser = true;
home = "/home/charlotte";
description = "Charlotte Van Petegem";
extraGroups = [ "wheel" "systemd-journal" ];
extraGroups = [ "wheel" "systemd-journal" ] ++ lib.optionals config.chvp.graphical [ "input" "video" ];
};
};
};

16
modules/eid.nix Normal file
View file

@ -0,0 +1,16 @@
{ config, lib, pkgs, ... }:
{
options.chvp.eid.enable = lib.mkOption {
default = false;
example = true;
};
config = lib.mkIf config.chvp.eid.enable {
environment.systemPackages = [ pkgs.eid-mw ];
services.pcscd = {
enable = true;
plugins = [ pkgs.ccid ];
};
};
}

21
modules/global-mailer.nix Normal file
View file

@ -0,0 +1,21 @@
{ config, lib, pkgs, ... }:
{
options.chvp.globalMailer.enable = lib.mkOption {
default = false;
example = true;
};
config = lib.mkIf config.chvp.smartd.enable {
services.ssmtp = {
enable = true;
authUser = "webmaster@vanpetegem.me";
authPassFile = "/data/var/secrets/ssmtp-mail-pass";
domain = "${config.networking.hostName}.vanpetegem.me";
hostName = "mail.vanpetegem.me:465";
root = "webmaster@vanpetegem.me";
setSendmail = true;
useTLS = true;
};
};
}

216
modules/neovim.nix Normal file
View file

@ -0,0 +1,216 @@
{ config, lib, pkgs, ... }:
let
customPlugins = {
snow-color-theme = pkgs.vimUtils.buildVimPlugin {
name = "snow";
src = pkgs.fetchFromGitHub {
owner = "nightsense";
repo = "snow";
rev = "f9800e987e404efed4748fe8098e04ddbec9770b";
sha256 = "099fky1bpppac5785bhx1jc26gfpm8n837p8487j1rf1lwq83q33";
};
};
};
jdtls = import ../packages/jdtls/default.nix { inherit pkgs; stdenv = pkgs.stdenv; };
kotlinls = import ../packages/kotlin-language-server/default.nix { inherit pkgs; };
base = home: {
home.sessionVariables = { EDITOR = "nvim"; };
programs.neovim = {
enable = true;
extraConfig = ''
set autoread
"" Theming
set termguicolors
set background=light
colorscheme snow
"" General settings
" Undo over sessions
set undofile
set undodir=${config.chvp.cachePrefix}${home}/.cache/nvim/undo
" Automatically save sessions on exit and load them on start
function! MakeSession()
let b:sessiondir = "${config.chvp.cachePrefix}${home}/.local/share/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 = "${config.chvp.cachePrefix}${home}/.local/share/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()
au VimLeave * :call MakeSession()
endif
"" 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
"" Fuzzy search in vim
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>
'';
plugins = with pkgs.vimPlugins // customPlugins; [
{
plugin = ale;
config = ''
let g:ale_fix_on_save = 1
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
'' + (lib.optionalString config.chvp.graphical ''
\ 'javascript': ['eslint', 'remove_trailing_lines', 'trim_whitespace'],
\ 'ledger': ['trim_whitespace'],
\ 'nix': ['nixpkgs-fmt', 'remove_trailing_lines', 'trim_whitespace'],
\ 'ruby': ['rubocop', 'remove_trailing_lines', 'trim_whitespace'],
\ 'typescript': ['eslint', 'remove_trailing_lines', 'trim_whitespace'],
\ 'vue': ['prettier', 'remove_trailing_lines', 'trim_whitespace'],
'') + ''
\}
'';
}
auto-pairs
{
plugin = deoplete-nvim;
config = ''
let g:deoplete#enable_at_startup = 1
set completeopt+=noselect
'' + lib.optionalString config.chvp.graphical ''
au VimEnter * call deoplete#custom#option('omni_patterns', {
\ 'ledger': ['[a-zA-Z][a-zA-Z: ]*'],
\})
'';
}
editorconfig-vim
snow-color-theme
vim-nix
] ++ lib.optionals config.chvp.graphical [
kotlin-vim
{
plugin = LanguageClient-neovim;
config = ''
" Required for operations modifying multiple buffers like rename
set hidden
let g:LanguageClient_serverCommands = {
\ 'java': ['${jdtls}/bin/jdtls'],
\ 'javascript': ['${pkgs.nodePackages.javascript-typescript-langserver}/bin/javascript-typescript-stdio'],
\ 'kotlin': ['${kotlinls}/bin/kotlin-language-server'],
\ 'ruby': ['${pkgs.solargraph}/bin/solargraph', 'stdio'],
\ 'typescript': ['${pkgs.nodePackages.typescript-language-server}/bin/typescript-language-server', '--stdio'],
\ 'vue': ['${pkgs.nodePackages.vue-language-server}/bin/vls'],
\ }
function LC_maps()
if has_key(g:LanguageClient_serverCommands, &filetype)
nnoremap <buffer> <silent> K :call LanguageClient#textDocument_hover()<cr>
nnoremap <buffer> <silent> gd :call LanguageClient#textDocument_definition()<CR>
nnoremap <buffer> <silent> <F2> :call LanguageClient#textDocument_rename()<CR>
endif
endfunction
autocmd FileType * call LC_maps()
'';
}
vim-ledger
vim-ruby
vim-vue
yats-vim
];
extraPackages = with pkgs; [
nixpkgs-fmt
];
};
};
in
{
options.chvp.neovim = {
enable = lib.mkOption {
default = true;
example = false;
};
};
config = lib.mkIf config.chvp.neovim.enable {
home-manager.users.charlotte = { ... }: (base "/home/charlotte");
home-manager.users.root = { ... }: (base "/root");
};
}

105
modules/nix.nix Normal file
View file

@ -0,0 +1,105 @@
{ config, lib, pkgs, ... }:
let
baseDirenv = {
programs.direnv = {
enable = true;
enableZshIntegration = true;
enableNixDirenvIntegration = true;
};
};
baseUnfree = {
xdg.configFile."nixpkgs/config.nix".source = ./nix/unfree.nix;
};
baseNixIndex = {
home.packages = with pkgs; [ nix-index ];
programs.zsh.initExtra = ''
source ${pkgs.nix-index}/etc/profile.d/command-not-found.sh
'';
systemd.user = {
services.nix-index = {
Unit = {
Description = "Service to run nix-index";
};
Service = {
Type = "oneshot";
ExecStart = "${pkgs.nix-index}/bin/nix-index";
};
};
timers.nix-index = {
Unit = {
Description = "Timer that starts nix-index every two hours";
PartOf = [ "nix-index.service" ];
};
Timer = {
OnCalendar = "00/2:30";
};
Install = {
WantedBy = [ "default.target" ];
};
};
};
};
in
{
options.chvp.nix = {
enableDirenv = lib.mkOption {
default = true;
example = false;
};
enableFlakes = lib.mkOption {
default = true;
example = false;
};
enableUnfree = lib.mkOption {
default = false;
example = true;
};
# Note that this is only enabled for charlotte, until https://github.com/bennofs/nix-index/issues/143 is resolved.
enableNixIndex = lib.mkOption {
default = true;
example = false;
};
};
config = {
chvp.zfs.homeLinks =
(lib.optional config.chvp.nix.enableDirenv { path = ".local/share/direnv"; type = "cache"; }) ++
(lib.optional config.chvp.nix.enableNixIndex { path = ".cache/nix-index"; type = "cache"; });
chvp.zfs.systemLinks =
(lib.optional config.chvp.nix.enableDirenv { path = "/root/.local/share/direnv"; type = "cache"; });
nix = {
gc = {
automatic = true;
dates = "hourly";
options = "--delete-older-than 7d";
};
optimise = {
automatic = true;
dates = [ "hourly" ];
};
trustedUsers = [ "@wheel" ];
extraOptions = (lib.optionalString config.chvp.nix.enableDirenv ''
keep-outputs = true
keep-derivations = true
'') + (lib.optionalString config.chvp.nix.enableFlakes ''
experimental-features = nix-command flakes
'');
};
nixpkgs.config = lib.mkIf config.chvp.nix.enableUnfree (import ./nix/unfree.nix);
nixpkgs.overlays = lib.mkIf config.chvp.nix.enableFlakes [
(self: super: {
nix = super.nixUnstable;
})
];
home-manager.users.charlotte = { ... }:
(lib.optionalAttrs config.chvp.nix.enableDirenv baseDirenv) //
(lib.optionalAttrs config.chvp.nix.enableUnfree baseUnfree) //
(lib.optionalAttrs config.chvp.nix.enableNixIndex baseNixIndex);
home-manager.users.root = { ... }:
(lib.optionalAttrs config.chvp.nix.enableDirenv baseDirenv) //
(lib.optionalAttrs config.chvp.nix.enableUnfree baseUnfree);
};
}

1
modules/nix/unfree.nix Normal file
View file

@ -0,0 +1 @@
{ allowUnfree = true; }

25
modules/smartd.nix Normal file
View file

@ -0,0 +1,25 @@
{ config, lib, pkgs, ... }:
{
options.chvp.smartd.enable = lib.mkOption {
default = false;
example = true;
};
config = lib.mkIf config.chvp.smartd.enable {
chvp.globalMailer.enable = true;
environment.systemPackages = [ pkgs.smartmontools ];
services.smartd = {
enable = true;
autodetect = true;
notifications = {
mail = {
enable = true;
sender = "${config.networking.hostName}@vanpetegem.me";
recipient = "webmaster@vanpetegem.me";
};
wall.enable = false;
};
};
};
}

36
modules/tmux.nix Normal file
View file

@ -0,0 +1,36 @@
{ config, lib, ... }:
let
base = {
programs.tmux = {
enable = true;
clock24 = true;
extraConfig = ''
bind q kill-session
bind v run-shell "tmux setw main-pane-width $(($(tmux display -p '#{window_width}') * 70 / 100)); tmux select-layout main-vertical"
bind h run-shell "tmux setw main-pane-height $(($(tmux display -p '#{window_height}') * 70 / 100)); tmux select-layout main-horizontal"
set -g default-terminal "screen-256color"
set -sg escape-time 10
'';
keyMode = "vi";
tmuxinator.enable = lib.mkIf config.chvp.graphical true;
};
};
in
{
options.chvp.tmux.enable = lib.mkOption {
default = true;
example = false;
};
config = lib.mkIf config.chvp.tmux.enable {
home-manager.users.charlotte = { ... }: base // lib.optionalAttrs config.chvp.graphical {
xdg.configFile = {
"tmuxinator/accentor.yml".source = ./tmux/accentor.yml;
"tmuxinator/dodona.yml".source = ./tmux/dodona.yml;
"tmuxinator/mail.yml".source = ./tmux/mail.yml;
};
};
home-manager.users.root = { ... }: base;
};
}

36
modules/tmux/accentor.yml Normal file
View file

@ -0,0 +1,36 @@
name: accentor
project_root: "/home/charlotte/repos/accentor"
windows:
- api:
root: "/home/charlotte/repos/accentor/api"
layout: main-vertical
panes:
- nvim
- git status
- web:
root: "/home/charlotte/repos/accentor/web"
layout: main-vertical
panes:
- nvim
- git status
- android:
root: "/home/charlotte/repos/accentor/android"
layout: main-vertical
panes:
- nvim
- git status
- run:
layout: even-horizontal
panes:
- rails:
- cd api
- bundle exec rails s
- delayed_job:
- cd api
- bundle exec rails jobs:work
- vue:
- cd web
- yarn run serve
- postgres:
- cd api
- start-db

55
modules/tmux/dodona.yml Normal file
View file

@ -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-dockers

47
modules/tmux/mail.yml Normal file
View file

@ -0,0 +1,47 @@
# /home/charlotte/.config/tmuxinator/mail.yml
name: mail
root: ~/mail
# 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:
- main:
layout: main-vertical
panes:
- neomutt
- khal interactive

View file

@ -20,7 +20,6 @@
path = "${config.chvp.cachePrefix}${home}/.local/share/zsh/history";
};
initExtra = ''
source ${pkgs.nix-index}/etc/profile.d/command-not-found.sh
${pkgs.any-nix-shell}/bin/any-nix-shell zsh --info-right | source /dev/stdin
'';
oh-my-zsh = {