josm.nix (2064B)
1 { config, lib, pkgs, ... }: 2 3 with lib; 4 let 5 cfg = config.programs.josm; 6 configDir = 7 if pkgs.stdenv.isDarwin then 8 "${config.home.homeDirectory}/Library/Preferences/JOSM" 9 else 10 "${config.xdg.configHome}/JOSM"; 11 configFile = "${configDir}/preferences.xml"; 12 in 13 { 14 meta.maintainers = [ maintainers.sikmir ]; 15 16 options.programs.josm = { 17 enable = mkEnableOption "An extensible editor for OpenStreetMap"; 18 19 package = mkOption { 20 default = pkgs.josm; 21 defaultText = literalExpression "pkgs.josm"; 22 description = "JOSM package to install."; 23 type = types.package; 24 }; 25 26 accessTokenKey = mkOption { 27 default = ""; 28 description = "OAuth Access Token Key."; 29 type = types.str; 30 }; 31 32 accessTokenSecret = mkOption { 33 default = ""; 34 description = "OAuth Access Token Secret."; 35 type = types.str; 36 }; 37 }; 38 39 config = mkIf cfg.enable ( 40 mkMerge [ 41 { 42 home.packages = [ cfg.package ]; 43 44 home.activation.createJOSMConfigFile = lib.hm.dag.entryBefore [ "writeBoundary" ] '' 45 . ${./josm/init-prefs.sh} 46 . ${./josm/upsert-tag.sh} 47 export PATH=${pkgs.xmlstarlet}/bin:$PATH 48 initPrefs ${cfg.package.version} ${configFile} 49 upsertTag josm.version ${cfg.package.version} ${configFile} 50 ''; 51 } 52 53 ( 54 mkIf (cfg.accessTokenKey != "") { 55 home.activation.setupAccessTokenKey = lib.hm.dag.entryAfter [ "writeBoundary" ] '' 56 . ${./josm/upsert-tag.sh} 57 export PATH=${pkgs.xmlstarlet}/bin:$PATH 58 upsertTag oauth.access-token.key ${cfg.accessTokenKey} ${configFile} 59 ''; 60 } 61 ) 62 63 ( 64 mkIf (cfg.accessTokenSecret != "") { 65 home.activation.setupAccessTokenSecret = lib.hm.dag.entryAfter [ "writeBoundary" ] '' 66 . ${./josm/upsert-tag.sh} 67 export PATH=${pkgs.xmlstarlet}/bin:$PATH 68 upsertTag oauth.access-token.secret ${cfg.accessTokenSecret} ${configFile} 69 ''; 70 } 71 ) 72 ] 73 ); 74 }