nur-packages

My NUR packages
git clone git://git.sikmir.ru/nur-packages
Log | Files | Refs | README | LICENSE

commit 4cd87124eebcb2fad6e7f601cbcd4aa0eef94a0e
parent d10dbbd13e73e817b2f5c17a99e04ae043ebd71a
Author: Nikolay Korotkiy <sikmir@gmail.com>
Date:   Fri, 30 Oct 2020 03:01:31 +0300

josm module: add access token options

Diffstat:
Mmodules/home-manager/programs/josm.nix | 56+++++++++++++++++++++++++++++++++++++++++++++++++++++---
Amodules/home-manager/programs/josm/init-prefs.sh | 18++++++++++++++++++
Amodules/home-manager/programs/josm/upsert-tag.sh | 15+++++++++++++++
3 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/modules/home-manager/programs/josm.nix b/modules/home-manager/programs/josm.nix @@ -3,6 +3,12 @@ with lib; let cfg = config.programs.josm; + configDir = + if pkgs.stdenv.isDarwin then + "${config.home.homeDirectory}/Library/Preferences/JOSM" + else + "${config.xdg.configHome}/JOSM"; + configFile = "${configDir}/preferences.xml"; in { meta.maintainers = [ maintainers.sikmir ]; @@ -16,9 +22,53 @@ in description = "JOSM package to install."; type = types.package; }; - }; - config = mkIf cfg.enable { - home.packages = [ cfg.package ]; + accessTokenKey = mkOption { + default = ""; + description = "OAuth Access Token Key."; + type = types.str; + }; + + accessTokenSecret = mkOption { + default = ""; + description = "OAuth Access Token Secret."; + type = types.str; + }; }; + + config = mkIf cfg.enable ( + mkMerge [ + { + home.packages = [ cfg.package ]; + + home.activation.createJOSMConfigFile = lib.hm.dag.entryBefore [ "writeBoundary" ] '' + . ${./josm/init-prefs.sh} + . ${./josm/upsert-tag.sh} + export PATH=${pkgs.xmlstarlet}/bin:$PATH + initPrefs ${cfg.package.version} ${configFile} + upsertTag josm.version ${cfg.package.version} ${configFile} + ''; + } + + ( + mkIf (cfg.accessTokenKey != "") { + home.activation.setupAccessTokenKey = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + . ${./josm/upsert-tag.sh} + export PATH=${pkgs.xmlstarlet}/bin:$PATH + upsertTag oauth.access-token.key ${cfg.accessTokenKey} ${configFile} + ''; + } + ) + + ( + mkIf (cfg.accessTokenSecret != "") { + home.activation.setupAccessTokenSecret = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + . ${./josm/upsert-tag.sh} + export PATH=${pkgs.xmlstarlet}/bin:$PATH + upsertTag oauth.access-token.secret ${cfg.accessTokenSecret} ${configFile} + ''; + } + ) + ] + ); } diff --git a/modules/home-manager/programs/josm/init-prefs.sh b/modules/home-manager/programs/josm/init-prefs.sh @@ -0,0 +1,18 @@ +function initPrefs() { + version=$1 + cfgfile=$2 + + if [ ! -f $cfgfile ]; then + $DRY_RUN_CMD mkdir -p $(dirname $cfgfile) + $DRY_RUN_CMD eval "echo '<preferences/>' > $cfgfile" + $DRY_RUN_CMD xml ed -P -L \ + -i "/preferences" -t attr -n "xmlns" -v "http://josm.openstreetmap.de/preferences-1.0" \ + -i "/preferences" -t attr -n "version" -v "$version" \ + $cfgfile + else + $DRY_RUN_CMD xml ed -P -L \ + -N N="http://josm.openstreetmap.de/preferences-1.0" \ + -u "/N:preferences/@version" -v "$version" \ + $cfgfile + fi +} diff --git a/modules/home-manager/programs/josm/upsert-tag.sh b/modules/home-manager/programs/josm/upsert-tag.sh @@ -0,0 +1,15 @@ +function upsertTag() { + key=$1 + value=$2 + cfgfile=$3 + + if [ -f $cfgfile ]; then + $DRY_RUN_CMD xml ed -P -L \ + -N N="http://josm.openstreetmap.de/preferences-1.0" \ + -d "//N:tag[@key='$key']" \ + -s '/N:preferences' -t elem -n "tag" \ + -i '$prev' -t attr -n "key" -v "$key" \ + -a "/N:preferences/tag[@key='$key']" -t attr -n "value" -v "$value" \ + $cfgfile + fi +}