From 91fb4f28ef5d87e8bcf7749928d30ba4a9cbbd34 Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Sun, 19 Feb 2023 17:50:35 +0300 Subject: 2023-02-19 --- modules/common/profiles/default.nix | 90 ++++++++++++++++++++ modules/common/profiles/dev/containers.nix | 76 +++++++++++++++++ modules/common/profiles/dev/default.nix | 89 ++++++++++++++++++++ modules/common/profiles/dev/editorconfig.ini | 83 ++++++++++++++++++ modules/common/profiles/dev/gdbinit | 41 +++++++++ modules/common/profiles/dev/ghci.conf | 35 ++++++++ modules/common/profiles/dev/pystartup.py | 121 +++++++++++++++++++++++++++ modules/common/profiles/dev/sql.nix | 101 ++++++++++++++++++++++ modules/common/profiles/headful.nix | 107 +++++++++++++++++++++++ modules/common/profiles/headless.nix | 23 +++++ 10 files changed, 766 insertions(+) create mode 100644 modules/common/profiles/default.nix create mode 100644 modules/common/profiles/dev/containers.nix create mode 100644 modules/common/profiles/dev/default.nix create mode 100644 modules/common/profiles/dev/editorconfig.ini create mode 100644 modules/common/profiles/dev/gdbinit create mode 100644 modules/common/profiles/dev/ghci.conf create mode 100644 modules/common/profiles/dev/pystartup.py create mode 100644 modules/common/profiles/dev/sql.nix create mode 100644 modules/common/profiles/headful.nix create mode 100644 modules/common/profiles/headless.nix (limited to 'modules/common/profiles') diff --git a/modules/common/profiles/default.nix b/modules/common/profiles/default.nix new file mode 100644 index 0000000..06ddaf4 --- /dev/null +++ b/modules/common/profiles/default.nix @@ -0,0 +1,90 @@ +{ + config, + lib, + pkgs, + this, + ... +}: +with lib; let + cfg = config.nixfiles.modules.profiles.default; +in { + imports = [ + ./dev + ./headful.nix + ./headless.nix + (mkAliasOptionModule ["colourScheme"] [ + "nixfiles" + "modules" + "profiles" + "default" + "colourScheme" + ]) + ]; + + options.nixfiles.modules.profiles.default = { + enable = + mkEnableOption "The most default profile of them all." + // { + default = true; + }; + + colourScheme = let + mkColour = default: + mkOption { + type = types.str; + inherit default; + description = "Colour in a standard hexadecimal notation."; + example = "#000000"; + }; + in rec { + black = mkColour "#161719"; + red = mkColour "#cc6666"; + green = mkColour "#b5bd68"; + yellow = mkColour "#f0c674"; + blue = mkColour "#81a2be"; + magenta = mkColour "#b294bb"; + cyan = mkColour "#8abeb7"; + white = mkColour "#c5c8c6"; + + brightBlack = mkColour "#969896"; + brightRed = mkColour "#cc6666"; + brightGreen = mkColour "#b5bd68"; + brightYellow = mkColour "#f0c674"; + brightBlue = mkColour "#81a2be"; + brightMagenta = mkColour "#b294bb"; + brightCyan = mkColour "#8abeb7"; + brightWhite = mkColour "#ffffff"; + + background = black; + foreground = white; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + { + assertion = !(with this; isHeadless && isHeadful); + message = '' + The configuration cannot be both "headful" and "headless" at the same + time. + ''; + } + ]; + + nixfiles.modules = { + htop.enable = true; + tmux.enable = true; + vim.enable = true; + }; + + time.timeZone = "Europe/Moscow"; + + environment.systemPackages = with pkgs; [ + ddrescue + file + git + gnupg + tree + ]; + }; +} diff --git a/modules/common/profiles/dev/containers.nix b/modules/common/profiles/dev/containers.nix new file mode 100644 index 0000000..cc24ab3 --- /dev/null +++ b/modules/common/profiles/dev/containers.nix @@ -0,0 +1,76 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; let + cfg = config.nixfiles.modules.profiles.dev.containers; +in { + options.nixfiles.modules.profiles.dev.containers.enable = + mkEnableOption "Tools for working with containers and container orchestration" + // { + default = config.nixfiles.modules.profiles.dev.default.enable; + }; + + config = mkIf cfg.enable { + hm = { + home = { + sessionVariables = { + MINIKUBE_IN_STYLE = "false"; + WERF_DEV = "true"; + WERF_INSECURE_REGISTRY = "true"; + WERF_LOG_DEBUG = "true"; + WERF_LOG_PRETTY = "false"; + WERF_LOG_VERBOSE = "true"; + WERF_SYNCHRONIZATION = ":local"; + WERF_TELEMETRY = "false"; + }; + + packages = with pkgs; [ + argocd + chart-testing + clusterctl + cmctl + datree + helm + istioctl + kubeconform + kubectl + kubectl-doctor + kubectl-images + kubectl-tree + kubectx + kubelogin + kubent + kubescape + kubeseal + kubespy + minikube + skaffold + skopeo + stern + telepresence + werf + ]; + }; + + programs.bash = { + shellAliases = with pkgs; { + b = "${buildah}/bin/buildah"; + h = "${helm}/bin/helm"; + k = "${kubectl}/bin/kubectl"; + kns = "${kubectx}/bin/kubens"; + ktx = "${kubectx}/bin/kubectx"; + }; + initExtra = mkAfter '' + _complete_alias b _buildah buildah + _complete_alias h __start_helm helm + _complete_alias k __start_kubectl kubectl + _complete_alias kns _kube_namespaces kubens + _complete_alias ktx _kube_contexts kubectx + ''; + }; + }; + }; +} diff --git a/modules/common/profiles/dev/default.nix b/modules/common/profiles/dev/default.nix new file mode 100644 index 0000000..b05aeac --- /dev/null +++ b/modules/common/profiles/dev/default.nix @@ -0,0 +1,89 @@ +{ + config, + lib, + pkgs, + this, + ... +}: +with lib; let + cfg = config.nixfiles.modules.profiles.dev.default; +in { + imports = [ + ./containers.nix + ./sql.nix + ]; + + options.nixfiles.modules.profiles.dev.default.enable = + mkEnableOption "Catch-all profile for stuff related to software development and etc."; + + config = mkIf cfg.enable { + nixfiles.modules = { + bat.enable = true; + curl.enable = true; + direnv.enable = true; + git.client.enable = true; + gnupg.enable = true; + nmap.enable = true; + wget.enable = true; + }; + + hm.home = { + file = { + ".editorconfig".source = ./editorconfig.ini; + + ".gdbinit".source = ./gdbinit; + + ".ghc/ghci.conf".source = ./ghci.conf; + + ".stack/config.yaml".text = generators.toYAML {} { + templates.params = rec { + author-name = my.fullname; + author-email = my.email; + copyright = "Copyright (c) ${author-name} <${author-email}>"; + github-username = my.username; + }; + }; + + ".stack/global-project/stack.yaml".text = generators.toYAML {} { + packages = []; + resolver = "lts-20.3"; + }; + }; + + sessionVariables = with config.dirs; rec { + CABAL_DIR = "${config.my.home}/.cabal"; + CABAL_CONFIG = pkgs.writeText "cabal-config" '' + repository hackage.haskell.org + url: https://hackage.haskell.org/ + secure: True + + jobs: $ncpus + + remote-repo-cache: ${CABAL_DIR}/packages + + world-file: ${CABAL_DIR}/world + + logs-dir: ${CABAL_DIR}/logs + build-summary: ${CABAL_DIR}/logs/build.log + + installdir: ${CABAL_DIR}/bin + extra-prog-path: ${CABAL_DIR}/bin + ''; + + STACK_ROOT = "${config.my.home}/.stack"; + + CARGO_HOME = "${config.my.home}/.cargo"; + + GOPATH = "${config.my.home}/.go"; + + PYTHONSTARTUP = ./pystartup.py; + }; + + packages = with pkgs; [ + htmlq + jq + yq + ]; + }; + }; +} diff --git a/modules/common/profiles/dev/editorconfig.ini b/modules/common/profiles/dev/editorconfig.ini new file mode 100644 index 0000000..17b0317 --- /dev/null +++ b/modules/common/profiles/dev/editorconfig.ini @@ -0,0 +1,83 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 80 +trim_trailing_whitespace = true + +[*.nix] +indent_size = 2 +indent_style = space + +[*.{S,s,asm}] +indent_size = 4 +indent_style = tab + +[*.{C,H,c,c++,cc,cpp,cxx,h,h++,hh,hpp,hxx}] +indent_size = 4 +indent_style = tab + +[*.{cl,clj,el,l,lisp,lsp,rkt,scm,ss}] +indent_size = 2 +indent_style = space + +[*.go] +indent_size = 4 +indent_style = tab + +[*.{py,pyx}] +indent_size = 4 +indent_style = space + +[*.{hs,lhs}] +indent_size = 2 +indent_style = space + +[*.{html,xhtml,xml}] +indent_size = 4 +indent_style = tab + +[*.json] +indent_size = 2 +indent_style = space + +[*.{yaml,yml}] +indent_size = 2 +indent_style = space + +[*.{toml,tml}] +indent_size = 4 +indent_style = space + +[*.{py,pyx}] +indent_size = 4 +indent_style = space +max_line_length = 72 + +[*.zig] +indent_size = 4 +indent_style = tab + +[configure.ac] +indent_size = 4 +indent_style = tab + +[{Makefile*,*.mk}] +indent_size = 4 +indent_style = tab + +[{CMakeLists.txt,*.cmake}] +indent_size = 8 +indent_style = tab + +[*.tex] +indent_size = 4 +indent_style = tab + +[*.{md,adoc,rtf,txt}] +indent_size = 4 +indent_style = tab diff --git a/modules/common/profiles/dev/gdbinit b/modules/common/profiles/dev/gdbinit new file mode 100644 index 0000000..e266236 --- /dev/null +++ b/modules/common/profiles/dev/gdbinit @@ -0,0 +1,41 @@ +set confirm off +set verbose off +set editing off + +set history expansion on + +set height 0 +set width 0 + +handle SIGALRM nostop print nopass +handle SIGBUS stop print nopass +handle SIGPIPE nostop print nopass +handle SIGSEGV stop print nopass + +set print address on +set print elements 0 +set print object on +set print pretty on +set print repeats 0 +set print static-members on +set print vtbl on + +set output-radix 10 + +set demangle-style gnu-v3 + +set disassembly-flavor intel + +alias iv=info variables + +alias da=disassemble + +define fs + finish + step +end + +define btc + backtrace + continue +end diff --git a/modules/common/profiles/dev/ghci.conf b/modules/common/profiles/dev/ghci.conf new file mode 100644 index 0000000..d672167 --- /dev/null +++ b/modules/common/profiles/dev/ghci.conf @@ -0,0 +1,35 @@ +:set -XBinaryLiterals +:set -XFlexibleContexts +:set -XNoMonomorphismRestriction + +:seti -XConstraintKinds +:seti -XDataKinds +:seti -XDeriveFunctor +:seti -XFlexibleInstances +:seti -XFunctionalDependencies +:seti -XGADTs +:seti -XLambdaCase +:seti -XMagicHash +:seti -XMultiParamTypeClasses +:seti -XMultiWayIf +:seti -XOverloadedLabels +:seti -XPackageImports +:seti -XPolyKinds +:seti -XRankNTypes +:seti -XScopedTypeVariables +:seti -XStandaloneDeriving +:seti -XTupleSections +:seti -XTypeFamilies +:seti -XTypeOperators +:seti -XUndecidableInstances + +:set +c +:set +m +:set +r +:set +s +:set +t + +:set prompt "\ESC[1;34m>\ESC[m\STX " +:set prompt-cont "\ESC[1;94m|\ESC[m\STX " + +:def hoogle \x -> pure (":!hoogle --color --count=10 \"" ++ x ++ "\"") diff --git a/modules/common/profiles/dev/pystartup.py b/modules/common/profiles/dev/pystartup.py new file mode 100644 index 0000000..adde66c --- /dev/null +++ b/modules/common/profiles/dev/pystartup.py @@ -0,0 +1,121 @@ +import atexit +import os +import readline +import rlcompleter +import sys +from code import InteractiveConsole +from tempfile import mkstemp + +readline.parse_and_bind("tab: complete") + + +class TermColors(dict): + color_templates = ( + ("Normal", "0"), + ("Black", "0;30"), + ("Red", "0;31"), + ("Green", "0;32"), + ("Brown", "0;33"), + ("Blue", "0;34"), + ("Purple", "0;35"), + ("Cyan", "0;36"), + ("LightGray", "0;37"), + ("DarkGray", "1;30"), + ("LightRed", "1;31"), + ("LightGreen", "1;32"), + ("Yellow", "1;33"), + ("LightBlue", "1;34"), + ("LightPurple", "1;35"), + ("LightCyan", "1;36"), + ("White", "1;37"), + ) + color_base = "\001\033[%sm\002" + + def __init__(self): + self.update(dict([(k, self.color_base % v) for k, v in self.color_templates])) + + +class Completer(object): + def save_history(self): + import readline + + readline.write_history_file(self.python_histfile) + + def __init__(self): + self.python_dir = os.path.expanduser("%s/python" % os.environ["XDG_DATA_HOME"]) + + if not os.path.exists(self.python_dir): + os.mkdir(self.python_dir) + + self.python_histfile = os.path.expanduser("%s/history" % self.python_dir) + + if os.path.exists(self.python_histfile): + readline.read_history_file(self.python_histfile) + + readline.set_history_length(1000) + atexit.register(self.save_history) + + +def DisplayHook(value): + if value is not None: + try: + import __builtin__ + + __builtin__._ = value + except ImportError: + __builtins__._ = value + + import pprint + + pprint.pprint(value) + del pprint + + +class EditableBufferInteractiveConsole(InteractiveConsole): + def __init__(self, *args, **kwargs): + self.last_buffer = [] + InteractiveConsole.__init__(self, *args, **kwargs) + + def runsource(self, source, *args): + self.last_buffer = [source.encode("utf-8")] + return InteractiveConsole.runsource(self, source, *args) + + def raw_input(self, *args): + line = InteractiveConsole.raw_input(self, *args) + + if line == EDIT_CMD: + tmp_fd, tmp_file = mkstemp(".py") + + os.write(tmp_fd, b"\n".join(self.last_buffer)) + os.close(tmp_fd) + + os.system("%s %s" % (EDITOR, tmp_file)) + + line = open(tmp_file).read() + + os.unlink(tmp_file) + tmp_file = "" + + lines = line.split("\n") + + for i in range(len(lines) - 1): + self.push(lines[i]) + + line = lines[-1] + return line + + +TC = TermColors() +ps1 = "%sλ%s %s>%s " +sys.ps1 = ps1 % (TC["Blue"], TC["Normal"], TC["White"], TC["Normal"]) +ps2 = " %s…%s %s>%s " +sys.ps2 = ps2 % (TC["Blue"], TC["Normal"], TC["White"], TC["Normal"]) +sys.displayhook = DisplayHook + +C = Completer() +EDITOR = os.environ.get("EDITOR", "vim") +EDIT_CMD = ":e" +C = EditableBufferInteractiveConsole(locals=locals()) +C.interact(banner="") + +sys.exit() diff --git a/modules/common/profiles/dev/sql.nix b/modules/common/profiles/dev/sql.nix new file mode 100644 index 0000000..7a2a09c --- /dev/null +++ b/modules/common/profiles/dev/sql.nix @@ -0,0 +1,101 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; let + cfg = config.nixfiles.modules.profiles.dev.sql; +in { + options.nixfiles.modules.profiles.dev.sql.enable = + mkEnableOption "SQL stuff and database management tools" + // { + default = config.nixfiles.modules.profiles.dev.default.enable; + }; + + config = mkIf cfg.enable { + hm = { + home.packages = with pkgs; [ + dbeaver + pgcli + litecli + ]; + + xdg = let + mainSection = { + destructive_warning = "True"; + enable_pager = "True"; + keyword_casing = "auto"; + less_chatty = "True"; + log_file = "/dev/null"; + log_level = "CRITICAL"; + multi_line = "False"; + syntax_style = "default"; + table_format = "fancy_grid"; + }; + + colorsSection = with config.colourScheme; { + "arg-toolbar" = "noinherit bold"; + "arg-toolbar.text" = "nobold"; + "bottom-toolbar" = "bg:${black} ${white}"; + "bottom-toolbar.off" = "bg:${black} ${brightBlack}"; + "bottom-toolbar.on" = "bg:${black} ${brightWhite}"; + "bottom-toolbar.transaction.failed" = "bg:${black} ${red} bold"; + "bottom-toolbar.transaction.valid" = "bg:${black} ${green} bold"; + "completion-menu.completion" = "bg:${black} ${white}"; + "completion-menu.completion.current" = "bg:${white} ${black}"; + "completion-menu.meta.completion" = "bg:${black} ${yellow}"; + "completion-menu.meta.completion.current" = "bg:${yellow} ${black}"; + "completion-menu.multi-column-meta" = "bg:${yellow} ${black}"; + "scrollbar" = "bg:${black}"; + "scrollbar.arrow" = "bg:${black}"; + "search" = "bg:${magenta} ${brightWhite}"; + "search-toolbar" = "noinherit bold"; + "search-toolbar.text" = "nobold"; + "search.current" = "bg:${green} ${brightWhite}"; + "selected" = "bg:${blue} ${brightWhite}"; + "system-toolbar" = "noinherit bold"; + }; + + mkCliConfig = { + name, + custom, + }: { + "${name}/config" = { + text = generators.toINI {} { + main = mainSection // custom; + colors = mapAttrs (_: v: "'${v}'") colorsSection; + }; + }; + }; + in { + configFile = mkMerge (map mkCliConfig [ + { + name = "pgcli"; + custom = { + auto_expand = "True"; + casing_file = "/dev/null"; + expand = "True"; + history_file = "/dev/null"; + keyring = "False"; + multi_line_mode = "psql"; + on_error = "STOP"; + prompt = "'\\u@\\h:\\d> '"; + vi = "True"; + }; + } + { + name = "litecli"; + custom = { + audit_log = "/dev/null"; + key_bindings = "vi"; + prompt = "'\\d> '"; + prompt_continuation = "'-> '"; + auto_vertical_output = "True"; + }; + } + ]); + }; + }; + }; +} diff --git a/modules/common/profiles/headful.nix b/modules/common/profiles/headful.nix new file mode 100644 index 0000000..eec14c5 --- /dev/null +++ b/modules/common/profiles/headful.nix @@ -0,0 +1,107 @@ +{ + config, + lib, + pkgs, + this, + ... +}: +with lib; let + cfg = config.nixfiles.modules.profiles.headful; +in { + options.nixfiles.modules.profiles.headful.enable = + mkEnableOption "headful profile" // {default = this.isHeadful;}; + + config = mkIf cfg.enable { + nixfiles.modules = { + profiles.dev.default.enable = true; + + alacritty.enable = true; + aria2.enable = true; + emacs.enable = true; + mpv.enable = true; + openssh.client.enable = true; + password-store.enable = true; + }; + + hm = { + home = { + file.".digrc".text = '' + +answer + +multiline + +recurse + ''; + + packages = with pkgs; [ + fd + ripgrep + ripgrep-all + sd + ]; + }; + + accounts.email = { + maildirBasePath = "${config.my.home}/mail"; + + accounts = let + mkAccount = attrs: + mkMerge [ + { + mbsync = { + enable = true; + create = "both"; + expunge = "both"; + patterns = ["*"]; + }; + msmtp.enable = true; + mu.enable = true; + } + attrs + ]; + + pass = path: "${pkgs.pass}/bin/pass show ${path}"; + in { + shire = mkAccount { + address = my.email; + gpg = { + inherit (my.pgp) key; + signByDefault = true; + encryptByDefault = false; + }; + + primary = true; + + imap.host = "shire.me"; + smtp.host = "shire.me"; + userName = "azahi@shire.me"; + passwordCommand = pass "email/shire.me/azahi"; + }; + + yahoo = mkAccount { + address = "a.gondor@yahoo.com"; + + imap.host = "imap.yahoo.com"; + smtp.host = "smtp.yahoo.com"; + userName = "a.gondor@yahoo.com"; + passwordCommand = pass "email/yahoo.com/a.gondor"; + }; + }; + }; + + programs = { + mbsync.enable = true; + msmtp.enable = true; + mu.enable = true; + }; + }; + + environment.systemPackages = with pkgs; [ + (aspellWithDicts (p: with p; [en ru])) + arping + dnsutils + inetutils + ldns + socat + tcpdump + ]; + }; +} diff --git a/modules/common/profiles/headless.nix b/modules/common/profiles/headless.nix new file mode 100644 index 0000000..cc7c326 --- /dev/null +++ b/modules/common/profiles/headless.nix @@ -0,0 +1,23 @@ +{ + config, + lib, + pkgs, + this, + ... +}: +with lib; let + cfg = config.nixfiles.modules.profiles.headless; +in { + options.nixfiles.modules.profiles.headless.enable = + mkEnableOption "headless profile" // {default = this.isHeadless;}; + + config = mkIf cfg.enable { + hm.home.file = { + ".hushlogin".text = ""; + ".bash_history".source = + config.hm.lib.file.mkOutOfStoreSymlink "/dev/null"; + }; + + environment.systemPackages = with pkgs; [alacritty.terminfo]; + }; +} -- cgit 1.4.1