All Projects → gvolpe → dconf2nix

gvolpe / dconf2nix

Licence: Apache-2.0 License
🐾 Convert Dconf files (e.g. Gnome Shell) to Nix, as expected by Home Manager

Programming Languages

Nix
1067 projects
haskell
3896 projects

Projects that are alternatives of or similar to dconf2nix

system
Declarative NixOS system configuration for all my machines
Stars: ✭ 14 (-72.55%)
Mutual labels:  nix, nixos, nixos-configuration, home-manager
nyx
⚙️Nix[OS] Configuration
Stars: ✭ 50 (-1.96%)
Mutual labels:  nix, nixos, nixos-configuration, home-manager
elemental
Elemental, the component parts of a Nix/OS development system.
Stars: ✭ 44 (-13.73%)
Mutual labels:  nix, nixos, nixos-configuration, home-manager
nixos-config
My NixOS configuration
Stars: ✭ 23 (-54.9%)
Mutual labels:  nix, nixos, nixos-configuration
digga
A flake utility library to craft shell-, home-, and hosts- environments.
Stars: ✭ 818 (+1503.92%)
Mutual labels:  nix, nixos, nixos-configuration
nix-config
My personal nix config
Stars: ✭ 32 (-37.25%)
Mutual labels:  nix, nixos, nixos-configuration
nixdots
I have no idea what the hell I'm doing
Stars: ✭ 46 (-9.8%)
Mutual labels:  nix, nixos, nixos-configuration
base16.nix
Quickly theme programs in your favourite base16 colorscheme
Stars: ✭ 61 (+19.61%)
Mutual labels:  nix, nixos, home-manager
dotfiles
No place like ~. Nix. All. The. Things.
Stars: ✭ 48 (-5.88%)
Mutual labels:  nix, nixos, home-manager
homeage
runtime decrypted age secrets for nix home manager
Stars: ✭ 43 (-15.69%)
Mutual labels:  nix, nixos, home-manager
dotnix
Shackled within an elaborate prison of my own design.
Stars: ✭ 35 (-31.37%)
Mutual labels:  nix, nixos, home-manager
dotfiles
Dotfiles
Stars: ✭ 25 (-50.98%)
Mutual labels:  nix, nixos, nixos-configuration
nix-home
A Nix Home Manager setup. I've now moved to a new configuration system at hugoreeves/elemental
Stars: ✭ 60 (+17.65%)
Mutual labels:  nix, nixos, home-manager
dotnix
nix stuff
Stars: ✭ 27 (-47.06%)
Mutual labels:  nix, nixos, nixos-configuration
nix-config
NixOS configuration (also on WSL)
Stars: ✭ 51 (+0%)
Mutual labels:  nix, nixos, nixos-configuration
impermanence
Modules to help you handle persistent state on systems with ephemeral root storage [maintainer=@talyz]
Stars: ✭ 401 (+686.27%)
Mutual labels:  nix, nixos, home-manager
nix-xdg
[WIP] Nix overlay for making programs xdg compliant
Stars: ✭ 18 (-64.71%)
Mutual labels:  nix, nixos, home-manager
nix-config
A collection of my system configs and dotfiles
Stars: ✭ 35 (-31.37%)
Mutual labels:  nix, nixos, home-manager
nix-rice
A library to functionally define your configuration and theme (rice) with Nix
Stars: ✭ 43 (-15.69%)
Mutual labels:  nix, nixos, home-manager
dotfiles
NixOS system config & Home-Manager user config
Stars: ✭ 43 (-15.69%)
Mutual labels:  nix, nixos, home-manager

dconf2nix

CI Status

A convenient converter of DConf files to Nix, as expected by Home Manager's dconf settings. So you can Nixify your Gnome Shell configuration 😉


Benchmarks

Take it with a grain of salt but on my machine it takes an average of 7.1ms to process a 349 lines configuration and generate a Nix file with 433 lines.

benchmarks

Introduction

Given the following dconf settings:

[org/gnome/desktop/peripherals/mouse]
natural-scroll=false
speed=-0.5

[org/gnome/desktop/peripherals/touchpad]
tap-to-click=false
two-finger-scrolling-enabled=true

[org/gnome/desktop/input-sources]
current=uint32 0
sources=[('xkb', 'us')]
xkb-options=[' terminate:ctrl_alt_bksp ', ' lv3:ralt_switch ', ' caps:ctrl_modifier ']

[org/gnome/desktop/screensaver]
picture-uri=' file:///home/gvolpe/Pictures/nixos.png '

