Skip to content

Commit

Permalink
Add support for nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Apr 16, 2024
1 parent 557f3de commit e7e5187
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions data/dconf.settings
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,10 @@ recently-installed-apps=['RollerCoaster Tycoon 3 Platinum!.desktop', 'RollerCoas

[org/gnome/evolution-data-server/calendar/list-of-equal]
reminders-snoozed=['=']

[org/gnome/Tetravex]
saved-game=@m(yyda(yyyyyyyy)ua(yyyyu)) nothing

[org/gnome/evince]
document-directory=@ms nothing
pictures-directory=@ms nothing
9 changes: 9 additions & 0 deletions output/dconf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -400,5 +400,14 @@ with lib.hm.gvariant;
reminders-snoozed = [ "=" ];
};

"org/gnome/Tetravex" = {
saved-game = mkNothing "(yyda(yyyyyyyy)ua(yyyyu))";
};

"org/gnome/evince" = {
document-directory = mkNothing "s";
pictures-directory = mkNothing "s";
};

};
}
5 changes: 4 additions & 1 deletion src/DConf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ sepOneEndBy p sep =
vBool :: Parsec Text () Value
vBool = B False <$ string "false" <|> B True <$ string "true"

vNothing :: Parsec Text () Value
vNothing = No <$ string "nothing"

vDouble :: Parsec Text () Value
vDouble = try $ do
s <- option "" $ string "-"
Expand Down Expand Up @@ -120,7 +123,7 @@ baseValue = choice

value :: Parsec Text () Value
value = choice
[vTyped, vDictDictEntry, vList, vJson, baseValue, vCast, vTuple, vVariant]
[vTyped, vDictDictEntry, vList, vJson, baseValue, vCast, vNothing, vTuple, vVariant]

vVariant :: Parsec Text () Value
vVariant = fmap V $ bracket "<" ">" value
Expand Down
1 change: 1 addition & 0 deletions src/DConf/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ castName TyObjectpath = "objectpath"

data Value = S Text -- String
| B Bool -- Bool
| No -- Nothing case of Maybe
| I Int -- Int
| C Ty Value -- Cast
| D Double -- Double
Expand Down
2 changes: 2 additions & 0 deletions src/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ renderValue raw = Nix $ renderValue' raw <> ";"

renderValue' (S v) = renderString v
renderValue' (B v) = T.toLower . T.pack $ show v
renderValue' (No ) = error "Standalone nothing not supported"
renderValue' (I v) = T.pack $ show v
renderValue' (D v) = T.pack $ show v
renderValue' (C ty v) =
Expand All @@ -102,6 +103,7 @@ renderValue raw = Nix $ renderValue' raw <> ";"
renderValue' (T xs) = "mkTuple " <> renderList xs
-- In home-manager, @mkValue []@ emits @\@as []@
renderValue' (Ty "as" (L [])) = renderList []
renderValue' (Ty ('m':t) No) = "mkNothing " <> T.pack (show t)
-- In home-manager, arrays are always typed when using @mkArray@.
renderValue' (Ty ('a':t) (L v)) = "mkArray " <> T.pack (show t) <> " " <> renderList v
-- TODO: add mkTyped to h-m
Expand Down

0 comments on commit e7e5187

Please sign in to comment.