From 187c673adf3c6a9a7afd8934ee41df7941f28cbf Mon Sep 17 00:00:00 2001 From: aszlig Date: Wed, 18 Mar 2015 03:07:20 +0100 Subject: modules: Move my modules into category dirs. Signed-off-by: aszlig --- modules/user/aszlig/programs/git/default.nix | 74 ++++++++++++++++++ modules/user/aszlig/programs/zsh/default.nix | 109 +++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 modules/user/aszlig/programs/git/default.nix create mode 100644 modules/user/aszlig/programs/zsh/default.nix (limited to 'modules/user/aszlig/programs') diff --git a/modules/user/aszlig/programs/git/default.nix b/modules/user/aszlig/programs/git/default.nix new file mode 100644 index 00000000..0090b617 --- /dev/null +++ b/modules/user/aszlig/programs/git/default.nix @@ -0,0 +1,74 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.vuizvui.user.aszlig.programs.git; + + genConf = attrs: let + escStr = s: "\"${escape [ "\"" "\\" ] s}\""; + mkVal = v: if isBool v && v then "true" + else if isBool v && !v then "false" + else escStr (toString v); + mkLine = key: val: "${key} = ${mkVal val}"; + + filterNull = filterAttrs (_: v: !(isNull v)); + + mkSection = sect: subsect: vals: '' + [${sect}${optionalString (subsect != null) " ${escStr subsect}"}] + ${concatStringsSep "\n" (mapAttrsToList mkLine (filterNull vals))} + ''; + + mkConf = sect: content: let + subs = filterAttrs (_: isAttrs) content; + nonSubs = filterAttrs (_: s: !isAttrs s) content; + hasPlain = (attrNames nonSubs) != []; + plainSects = singleton (mkSection sect null nonSubs); + in mapAttrsToList (mkSection sect) subs ++ optional hasPlain plainSects; + + text = concatStringsSep "\n" (flatten (mapAttrsToList mkConf attrs)); + in pkgs.writeText "gitconfig" text; + + gitPatched = overrideDerivation pkgs.gitFull (git: { + makeFlags = let + oldFlags = git.makeFlags or []; + newVal = "ETC_GITCONFIG=${cfg.config}"; + in if isList oldFlags + then oldFlags ++ [ newVal ] + else "${oldFlags} ${newVal}"; + }); +in { + options.vuizvui.user.aszlig.programs.git = { + enable = mkEnableOption "Git"; + + config = mkOption { + description = "System-wide default config for Git"; + + type = let + superType = types.attrsOf types.unspecified; + in mkOptionType { + name = "attribute set of either plain values or " + + "attribute sets of values (if it is a subsection)"; + inherit (superType) check merge; + inherit (superType) getSubOptions getSubModules substSubModules; + }; + + default = {}; + example = { + color.ui = "auto"; + merge.tool = "vimdiff"; + guitool.foobar.noconsole = true; + }; + + apply = genConf; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [ + gitPatched + pkgs.gitAndTools.git-remote-hg + pkgs.gitAndTools.hub + ]; + }; +} diff --git a/modules/user/aszlig/programs/zsh/default.nix b/modules/user/aszlig/programs/zsh/default.nix new file mode 100644 index 00000000..cb8ccd64 --- /dev/null +++ b/modules/user/aszlig/programs/zsh/default.nix @@ -0,0 +1,109 @@ +{ config, lib, ... }: + +with lib; + +let + cfg = config.vuizvui.user.aszlig.programs.zsh; + +in { + options.vuizvui.user.aszlig.programs.zsh = { + enable = mkEnableOption "zsh"; + }; + + config = mkIf cfg.enable { + environment.shellInit = '' + export EDITOR="vim" + export EMAIL="aszlig@redmoonstudios.org" + ''; + + programs.zsh.enable = true; + + programs.zsh.shellAliases.t = "task"; + + programs.zsh.interactiveShellInit = mkAfter '' + export HISTFILE=~/.histfile + export HISTSIZE=100000 + export SAVEHIST=100000 + + unsetopt SHARE_HISTORY + + setopt extendedglob + setopt extendedhistory + setopt globcomplete + setopt histnostore + setopt histreduceblanks + setopt correct + setopt dvorak + setopt interactivecomments + setopt autopushd + setopt autocd + setopt beep + + bindkey -v + if [[ "$TERM" = xterm ]]; then + bindkey -v '\e[H' vi-beginning-of-line + bindkey -v '\e[F' vi-end-of-line + + function set-title() { + echo -en "\e]2;$2\a" + } + + function reset-title() { + echo -en "\e]2;''${(%):-%~}\a" + } + + autoload -Uz add-zsh-hook + add-zsh-hook preexec set-title + add-zsh-hook precmd reset-title + else + bindkey -v '\e[1~' vi-beginning-of-line + bindkey -v '\e[4~' vi-end-of-line + fi + + bindkey -a '/' history-incremental-pattern-search-backward + bindkey -a '?' history-incremental-pattern-search-forward + bindkey '\e[A' up-line-or-history + bindkey '\e[B' down-line-or-history + + zstyle ':completion:*' completer _expand _complete _ignored _approximate + zstyle ':completion:*' expand prefix suffix + zstyle ':completion:*' group-name ''' + zstyle ':completion:*' insert-unambiguous true + zstyle ':completion:*' list-colors ''' + zstyle ':completion:*' list-prompt \ + %SAt %p: Hit TAB for more, or the character to insert%s + zstyle ':completion:*' list-suffixes true + zstyle ':completion:*' matcher-list ''' \ + 'm:{[:lower:]}={[:upper:]}' \ + 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' \ + 'l:|=* r:|=*' \ + 'r:|[._-]=** r:|=**' + zstyle ':completion:*' max-errors 2 numeric + zstyle ':completion:*' menu select=long + zstyle ':completion:*' original true + zstyle ':completion:*' preserve-prefix '//[^/]##/' + zstyle ':completion:*' prompt \ + 'Hm, did you mistype something? There are %e errors in the completion.' + zstyle ':completion:*' select-prompt \ + %SScrolling active: current selection at %p%s + zstyle ':completion:*' use-compctl false + zstyle ':completion:*' verbose true + + autoload -Uz compinit + compinit + + autoload -Uz zmv + ''; + + programs.zsh.promptInit = '' + autoload -Uz prompt_special_chars + + () { + local p_machine='%(!..%B%F{red}%n%b%F{blue}@)%b%F{red}%m' + local p_path='%B%F{blue}[%F{cyan}%~%B%F{blue}]' + local p_exitcode='%F{green}%?%(!.%F{cyan}>.%b%F{green}>)%b%f ' + PROMPT="$p_machine$p_path$p_exitcode" + } + ''; + }; +} -- cgit 1.4.1