Skip to content

Commit

Permalink
Add full Variant support
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Apr 15, 2024
1 parent e8a5dd1 commit d9c960e
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
11 changes: 11 additions & 0 deletions data/variant.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[foo]
int32=<0>
true=<true>
false=<false>
uint32=<uint32 2>
tuple=<(uint32 2, 'ABC')>
array=<[1, 2, 3]>
string=<'#polari'>
variant=<<7>>
in-array=[<5>, <6>]
typed=<@ai []>
8 changes: 4 additions & 4 deletions output/dconf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ with lib.hm.gvariant;
};

"org/gnome/Weather" = {
locations = [ (mkVariant [ (mkUint32 2) (mkVariant [ "Gdańsk" "EPGD" true [ (mkTuple [ 0.9491682190584854 0.3223041410193837 ]) ] [ (mkTuple [ 0.9485864484589182 0.32579479952337237 ]) ] ]) ]) (mkVariant [ (mkUint32 2) (mkVariant [ "Gdynia, Działdowo County, Warmian-Masurian Voivodeship" "" false [ (mkTuple [ 0.9302794944578734 0.34699627038777753 ]) ] [ (mkTuple [ 0.938610530426954 0.3574455077502486 ]) ] ]) ]) (mkVariant [ (mkUint32 2) (mkVariant [ "Gdynia, Pomeranian Voivodeship" "" false [ (mkTuple [ 0.9514923902475622 0.3235888220312407 ]) ] [ (mkTuple [ 0.9485864484589182 0.32579479952337237 ]) ] ]) ]) ];
locations = [ (mkVariant (mkTuple [ (mkUint32 2) (mkVariant (mkTuple [ "Gdańsk" "EPGD" true [ (mkTuple [ 0.9491682190584854 0.3223041410193837 ]) ] [ (mkTuple [ 0.9485864484589182 0.32579479952337237 ]) ] ])) ])) (mkVariant (mkTuple [ (mkUint32 2) (mkVariant (mkTuple [ "Gdynia, Działdowo County, Warmian-Masurian Voivodeship" "" false [ (mkTuple [ 0.9302794944578734 0.34699627038777753 ]) ] [ (mkTuple [ 0.938610530426954 0.3574455077502486 ]) ] ])) ])) (mkVariant (mkTuple [ (mkUint32 2) (mkVariant (mkTuple [ "Gdynia, Pomeranian Voivodeship" "" false [ (mkTuple [ 0.9514923902475622 0.3235888220312407 ]) ] [ (mkTuple [ 0.9485864484589182 0.32579479952337237 ]) ] ])) ])) ];
};

"org/gnome/shell/weather" = {
automatic-location = true;
locations = [ (mkVariant [ (mkUint32 2) (mkVariant [ "Gdańsk" "EPGD" true [ (mkTuple [ 0.9491682190584854 0.3223041410193837 ]) ] [ (mkTuple [ 0.9485864484589182 0.32579479952337237 ]) ] ]) ]) (mkVariant [ (mkUint32 2) (mkVariant [ "Gdynia, Działdowo County, Warmian-Masurian Voivodeship" "" false [ (mkTuple [ 0.9302794944578734 0.34699627038777753 ]) ] [ (mkTuple [ 0.938610530426954 0.3574455077502486 ]) ] ]) ]) (mkVariant [ (mkUint32 2) (mkVariant [ "Gdynia, Pomeranian Voivodeship" "" false [ (mkTuple [ 0.9514923902475622 0.3235888220312407 ]) ] [ (mkTuple [ 0.9485864484589182 0.32579479952337237 ]) ] ]) ]) ];
locations = [ (mkVariant (mkTuple [ (mkUint32 2) (mkVariant (mkTuple [ "Gdańsk" "EPGD" true [ (mkTuple [ 0.9491682190584854 0.3223041410193837 ]) ] [ (mkTuple [ 0.9485864484589182 0.32579479952337237 ]) ] ])) ])) (mkVariant (mkTuple [ (mkUint32 2) (mkVariant (mkTuple [ "Gdynia, Działdowo County, Warmian-Masurian Voivodeship" "" false [ (mkTuple [ 0.9302794944578734 0.34699627038777753 ]) ] [ (mkTuple [ 0.938610530426954 0.3574455077502486 ]) ] ])) ])) (mkVariant (mkTuple [ (mkUint32 2) (mkVariant (mkTuple [ "Gdynia, Pomeranian Voivodeship" "" false [ (mkTuple [ 0.9514923902475622 0.3235888220312407 ]) ] [ (mkTuple [ 0.9485864484589182 0.32579479952337237 ]) ] ])) ])) ];
};