You will get the following output when running dconf2nix:

{ lib, ... }:

let
  mkTuple = lib.hm.gvariant.mkTuple;
in
{
  dconf.settings = {
    "org/gnome/desktop/peripherals/mouse" = {
      natural-scroll = false;
      speed = -0.5;
    };

    "org/gnome/desktop/peripherals/touchpad" = {
      tap-to-click = false;
      two-finger-scrolling-enabled = true;
    };

    "org/gnome/desktop/input-sources" = {
      current = "uint32 0";
      sources = [ (mkTuple [ "xkb" "us" ]) ];
      xkb-options = [ "terminate:ctrl_alt_bksp" "lv3:ralt_switch" "caps:ctrl_modifier" ];
    };

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

}

It makes use of the Home Manager's dconf.settings key.

You can make changes in the UI and create a dump of your dconf file at any time, which you can Nixify so Home Manager can restore the next time you run home-manager switch. To create a dump, run the following command:

dconf dump / > dconf.settings

Run

The easiest way is to pipe the standard input to dconf2nix and expect the result in the standard output:

dconf dump / | dconf2nix > dconf.nix

If you have an input file instead, you can run the following command:

dconf2nix -i data/dconf.settings -o output/dconf.nix

Type --help for some more information.

dconf2nix - Nixify dconf configuration files

Usage: dconf2nix [-v|--version]
                 [[-r|--root ARG] [-t|--timeout ARG] [--verbose] |
                   (-i|--input ARG) (-o|--output ARG) [-r|--root ARG]
                   [-t|--timeout ARG] [--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)
  --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)
  --verbose                Verbose mode (debug)

Custom root

By default, dconf2nix expects the root to be /. If you want to create a dump of a custom root, you can use the --root flag. For example:

dconf dump /system/locale/ | dconf2nix --root system/locale > dconf.nix

This will generate an output similar to the one below.

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

  };
}

Supported types

For now, only types supported by Home Manager as specified here are supported. If there's enough interest, we might be able to work on supporting the full specification.

Due to the lack of support, dconf2nix parses dictionaries and list of variants as simple strings to avoid failing to parse a file and retain most of the information.

Gnome Shell configuration

Once you have your dconf.nix, you can import it via Home Manager.

{
  programs.home-manager.enable = true;

  imports = [
    ./dconf.nix
  ];
}

If you are using the Home Manager module for NixOS you can import it like so:

{
  home-manager.users.joe = { pkgs, ... }: {
    imports = [ ./dconf.nix ];
	# ...
  };
}

Installation

The simplest way is to install it via nix-env.

nix-env -i dconf2nix

Or if you want to pull the latest master.

nix-env -i -f https://github.com/gvolpe/dconf2nix/archive/master.tar.gz

You could also use Cachix to reduce the installation time.

Alternatively, here's an overlay for the binary you can use to avoid compiling it (only for Linux-x86-64).

self: super:

rec {
  dconf2nix = super.dconf2nix.overrideAttrs (
    old: rec {
      version = "v0.0.6";

      src = builtins.fetchurl {
        url    = "https://github.com/gvolpe/dconf2nix/releases/download/${version}/dconf2nix-linux-x86-64";
        sha256 = "1bh78hfgy4wnfdq184ck5yw72szllzl5sm7a3a4y46byq0xxklcd";
      };

      phases = ["installPhase" "patchPhase"];

      installPhase = ''
        mkdir -p $out/bin
        cp $src $out/bin/dconf2nix
        chmod +x $out/bin/dconf2nix
      '';
    }
  );
}

Have a look at the latest releases in case the README file gets outdated.

Troubleshooting

error

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

To find which section caused the error you can download d2n_util.sh (made by Broccoli):

curl https://raw.githubusercontent.com/broccoli5/Scripts/main/d2n_util.sh > d2n_util.sh && chmod +x d2n_util.sh

You can then run: dconf dump / | ./d2n_util.sh -t to create the sections and automaticaly test them. When creating a issue include both, the sections which failed the test and the errors from "d2n.log". For more options run ./d2n_util.sh -h

Do also consider the caveats mentioned above in the Supported Types section.

Development

To compile and run the tests locally.

cabal new-configure
cabal new-run dconf2nix-tests

To generate the static binary.

cabal new-configure --disable-executable-dynamic --ghc-option=-optl=-static --ghc-option=-optl=-pthread
nix-build

If everything goes well, the binary should be under result/bin/.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].