From ba9e3c3066ddc19a711287a99a67edd2ad0c4322 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Wed, 26 Mar 2025 14:27:54 +0800 Subject: [PATCH] lib: init formats subset --- lib/default.nix | 4 ++++ lib/formats.nix | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/formats.nix diff --git a/lib/default.nix b/lib/default.nix index 24160a23..5fce7623 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -15,6 +15,10 @@ in pkgs.lib.makeExtensible (self: math = callLib ./math.nix; xdg = callLib ./xdg.nix; + # Just like from its inspiration, this contains Nix-representable data + # formats and won't have any attributes exported at the top-level. + formats = callLib ./formats.nix; + # For future references, these are the only attributes that are going to be # exported as part of nixpkgs overlay. fetchers = callLib ./fetchers; diff --git a/lib/formats.nix b/lib/formats.nix new file mode 100644 index 00000000..41f25344 --- /dev/null +++ b/lib/formats.nix @@ -0,0 +1,21 @@ +{ lib, pkgs, self }: + +{ + # The gnome-session config files uses one from GLib. See the following link + # at for details about the + # keyfile formatting and possibly the Desktop Entry specification at + # . + glibKeyfile = {}: { + type = with lib.types; + let + valueType = oneOf [ bool float int str (listOf valueType) ] // { + description = + "GLib keyfile atom (bool, int, float, string, or a list of the previous atoms)"; + }; + in attrsOf (attrsOf valueType); + + generate = name: value: + pkgs.callPackage + ({ lib, writeText }: writeText name (lib.generators.toDconfINI value)); + }; +}