"system/locale" = {
Expand All @@ -385,9 +385,9 @@ with lib.hm.gvariant;

"issue28/org/gnome/clocks" = {
world-clocks = [ {
location = mkVariant [ (mkUint32 2) (mkVariant [ "Houston" "KHOU" false [ (mkTuple [ 0.5172719570598194 (-1.6629933445314968) ]) ] [ (mkTuple [ 0.5172719570598194 (-1.6629933445314968) ]) ] ]) ];
location = mkVariant (mkTuple [ (mkUint32 2) (mkVariant (mkTuple [ "Houston" "KHOU" false [ (mkTuple [ 0.5172719570598194 (-1.6629933445314968) ]) ] [ (mkTuple [ 0.5172719570598194 (-1.6629933445314968) ]) ] ])) ]);
} {
location = mkVariant [ (mkUint32 2) (mkVariant [ "Singapore" "WSAP" true [ (mkTuple [ 2.3852838928353343e-2 1.8136879868485383 ]) ] [ (mkTuple [ 2.2568084612667797e-2 1.8126262332513803 ]) ] ]) ];
location = mkVariant (mkTuple [ (mkUint32 2) (mkVariant (mkTuple [ "Singapore" "WSAP" true [ (mkTuple [ 2.3852838928353343e-2 1.8136879868485383 ]) ] [ (mkTuple [ 2.2568084612667797e-2 1.8126262332513803 ]) ] ])) ]);
} ];
};

Expand Down
22 changes: 22 additions & 0 deletions output/variant.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated via dconf2nix: https://github.com/nix-commmunity/dconf2nix
{ lib, ... }:

with lib.hm.gvariant;

{
dconf.settings = {
"foo" = {
array = mkVariant [ 1 2 3 ];
false = mkVariant false;
in-array = [ (mkVariant 5) (mkVariant 6) ];
int32 = mkVariant 0;
string = mkVariant "#polari";
true = mkVariant true;
tuple = mkVariant (mkTuple [ (mkUint32 2) "ABC" ]);
typed = mkVariant [];
uint32 = mkVariant (mkUint32 2);
variant = mkVariant (mkVariant 7);
};

};
}
2 changes: 1 addition & 1 deletion src/DConf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ value = choice
[vTyped, vRecord, vList, vJson, vBool, vInt, vDouble, vUint32, vInt64, fmap S vString, vTuple, vVariant]

vVariant :: Parsec Text () Value
vVariant = fmap V $ bracket "<(" ")>" $ commaSeparated $ value
vVariant = fmap V $ bracket "<" ">" value

vList :: Parsec Text () Value
vList = fmap L $ bracket "[" "]" $ commaSeparated $ value
Expand Down
2 changes: 1 addition & 1 deletion src/DConf/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data Value = S Text -- String
| D Double -- Double
| T [Value] -- Tuple of n-arity
| L [Value] -- List of values
| V [Value] -- Variant
| V Value -- Variant
| R [(Text,Value)] -- Record
| Json Text -- Json value
deriving (Eq, Show)
Expand Down
2 changes: 1 addition & 1 deletion src/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ renderValue raw = Nix $ renderValue' raw <> ";"
renderValue' (I64 v) = "mkInt64 " <> T.pack (show v)
renderValue' (L xs) = renderList xs
renderValue' (T xs) = "mkTuple " <> renderList xs
renderValue' (V xs) = "mkVariant " <> renderList xs
renderValue' (V v) = "mkVariant " <> renderItem v
renderValue' (Json v) =
"''\n" <> mkSpaces 8 <> T.strip v <> "\n" <> mkSpaces 6 <> "''"
renderValue' (R kvs) =
Expand Down
11 changes: 11 additions & 0 deletions test/DConf2NixTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ prop_dconf2nix_unicode :: Property
prop_dconf2nix_unicode =
withTests (10 :: TestLimit) dconf2nixUnicode

dconf2nixVariant :: Property
dconf2nixVariant =
let input = "data/variant.settings"
output = "output/variant.nix"
root = Root T.empty
in baseProperty input output root

prop_dconf2nix_variant :: Property
prop_dconf2nix_variant =
withTests (10 :: TestLimit) dconf2nixVariant

dconf2nixEmoji :: Property
dconf2nixEmoji =
let input = "data/emoji.settings"
Expand Down

0 comments on commit d9c960e

Please sign in to comment.