Skip to content

Commit

Permalink
Fix various issues (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyYakeley authored Jun 22, 2023
1 parent 2502d6f commit bcb1c60
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 151 deletions.
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,20 @@ Type `--help` for some more information.
```shell
dconf2nix - Nixify dconf configuration files

Usage: dconf2nix [-v|--version]
[[-r|--root ARG] [-t|--timeout ARG] [-e|--emoji] [--verbose] |
(-i|--input ARG) (-o|--output ARG) [-r|--root ARG]
[-t|--timeout ARG] [-e|--emoji] [--verbose]]
Usage: dconf2nix [-v|--version]
[[-r|--root ARG] [-e|--emoji] [--verbose] | (-i|--input ARG)
(-o|--output ARG) [-r|--root ARG] [-e|--emoji] [--verbose]]
Convert a dconf file into a Nix file, as expected by Home Manager.

Available options:
-h,--help Show this help text
-v,--version Show the current version
-r,--root ARG Custom root path. e.g.: system/locale/
-t,--timeout ARG Timeout in seconds for the conversion
process (default: 5)
-e,--emoji Enable emoji support (adds a bit of overhead)
--verbose Verbose mode (debug)
-i,--input ARG Path to the dconf file (input)
-o,--output ARG Path to the Nix output file (to be created)
-r,--root ARG Custom root path. e.g.: system/locale/
-t,--timeout ARG Timeout in seconds for the conversion
process (default: 5)
-e,--emoji Enable emoji support (adds a bit of overhead)
--verbose Verbose mode (debug)
```
Expand Down Expand Up @@ -221,11 +216,7 @@ Have a look at the [latest releases](https://github.com/gvolpe/dconf2nix/release

### Troubleshooting

![error](img/error.png)

The default timeout is of 5 seconds. You can see it by running `dconf2nix --help`.

Do also consider the caveats mentioned above in the [Supported Types](#supported-types) section.
Do consider the caveats mentioned above in the [Supported Types](#supported-types) section.

### Development

Expand Down
26 changes: 4 additions & 22 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,13 @@ import CommandLine ( FileArgs(..)
, StdinArgs(..)
, runArgs
)
import Data.Foldable ( traverse_ )
import DConf.Data ( ProcessTimeout(..)
, Verbosity(..)
)
import DConf2Nix ( dconf2nixFile
, dconf2nixStdin
)
import System.Timeout ( timeout )

timeoutMessage = unlines
[ "💥 The process timed out."
, ""
, " 💡 You can try increasing the timeout using --timeout."
, ""
, " ⛔ If the issue persists, run it again using --verbose and report the issue on Github, indicating dconf2nix's version. Sorry 😞."
]

dconf2nix :: ProcessTimeout -> IO () -> Maybe String -> IO ()
dconf2nix (ProcessTimeout t) fa successMsg = timeout (t * 1000000) fa >>= \case
Just _ -> traverse_ putStrLn successMsg
Nothing -> error timeoutMessage

main :: IO ()
main = runArgs >>= \case
FileInput (FileArgs i o r t e v) ->
dconf2nix t (dconf2nixFile i o r e v) (Just "🚀 Successfully Nixified! ❄️")
StdinInput (StdinArgs r t e v) ->
dconf2nix t (dconf2nixStdin r e v) Nothing
FileInput (FileArgs i o r e v) ->
dconf2nixFile i o r e v
StdinInput (StdinArgs r e v) ->
dconf2nixStdin r e v
2 changes: 2 additions & 0 deletions dconf2nix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ library
, text
hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall

test-Suite dconf2nix-tests
type: exitcode-stdio-1.0
Expand All @@ -50,3 +51,4 @@ executable dconf2nix
, dconf2nix
hs-source-dirs: app
default-language: Haskell2010
ghc-options: -Wall
Binary file removed img/error.png
Binary file not shown.
34 changes: 19 additions & 15 deletions output/dconf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ with lib.hm.gvariant;

"org/gnome/desktop/interface" = {
clock-show-weekday = true;
document-font-name = "JetBrainsMono Nerd Font 11";
document-font-name = " JetBrainsMono Nerd Font 11 ";
enable-hot-corners = false;
font-name = "JetBrainsMono Nerd Font 11";
gtk-im-module = "gtk-im-context-simple";
gtk-theme = "Adwaita-dark";
icon-theme = "Adwaita";
monospace-font-name = "JetBrainsMono Nerd Font 10";
font-name = " JetBrainsMono Nerd Font 11 ";
gtk-im-module = " gtk-im-context-simple ";
gtk-theme = " Adwaita-dark ";
icon-theme = " Adwaita ";
monospace-font-name = " JetBrainsMono Nerd Font 10 ";
show-battery-percentage = true;
};

Expand All @@ -36,7 +36,7 @@ with lib.hm.gvariant;
};

"org/gnome/desktop/screensaver" = {
picture-uri = "file:///home/gvolpe/Pictures/nixos.png";
picture-uri = " file:///home/gvolpe/Pictures/nixos.png ";
};

"org/gnome/desktop/sound" = {
Expand All @@ -53,7 +53,7 @@ with lib.hm.gvariant;
};

"org/gnome/desktop/wm/preferences" = {
button-layout = "close,minimize,maximize:";
button-layout = " close,minimize,maximize:";
titlebar-font = "JetBrainsMono Nerd Font Mono 11";
workspace-names = [];
};
Expand Down Expand Up @@ -98,7 +98,7 @@ with lib.hm.gvariant;
"org/gnome/desktop/input-sources" = {
current = mkUint32 0;
sources = [ (mkTuple [ "xkb" "us" ]) ];
xkb-options = [ "terminate:ctrl_alt_bksp" "lv3:ralt_switch" "caps:ctrl_modifier" ];
xkb-options = [ " terminate:ctrl_alt_bksp " " lv3:ralt_switch " " caps:ctrl_modifier " ];
};

"org/gnome/desktop/interface" = {
Expand Down Expand Up @@ -286,7 +286,7 @@ with lib.hm.gvariant;

"org/gnome/shell/extensions/dash-to-dock" = {
dock-fixed = false;
dock-position = "BOTTOM";
dock-position = " BOTTOM ";
};

"org/gnome/shell/extensions/dash-to-dock" = {
Expand Down Expand Up @@ -334,7 +334,7 @@ with lib.hm.gvariant;
};

"org/gnome/shell/world-clocks" = {
locations = "@av []";
locations = [];
};

"org/gnome/software" = {
Expand All @@ -361,20 +361,20 @@ with lib.hm.gvariant;
};

"org/gnome/Weather" = {
locations = "[<(uint32 2, <('Gdańsk', 'EPGD', true, [(0.94916821905848536, 0.32230414101938371)], [(0.94858644845891815, 0.32579479952337237)])>)>, <(uint32 2, <('Gdynia, Działdowo County, Warmian-Masurian Voivodeship', '', false, [(0.93027949445787339, 0.34699627038777753)], [(0.93861053042695397, 0.35744550775024858)])>)>, <(uint32 2, <('Gdynia, Pomeranian Voivodeship', '', false, [(0.95149239024756216, 0.32358882203124067)], [(0.94858644845891815, 0.32579479952337237)])>)>]";
locations = [ (mkVariant [ (mkUint32 2) (mkVariant [ "Gda\324sk" "EPGD" true [ (mkTuple [ 0.9491682190584854 0.3223041410193837 ]) ] [ (mkTuple [ 0.9485864484589182 0.32579479952337237 ]) ] ]) ]) (mkVariant [ (mkUint32 2) (mkVariant [ "Gdynia, Dzia\322dowo 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 ]) ] ]) ]) ];
};

"org/gnome/shell/weather" = {
automatic-location = true;
locations = "[<(uint32 2, <('Gdańsk', 'EPGD', true, [(0.94916821905848536, 0.32230414101938371)], [(0.94858644845891815, 0.32579479952337237)])>)>, <(uint32 2, <('Gdynia, Działdowo County, Warmian-Masurian Voivodeship', '', false, [(0.93027949445787339, 0.34699627038777753)], [(0.93861053042695397, 0.35744550775024858)])>)>, <(uint32 2, <('Gdynia, Pomeranian Voivodeship', '', false, [(0.95149239024756216, 0.32358882203124067)], [(0.94858644845891815, 0.32579479952337237)])>)>]";
locations = [ (mkVariant [ (mkUint32 2) (mkVariant [ "Gda\324sk" "EPGD" true [ (mkTuple [ 0.9491682190584854 0.3223041410193837 ]) ] [ (mkTuple [ 0.9485864484589182 0.32579479952337237 ]) ] ]) ]) (mkVariant [ (mkUint32 2) (mkVariant [ "Gdynia, Dzia\322dowo 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 ]) ] ]) ]) ];
};

"system/locale" = {
region = "en_US.UTF-8";
};

"issue28/desktop/ibus/panel/emoji" = {
favorites = [ "\8211" "\8594" "\8593" "\8595" "\8482" "\\u00ad" "\176" "\\v" "\160" "\171" "\8451" ];
favorites = [ "\137" "\396" "\395" "\397" "\322" "\\u00ad" "\176" "\\v" "\160" "\171" "\297" ];
};

"issue28/org/gnome/desktop/input-sources" = {
Expand All @@ -384,7 +384,11 @@ with lib.hm.gvariant;
};

"issue28/org/gnome/clocks" = {
world-clocks = "[{'location': <(uint32 2, <('Houston', 'KHOU', false, [(0.51727195705981943, -1.6629933445314968)], [(0.51727195705981943, -1.6629933445314968)])>)>}, {'location': <(uint32 2, <('Singapore', 'WSAP', true, [(0.023852838928353343, 1.8136879868485383)], [(0.022568084612667797, 1.8126262332513803)])>)>}]";
world-clocks = [ {
location = mkVariant [ (mkUint32 2) (mkVariant [ "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 ]) ] ]) ];
} ];
};

"org/gnome/shell/extensions/arcmenu" = {
Expand Down
4 changes: 3 additions & 1 deletion output/headers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ with lib.hm.gvariant;
"uk/co/ibboard/cawbird" = {
round-avatars = false;
startup-accounts = [ "account_name" ];
window-geometry = "{'account_name': (30, 26, 694, 1182)}";
window-geometry = {
account_name = mkTuple [ 30 26 694 1182 ];
};
};

"org/gnome/shell/extensions/bluetooth_battery_indicator" = {
Expand Down
11 changes: 1 addition & 10 deletions src/CommandLine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,16 @@ data FileArgs = FileArgs
{ fileInput :: InputFilePath
, fileOutput :: OutputFilePath
, fileRoot :: Root
, fileTimeout :: ProcessTimeout
, fileEmojiSupport :: EmojiSupport
, fileVerbosity :: Verbosity
}

data StdinArgs = StdinArgs
{ stdinRoot :: Root
, stdinTimeout :: ProcessTimeout
, stdinEmojiSupport :: EmojiSupport
, stdinVerbosity :: Verbosity
}

timeoutArgs :: Parser ProcessTimeout
timeoutArgs = ProcessTimeout <$> option auto
(long "timeout" <> short 't' <> showDefault <> value 5 <> help
"Timeout in seconds for the conversion process"
)

verbosityArgs :: Parser Verbosity
verbosityArgs =
flag Normal Verbose (long "verbose" <> help "Verbose mode (debug)")
Expand All @@ -61,13 +53,12 @@ fileArgs = fmap FileInput $ FileArgs
)
)
<*> rootArgs
<*> timeoutArgs
<*> emojiArgs
<*> verbosityArgs

stdinArgs :: Parser Input
stdinArgs =
StdinInput <$> (StdinArgs <$> rootArgs <*> timeoutArgs <*> emojiArgs <*> verbosityArgs)
StdinInput <$> (StdinArgs <$> rootArgs <*> emojiArgs <*> verbosityArgs)

versionInfo :: String
versionInfo = unlines
Expand Down
Loading

0 comments on commit bcb1c60

Please sign in to comment.