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 . xfconf ; 8 9xfIntVariant = types . submodule { 10options = { 11type = mkOption { 12type = types . enum [ "int" "uint" "uint64" ]; 13description = '' 14To distinguish between int, uint and uint64 in xfconf, 15you can specify the type in xfconf with this submodule. 16For other types, you don't need to use this submodule, 17just specify the value is enough. 18'' ; 19}; 20value = mkOption { 21type = types . int ; 22description = "The value in xfconf." ; 23}; 24}; 25}; 26 27withType = v : 28if builtins . isAttrs v then [ 29"-t" 30v . type 31"-s" 32( toString v . value ) 33] else if builtins . isBool v then [ 34"-t" 35"bool" 36"-s" 37( if v then "true" else "false" ) 38] else if builtins . isInt v then [ 39"-t" 40"int" 41"-s" 42( toString v ) 43] else if builtins . isFloat v then [ 44"-t" 45"double" 46"-s" 47( toString v ) 48] else if builtins . isString v then [ 49"-t" 50"string" 51"-s" 52v 53] else if builtins . isList v then 54[ "-a" ] ++ concatMap withType v 55else 56throw "unexpected xfconf type: ${ builtins . typeOf v } " ; 57 58in { 59meta . maintainers = [ maintainers . chuangzhu ]; 60 61options . xfconf = { 62enable = mkOption { 63type = types . bool ; 64default = true ; 65visible = false ; 66description = '' 67Whether to enable Xfconf settings. 68 69Note, if you use NixOS then you must add 70`programs.xfconf.enable = true` 71to your system configuration. Otherwise you will see a systemd error 72message when your configuration is activated. 73'' ; 74}; 75 76settings = mkOption { 77type = with types ; 78# xfIntVariant must come AFTER str; otherwise strings are treated as submodule imports... 79let value = nullOr ( oneOf [ bool int float str xfIntVariant ]); 80in attrsOf ( attrsOf ( either value ( listOf value ))) // { 81description = "xfconf settings" ; 82}; 83default = { }; 84example = literalExpression '' 85{ 86xfce4-session = { 87"startup/ssh-agent/enabled" = false; 88"general/LockCommand" = "''${pkgs.lightdm}/bin/dm-tool lock"; 89}; 90xfce4-desktop = { 91"backdrop/screen0/monitorLVDS-1/workspace0/last-image" = 92"''${pkgs.nixos-artwork.wallpapers.stripes-logo.gnomeFilePath}"; 93}; 94} 95'' ; 96description = '' 97Settings to write to the Xfconf configuration system. 98'' ; 99}; 100}; 101 102config = mkIf ( cfg . enable && cfg . settings != { }) { 103assertions = 104[ ( hm . assertions . assertPlatform "xfconf" pkgs platforms . linux ) ]; 105 106home . activation . xfconfSettings = hm . dag . entryAfter [ "installPackages" ] 107( let 108mkCommand = channel :property :value :'' 109$DRY_RUN_CMD ${ pkgs . xfce . xfconf } /bin/xfconf-query \ 110${ 111escapeShellArgs ([ "-c" channel "-p" "/ ${ property } " ] 112++ ( if value == null then 113[ "-r" ] 114else 115[ "-n" ] ++ withType value )) 116} 117'' ; 118 119commands = mapAttrsToList 120( channel :properties :mapAttrsToList ( mkCommand channel ) properties ) 121cfg . settings ; 122 123load = pkgs . writeShellScript "load-xfconf" 124( concatMapStrings concatStrings commands ); 125in '' 126if [[ -v DBUS_SESSION_BUS_ADDRESS ]]; then 127export DBUS_RUN_SESSION_CMD="" 128else 129export DBUS_RUN_SESSION_CMD=" ${ pkgs . dbus } /bin/dbus-run-session --dbus-daemon= ${ pkgs . dbus } /bin/dbus-daemon" 130fi 131 132$DRY_RUN_CMD $DBUS_RUN_SESSION_CMD ${ load } 133 134unset DBUS_RUN_SESSION_CMD 135'' ); 136}; 137}