nixos/dconf: refractor
remove `with lib;` profiles option now accepts packages in addition to paths. profiles option is no longer internal. cfgDir definition has been inlined. pulled GIO_EXTRA_MODULES inside mkif. removed pointless comments with section headings. defined profiles are now turned into package, allowing to simplify the db update logic.
This commit is contained in:
parent
da614d98e9
commit
cce75fa51e
|
@ -1,55 +1,50 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.programs.dconf;
|
||||
cfgDir = pkgs.symlinkJoin {
|
||||
name = "dconf-system-config";
|
||||
paths = map (x: "${x}/etc/dconf") cfg.packages;
|
||||
postBuild = ''
|
||||
mkdir -p $out/profile
|
||||
mkdir -p $out/db
|
||||
'' + (
|
||||
concatStringsSep "\n" (
|
||||
mapAttrsToList (
|
||||
name: path: ''
|
||||
ln -s ${path} $out/profile/${name}
|
||||
''
|
||||
) cfg.profiles
|
||||
)
|
||||
) + ''
|
||||
${pkgs.dconf}/bin/dconf update $out/db
|
||||
|
||||
# Generate dconf profile
|
||||
mkDconfProfile = name: value:
|
||||
pkgs.runCommand "dconf-profile" { } ''
|
||||
mkdir -p $out/etc/dconf/profile/
|
||||
cp ${value} $out/etc/dconf/profile/${name}
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
###### interface
|
||||
|
||||
options = {
|
||||
programs.dconf = {
|
||||
enable = mkEnableOption (lib.mdDoc "dconf");
|
||||
enable = lib.mkEnableOption (lib.mdDoc "dconf");
|
||||
|
||||
profiles = mkOption {
|
||||
type = types.attrsOf types.path;
|
||||
default = {};
|
||||
description = lib.mdDoc "Set of dconf profile files, installed at {file}`/etc/dconf/profiles/«name»`.";
|
||||
internal = true;
|
||||
profiles = lib.mkOption {
|
||||
type = with lib.types; attrsOf (oneOf [
|
||||
path
|
||||
package
|
||||
]);
|
||||
description = lib.mdDoc "Attrset of dconf profiles.";
|
||||
};
|
||||
|
||||
packages = mkOption {
|
||||
type = types.listOf types.package;
|
||||
default = [];
|
||||
packages = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.package;
|
||||
default = [ ];
|
||||
description = lib.mdDoc "A list of packages which provide dconf profiles and databases in {file}`/etc/dconf`.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
###### implementation
|
||||
config = lib.mkIf (cfg.profiles != { } || cfg.enable) {
|
||||
programs.dconf.packages = lib.mapAttrsToList mkDconfProfile cfg.profiles;
|
||||
|
||||
config = mkIf (cfg.profiles != {} || cfg.enable) {
|
||||
environment.etc.dconf = mkIf (cfg.profiles != {} || cfg.packages != []) {
|
||||
source = cfgDir;
|
||||
environment.etc.dconf = lib.mkIf (cfg.packages != [ ]) {
|
||||
source = pkgs.symlinkJoin {
|
||||
name = "dconf-system-config";
|
||||
paths = map (x: "${x}/etc/dconf") cfg.packages;
|
||||
nativeBuildInputs = [ (lib.getBin pkgs.dconf) ];
|
||||
postBuild = ''
|
||||
if test -d $out/db; then
|
||||
dconf update $out/db
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
services.dbus.packages = [ pkgs.dconf ];
|
||||
|
@ -59,8 +54,9 @@ in
|
|||
# For dconf executable
|
||||
environment.systemPackages = [ pkgs.dconf ];
|
||||
|
||||
# Needed for unwrapped applications
|
||||
environment.sessionVariables.GIO_EXTRA_MODULES = mkIf cfg.enable [ "${pkgs.dconf.lib}/lib/gio/modules" ];
|
||||
environment.sessionVariables = lib.mkIf cfg.enable {
|
||||
# Needed for unwrapped applications
|
||||
GIO_EXTRA_MODULES = [ "${pkgs.dconf.lib}/lib/gio/modules" ];
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue