From 616dbd67f7a903d2a57ef4b8d0d9bcc4f567eab3 Mon Sep 17 00:00:00 2001 From: Alistair Potts Date: Thu, 1 Feb 2018 13:33:24 +0000 Subject: [PATCH 1/5] mercurial: add module Very simple module for hg based on programs.git, and is intended to have compatible options. For simple setups, a user should be able to write something like: {...}: let vcsconfig = { enable = true; userName = "John Smith"; userEmail = "js@example.com"; ignores = [ "*.swp" "*~" ]; }; in { programs.git = vcsconfig // {...extra git config...}; programs.mercurial = vcsconfig // {...extra hg confg...}; } For this reason, the ignore options are `ignores` for `syntax: glob` and `ignoresRegexp` for `syntax: regexp` so that simple glob ignores can (very likely) be shared with a git config, despite regular expressions being the default for mercurial. --- modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/mercurial.nix | 102 +++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 modules/programs/mercurial.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 202ab915..1dab10ae 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -543,6 +543,13 @@ in The old module will be removed on February 25, 2018. ''; } + + { + time = "2018-02-02T11:15:00+00:00"; + message = '' + A new program configuration is available: 'programs.mercurial' + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 7fd76147..8c000d2f 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -34,6 +34,7 @@ let ./programs/info.nix ./programs/lesspipe.nix ./programs/man.nix + ./programs/mercurial.nix ./programs/neovim.nix ./programs/rofi.nix ./programs/ssh.nix diff --git a/modules/programs/mercurial.nix b/modules/programs/mercurial.nix new file mode 100644 index 00000000..5daee39f --- /dev/null +++ b/modules/programs/mercurial.nix @@ -0,0 +1,102 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.mercurial; + +in + +{ + + options = { + programs.mercurial = { + enable = mkEnableOption "Mercurial"; + + package = mkOption { + type = types.package; + default = pkgs.mercurial; + defaultText = "pkgs.mercurial"; + description = "Mercurial package to install."; + }; + + userName = mkOption { + type = types.str; + description = "Default user name to use."; + }; + + userEmail = mkOption { + type = types.str; + description = "Default user email to use."; + }; + + aliases = mkOption { + type = types.attrs; + default = {}; + description = "Mercurial aliases to define."; + }; + + extraConfig = mkOption { + type = types.either types.attrs types.lines; + default = {}; + description = "Additional configuration to add."; + }; + + iniContent = mkOption { + type = types.attrsOf types.attrs; + internal = true; + }; + + ignores = mkOption { + type = types.listOf types.str; + default = []; + example = [ "*~" "*.swp" ]; + description = "List of globs for files to be globally ignored."; + }; + + ignoresRegexp = mkOption { + type = types.listOf types.str; + default = []; + example = [ "^.*~$" "^.*\\.swp$" ]; + description = + "List of regular expressions for files to be globally ignored."; + }; + }; + }; + + config = mkIf cfg.enable ( + mkMerge [ + { + home.packages = [ cfg.package ]; + + programs.mercurial.iniContent.ui = { + username = cfg.userName + " <" + cfg.userEmail + ">"; + }; + + xdg.configFile."hg/hgrc".text = generators.toINI {} cfg.iniContent; + } + + (mkIf (cfg.ignores != [] || cfg.ignoresRegexp != []) { + programs.mercurial.iniContent.ui.ignore = + "${config.xdg.configHome}/hg/hgignore_global"; + + xdg.configFile."hg/hgignore_global".text = + "syntax: glob\n" + concatStringsSep "\n" cfg.ignores + "\n" + + "syntax: regexp\n" + concatStringsSep "\n" cfg.ignoresRegexp + "\n"; + }) + + (mkIf (cfg.aliases != {}) { + programs.mercurial.iniContent.alias = cfg.aliases; + }) + + (mkIf (lib.isAttrs cfg.extraConfig) { + programs.mercurial.iniContent = cfg.extraConfig; + }) + + (mkIf (lib.isString cfg.extraConfig) { + xdg.configFile."hg/hgrc".text = cfg.extraConfig; + }) + ] + ); +} From 91a98f919db2fab3e5c9d47d3955e3896f320f3a Mon Sep 17 00:00:00 2001 From: Alistair Potts Date: Fri, 2 Feb 2018 15:25:51 +0000 Subject: [PATCH 2/5] stalonetray: add module Adds a service for the Stalonetray system tray. Configured through a 'config' attribute set, which writes space separated key value pairs on successive lines to `~/.stalonetrayrc`. --- modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/services/stalonetray.nix | 94 ++++++++++++++++++++++++++++++++ modules/services/syncthing.nix | 5 +- 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 modules/services/stalonetray.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 1dab10ae..0cb5758e 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -550,6 +550,13 @@ in A new program configuration is available: 'programs.mercurial' ''; } + + { + time = "2018-02-03T10:00:00+00:00"; + message = '' + A new module is available: 'services.stalonetray' + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 8c000d2f..aa04f327 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -57,6 +57,7 @@ let ./services/random-background.nix ./services/redshift.nix ./services/screen-locker.nix + ./services/stalonetray.nix ./services/syncthing.nix ./services/taffybar.nix ./services/tahoe-lafs.nix diff --git a/modules/services/stalonetray.nix b/modules/services/stalonetray.nix new file mode 100644 index 00000000..7b16f754 --- /dev/null +++ b/modules/services/stalonetray.nix @@ -0,0 +1,94 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.stalonetray; + +in + +{ + options = { + services.stalonetray = { + enable = mkEnableOption "Stalonetray system tray"; + + package = mkOption { + default = pkgs.stalonetray; + defaultText = "pkgs.stalonetray"; + type = types.package; + example = literalExample "pkgs.stalonetray"; + description = "The package to use for the Stalonetray binary."; + }; + + config = mkOption { + type = with types; + attrsOf (nullOr (either str (either bool int))); + description = '' + Stalonetray configuration as a set of attributes. + ''; + default = {}; + example = { + geometry = "3x1-600+0"; + decorations = null; + icon_size = 30; + sticky = true; + background = "#cccccc"; + }; + }; + + extraConfig = mkOption { + type = types.lines; + description = "Additional configuration lines for stalonetrayrc."; + default = ""; + example = '' + geometry 3x1-600+0 + decorations none + icon_size 30 + sticky true + background "#cccccc" + ''; + }; + }; + }; + + config = mkIf cfg.enable (mkMerge [ + { + home.packages = [ cfg.package ]; + + systemd.user.services.stalonetray = { + Unit = { + Description = "Stalonetray system tray"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + + Service = { + ExecStart = "${cfg.package}/bin/stalonetray"; + Restart = "on-failure"; + }; + }; + } + + (mkIf (cfg.config != {}) { + home.file.".stalonetrayrc".text = + let + valueToString = v: + if isBool v then (if v then "true" else "false") + else if (v==null) then "none" + else ''"${toString v}"''; + in + concatStrings ( + mapAttrsToList (k: v: "${k} ${valueToString v}\n") cfg.config + ); + }) + + (mkIf (cfg.extraConfig != "") { + home.file.".stalonetrayrc".text = cfg.extraConfig; + }) + ]); +} diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix index 1906814b..5acf313f 100644 --- a/modules/services/syncthing.nix +++ b/modules/services/syncthing.nix @@ -52,7 +52,10 @@ with lib; qsyncthingtray = { Unit = { Description = "QSyncthingTray"; - After = [ "graphical-session-pre.target" "polybar.service" "taffybar.service" ]; + After = [ "graphical-session-pre.target" + "polybar.service" + "taffybar.service" + "stalonetray.service" ]; PartOf = [ "graphical-session.target" ]; }; From fa6f697dbbe06b47b17057d93dffdfcd6f39cbbc Mon Sep 17 00:00:00 2001 From: Nikita Uvarov Date: Thu, 25 Jan 2018 14:13:44 +0100 Subject: [PATCH 3/5] zsh: move session variables export to zshrc Unlike .zshenv, .zshrc file is sourced only by interactive shells. --- modules/programs/zsh.nix | 86 ++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index 9dcbece3..6706fa68 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -171,10 +171,8 @@ in sessionVariables = mkOption { default = {}; type = types.attrs; - example = { ZSH_CACHE_DIR = "$HOME/.cache/zsh"; }; - description = '' - Environment variables that will be set for zsh session. - ''; + example = { MAILCHECK = 30; }; + description = "Environment variables that will be set for zsh session."; }; initExtra = mkOption { @@ -240,20 +238,46 @@ in }; config = mkIf cfg.enable (mkMerge [ + (mkIf (cfg.profileExtra != "") { + home.file."${relToDotDir ".zprofile"}".text = cfg.profileExtra; + }) + + (mkIf (cfg.loginExtra != "") { + home.file."${relToDotDir ".zlogin"}".text = cfg.loginExtra; + }) + + (mkIf (cfg.logoutExtra != "") { + home.file."${relToDotDir ".zlogout"}".text = cfg.logoutExtra; + }) + + (mkIf cfg.oh-my-zsh.enable { + home.file."${relToDotDir ".zshenv"}".text = '' + ZSH="${pkgs.oh-my-zsh}/share/oh-my-zsh"; + ZSH_CACHE_DIR="''${XDG_CACHE_HOME:-''$HOME/.cache}/oh-my-zsh"; + ''; + }) + + (mkIf (cfg.dotDir != null) { + home.file."${relToDotDir ".zshenv"}".text = '' + ZDOTDIR=${zdotdir} + ''; + + # When dotDir is set, only use ~/.zshenv to source ZDOTDIR/.zshenv, + # This is so that if ZDOTDIR happens to be + # already set correctly (by e.g. spawning a zsh inside a zsh), all env + # vars still get exported + home.file.".zshenv".text = '' + source ${zdotdir}/.zshenv + ''; + }) + { home.packages = with pkgs; [ zsh ] ++ optional cfg.enableCompletion nix-zsh-completions ++ optional cfg.oh-my-zsh.enable oh-my-zsh; - home.file."${relToDotDir ".zshenv"}".text = '' - typeset -U fpath - ${optionalString (config.home.sessionVariableSetter != "pam") '' - . "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" - ''} - ${envVarsStr} - ''; - home.file."${relToDotDir ".zshrc"}".text = '' + typeset -U path cdpath fpath manpath fpath+="$HOME/.nix-profile/share/zsh/site-functions" fpath+="$HOME/.nix-profile/share/zsh/$ZSH_VERSION/functions" @@ -299,41 +323,17 @@ in ${cfg.initExtra} + # Environment variables + ${optionalString (config.home.sessionVariableSetter != "pam") '' + . "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" + ''} + ${envVarsStr} + + # Aliases ${aliasesStr} ''; } - (mkIf cfg.oh-my-zsh.enable { - programs.zsh.sessionVariables = { - ZSH = "${pkgs.oh-my-zsh}/share/oh-my-zsh"; - ZSH_CACHE_DIR = "\${XDG_CACHE_HOME:-$HOME/.cache}/oh-my-zsh"; - }; - }) - - (mkIf (cfg.profileExtra != "") { - home.file."${relToDotDir ".zprofile"}".text = cfg.profileExtra; - }) - - (mkIf (cfg.loginExtra != "") { - home.file."${relToDotDir ".zlogin"}".text = cfg.loginExtra; - }) - - (mkIf (cfg.logoutExtra != "") { - home.file."${relToDotDir ".zlogout"}".text = cfg.logoutExtra; - }) - - (mkIf (cfg.dotDir != null) { - programs.zsh.sessionVariables.ZDOTDIR = zdotdir; - - # When dotDir is set, only use ~/.zshenv to source ZDOTDIR/.zshenv, - # This is so that if ZDOTDIR happens to be - # already set correctly (by e.g. spawning a zsh inside a zsh), all env - # vars still get exported - home.file.".zshenv".text = '' - source ${zdotdir}/.zshenv - ''; - }) - (mkIf cfg.oh-my-zsh.enable { # Oh-My-Zsh calls compinit during initialization, # calling it twice causes sight start up slowdown From 2304c145f342ae98968c1ea295f02c1183539ea3 Mon Sep 17 00:00:00 2001 From: Nikita Uvarov Date: Mon, 29 Jan 2018 11:30:26 +0100 Subject: [PATCH 4/5] zsh: add system packages' completion path to fpath --- modules/programs/zsh.nix | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index 6706fa68..a5163d87 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -153,7 +153,13 @@ in enableCompletion = mkOption { default = true; - description = "Enable zsh completion."; + description = '' + Enable zsh completion. Don't forget to add + + environment.pathsToLink = [ "/share/zsh" ]; + + to your system configuration to get completion for system packages (e.g. systemd). + ''; type = types.bool; }; @@ -278,8 +284,10 @@ in home.file."${relToDotDir ".zshrc"}".text = '' typeset -U path cdpath fpath manpath - fpath+="$HOME/.nix-profile/share/zsh/site-functions" - fpath+="$HOME/.nix-profile/share/zsh/$ZSH_VERSION/functions" + + for profile in ''${(z)NIX_PROFILES}; do + fpath+=($profile/share/zsh/site-functions $profile/share/zsh/$ZSH_VERSION/functions $profile/share/zsh/vendor-completions) + done HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help" From 6833f96c147779fe197657bbcc4bd323324cd6c3 Mon Sep 17 00:00:00 2001 From: Mogria Date: Sat, 27 Jan 2018 18:10:13 +0100 Subject: [PATCH 5/5] rofi: add options to for location, xoffset & yoffset --- modules/programs/rofi.nix | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/modules/programs/rofi.nix b/modules/programs/rofi.nix index 9391b2d0..de98a466 100644 --- a/modules/programs/rofi.nix +++ b/modules/programs/rofi.nix @@ -113,6 +113,17 @@ let (rowsColorsToString colors.rows)} ''; + locationsMap = { + center = 0; + top-left = 1; + top = 2; + top-right = 3; + right = 4; + bottom-right = 5; + bottom = 6; + bottom-left = 7; + left = 8; + }; in { @@ -195,6 +206,28 @@ in description = "Whether to run rofi fullscreen."; }; + location = mkOption { + default = "center"; + type = types.enum (builtins.attrNames locationsMap); + description = "The location rofi appears on the screen."; + }; + + xoffset = mkOption { + default = 0; + type = types.int; + description = '' + Offset in the x-axis in pixels relative to the chosen location. + ''; + }; + + yoffset = mkOption { + default = 0; + type = types.int; + description = '' + Offset in the y-axis in pixels relative to the chosen location. + ''; + }; + colors = mkOption { default = null; type = types.nullOr colorsSubmodule; @@ -258,6 +291,9 @@ in ${setOption "terminal" cfg.terminal} ${setOption "cycle" cfg.cycle} ${setOption "fullscreen" cfg.fullscreen} + ${setOption "location" (builtins.getAttr cfg.location locationsMap)} + ${setOption "xoffset" cfg.xoffset} + ${setOption "yoffset" cfg.yoffset} ${setColorScheme cfg.colors}