fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . fusuma ; 8 9yamlFormat = pkgs . formats . yaml { }; 10 11configJson = pkgs . writeText "config.json" ( builtins . toJSON cfg . settings ); 12 13configYamlRaw = pkgs . runCommand "config.yaml.raw" { } '' 14${ pkgs . remarshal } /bin/json2yaml -i ${ configJson } -o $ out ; 15'' ; 16 17# convert keys into literal numbers where necessary, 18# fusuma does not support string type finger count. 19strToInt = pkgs . writers . writePython3 "str2int" { 20libraries = [ pkgs . python3Packages . pyyaml ]; 21} '' 22import yaml 23from yaml import FullLoader 24 25 26def str2int(config): 27if type(config) is not dict: 28return 29 30for key in list(config): 31if type(config[key]) is dict and key.isdigit(): 32t = config[key] 33del config[key] 34config[int(key)] = t 35else: 36str2int(config[key]) 37 38 39if __name__ == '__main__': 40path = " ${ configYamlRaw } " 41with open(path) as f: 42config = yaml.load(f, Loader=FullLoader) 43str2int(config) 44print(yaml.dump(config)) 45'' ; 46 47configYaml = pkgs . stdenv . mkDerivation { 48name = "config.yaml" ; 49buildCommand = '' 50${ strToInt } > $out 51'' ; 52}; 53 54makeBinPath = packages : 55foldl ( a :b :if a == "" then b else " ${ a } : ${ b } " ) "" 56( map ( pkg :" ${ pkg } /bin" ) packages ); 57 58in { 59meta . maintainers = [ hm . maintainers . iosmanthus ]; 60 61options . services . fusuma = { 62enable = mkEnableOption 63"the fusuma systemd service to automatically enable touchpad gesture" ; 64 65package = mkOption { 66type = types . package ; 67default = pkgs . fusuma ; 68defaultText = literalExpression "pkgs.fusuma" ; 69description = "Package providing {command}`fusuma`." ; 70}; 71 72settings = mkOption { 73type = yamlFormat . type ; 74example = literalExpression '' 75{ 76threshold = { 77swipe = 0.1; 78}; 79interval = { 80swipe = 0.7; 81}; 82swipe = { 83"3" = { 84left = { 85# GNOME: Switch to left workspace 86command = "xdotool key ctrl+alt+Right"; 87}; 88}; 89}; 90}; 91'' ; 92description = '' 93YAML config that will override the default fusuma configuration. 94'' ; 95}; 96 97extraPackages = mkOption { 98type = types . listOf types . package ; 99default = with pkgs ; [ coreutils ]; 100defaultText = literalExpression "pkgs.coreutils" ; 101example = literalExpression '' 102with pkgs; [ coreutils xdotool ]; 103'' ; 104description = '' 105Extra packages needs to bring to the scope of fusuma service. 106'' ; 107}; 108}; 109 110config = mkIf cfg . enable { 111assertions = [ 112( lib . hm . assertions . assertPlatform "services.fusuma" pkgs 113lib . platforms . linux ) 114]; 115 116xdg . configFile . "fusuma/config.yaml" . source = configYaml ; 117 118systemd . user . services . fusuma = { 119Unit = { 120Description = "Fusuma services" ; 121After = [ "graphical-session-pre.target" ]; 122PartOf = [ "graphical-session.target" ]; 123}; 124 125Service = { 126Environment = with pkgs ; "PATH= ${ makeBinPath cfg . extraPackages } " ; 127ExecStart = 128" ${ cfg . package } /bin/fusuma -c ${ config . xdg . configHome } /fusuma/config.yaml" ; 129}; 130 131Install = { WantedBy = [ "graphical-session.target" ]; }; 132}; 133}; 134}