treewide: replace attrs by formats or types.anything

This commit is contained in:
Nicolas Berbiche 2020-11-29 21:54:55 -05:00
parent c1faa848c5
commit 44f9d68d8c
No known key found for this signature in database
GPG key ID: F3308ADE984B83CB
20 changed files with 134 additions and 64 deletions

View file

@ -3,9 +3,8 @@
with lib; with lib;
let let
cfg = config.programs.alacritty; cfg = config.programs.alacritty;
yamlFormat = pkgs.formats.yaml { };
in { in {
options = { options = {
programs.alacritty = { programs.alacritty = {
@ -19,7 +18,7 @@ in {
}; };
settings = mkOption { settings = mkOption {
type = types.attrs; type = yamlFormat.type;
default = { }; default = { };
example = literalExample '' example = literalExample ''
{ {
@ -51,6 +50,11 @@ in {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
xdg.configFile."alacritty/alacritty.yml" = mkIf (cfg.settings != { }) { xdg.configFile."alacritty/alacritty.yml" = mkIf (cfg.settings != { }) {
# TODO: Replace by the generate function but need to figure out how to
# handle the escaping first.
#
# source = yamlFormat.generate "alacritty.yml" cfg.settings;
text = text =
replaceStrings [ "\\\\" ] [ "\\" ] (builtins.toJSON cfg.settings); replaceStrings [ "\\\\" ] [ "\\" ] (builtins.toJSON cfg.settings);
}; };

View file

@ -16,7 +16,7 @@ with lib;
}; };
extraConfig = mkOption { extraConfig = mkOption {
type = types.attrs; type = types.attrsOf types.anything;
default = { }; default = { };
example = { select_query = ""; }; example = { select_query = ""; };
description = '' description = ''

View file

@ -7,6 +7,8 @@ let
cfg = config.programs.astroid; cfg = config.programs.astroid;
jsonFormat = pkgs.formats.json { };
astroidAccounts = astroidAccounts =
filterAttrs (n: v: v.astroid.enable) config.accounts.email.accounts; filterAttrs (n: v: v.astroid.enable) config.accounts.email.accounts;
@ -36,8 +38,7 @@ let
} // astroid.extraConfig; } // astroid.extraConfig;
# See https://github.com/astroidmail/astroid/wiki/Configuration-Reference # See https://github.com/astroidmail/astroid/wiki/Configuration-Reference
configFile = mailAccounts: finalConfig = let
let
template = fromJSON (readFile ./astroid-config-template.json); template = fromJSON (readFile ./astroid-config-template.json);
astroidConfig = foldl' recursiveUpdate template [ astroidConfig = foldl' recursiveUpdate template [
{ {
@ -48,7 +49,7 @@ let
cfg.extraConfig cfg.extraConfig
cfg.externalEditor cfg.externalEditor
]; ];
in builtins.toJSON astroidConfig; in astroidConfig;
in { in {
options = { options = {
@ -90,9 +91,13 @@ in {
}; };
extraConfig = mkOption { extraConfig = mkOption {
type = types.attrs; type = jsonFormat.type;
default = { }; default = { };
example = { poll.interval = 0; }; example = literalExample ''
{
poll.interval = 0;
}
'';
description = '' description = ''
JSON config that will override the default Astroid configuration. JSON config that will override the default Astroid configuration.
''; '';
@ -107,13 +112,8 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ pkgs.astroid ]; home.packages = [ pkgs.astroid ];
xdg.configFile."astroid/config".source = pkgs.runCommand "out.json" { xdg.configFile."astroid/config".source =
json = configFile astroidAccounts; jsonFormat.generate "astroid-config" finalConfig;
preferLocalBuild = true;
allowSubstitutes = false;
} ''
echo -n "$json" | ${pkgs.jq}/bin/jq . > $out
'';
xdg.configFile."astroid/poll.sh" = { xdg.configFile."astroid/poll.sh" = {
executable = true; executable = true;

View file

@ -6,6 +6,8 @@ let
cfg = config.programs.beets; cfg = config.programs.beets;
yamlFormat = pkgs.formats.yaml { };
in { in {
meta.maintainers = [ maintainers.rycee ]; meta.maintainers = [ maintainers.rycee ];
@ -39,7 +41,7 @@ in {
}; };
settings = mkOption { settings = mkOption {
type = types.attrs; type = yamlFormat.type;
default = { }; default = { };
description = '' description = ''
Configuration written to Configuration written to
@ -52,7 +54,7 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
xdg.configFile."beets/config.yaml".text = xdg.configFile."beets/config.yaml".source =
builtins.toJSON config.programs.beets.settings; yamlFormat.generate "beets-config" cfg.settings;
}; };
} }

View file

@ -5,16 +5,8 @@ with lib;
let let
cfg = config.programs.direnv; cfg = config.programs.direnv;
configFile = config:
pkgs.runCommand "config.toml" { tomlFormat = pkgs.formats.toml { };
buildInputs = [ pkgs.remarshal ];
preferLocalBuild = true;
allowSubstitutes = false;
} ''
remarshal -if json -of toml \
< ${pkgs.writeText "config.json" (builtins.toJSON config)} \
> $out
'';
in { in {
meta.maintainers = [ maintainers.rycee ]; meta.maintainers = [ maintainers.rycee ];
@ -23,7 +15,7 @@ in {
enable = mkEnableOption "direnv, the environment switcher"; enable = mkEnableOption "direnv, the environment switcher";
config = mkOption { config = mkOption {
type = types.attrs; type = tomlFormat.type;
default = { }; default = { };
description = '' description = ''
Configuration written to Configuration written to
@ -80,8 +72,9 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ pkgs.direnv ]; home.packages = [ pkgs.direnv ];
xdg.configFile."direnv/config.toml" = xdg.configFile."direnv/config.toml" = mkIf (cfg.config != { }) {
mkIf (cfg.config != { }) { source = configFile cfg.config; }; source = tomlFormat.generate "direnv-config" cfg.config;
};
xdg.configFile."direnv/direnvrc" = let xdg.configFile."direnv/direnvrc" = let
text = concatStringsSep "\n" (optional (cfg.stdlib != "") cfg.stdlib text = concatStringsSep "\n" (optional (cfg.stdlib != "") cfg.stdlib

View file

@ -101,7 +101,7 @@ let
}; };
contents = mkOption { contents = mkOption {
type = types.attrs; type = types.attrsOf types.anything;
default = { }; default = { };
description = '' description = ''
Configuration to include. If empty then a path must be given. Configuration to include. If empty then a path must be given.

View file

@ -23,7 +23,7 @@ in {
config = mkOption { config = mkOption {
default = { }; default = { };
type = types.attrs; type = types.attrsOf types.anything;
description = '' description = ''
Add terms to the <filename>matplotlibrc</filename> file to Add terms to the <filename>matplotlibrc</filename> file to
control the default matplotlib behavior. control the default matplotlib behavior.

View file

@ -6,6 +6,8 @@ let
cfg = config.programs.mercurial; cfg = config.programs.mercurial;
iniFormat = pkgs.formats.ini { };
in { in {
options = { options = {
@ -30,19 +32,19 @@ in {
}; };
aliases = mkOption { aliases = mkOption {
type = types.attrs; type = types.attrsOf types.anything;
default = { }; default = { };
description = "Mercurial aliases to define."; description = "Mercurial aliases to define.";
}; };
extraConfig = mkOption { extraConfig = mkOption {
type = types.either types.attrs types.lines; type = types.either (types.attrsOf types.anything) types.lines;
default = { }; default = { };
description = "Additional configuration to add."; description = "Additional configuration to add.";
}; };
iniContent = mkOption { iniContent = mkOption {
type = types.attrsOf types.attrs; type = iniFormat.type;
internal = true; internal = true;
}; };
@ -71,7 +73,8 @@ in {
username = cfg.userName + " <" + cfg.userEmail + ">"; username = cfg.userName + " <" + cfg.userEmail + ">";
}; };
xdg.configFile."hg/hgrc".text = generators.toINI { } cfg.iniContent; xdg.configFile."hg/hgrc".source =
iniFormat.generate "hgrc" cfg.iniContent;
} }
(mkIf (cfg.ignores != [ ] || cfg.ignoresRegexp != [ ]) { (mkIf (cfg.ignores != [ ] || cfg.ignoresRegexp != [ ]) {

View file

@ -156,7 +156,7 @@ in {
}; };
configure = mkOption { configure = mkOption {
type = types.attrs; type = types.attrsOf types.anything;
default = { }; default = { };
example = literalExample '' example = literalExample ''
configure = { configure = {

View file

@ -78,7 +78,7 @@ in {
}; };
settings = mkOption { settings = mkOption {
type = types.attrs; type = types.attrsOf types.anything;
default = { }; default = { };
description = '' description = ''
Options to add to qutebrowser <filename>config.py</filename> file. Options to add to qutebrowser <filename>config.py</filename> file.

View file

@ -40,7 +40,7 @@ in {
enable = mkEnableOption "Task Warrior"; enable = mkEnableOption "Task Warrior";
config = mkOption { config = mkOption {
type = types.attrs; type = types.attrsOf types.anything;
default = { }; default = { };
example = literalExample '' example = literalExample ''
{ {

View file

@ -124,7 +124,7 @@ in {
extraConfig = mkOption { extraConfig = mkOption {
default = { }; default = { };
type = types.attrs; type = types.attrsOf types.anything;
description = "Additional configuration to add."; description = "Additional configuration to add.";
example = { "shading" = 15; }; example = { "shading" = 15; };
}; };

View file

@ -8,6 +8,8 @@ let
vscodePname = cfg.package.pname; vscodePname = cfg.package.pname;
jsonFormat = pkgs.formats.json { };
configDir = { configDir = {
"vscode" = "Code"; "vscode" = "Code";
"vscode-insiders" = "Code - Insiders"; "vscode-insiders" = "Code - Insiders";
@ -46,7 +48,7 @@ in {
}; };
userSettings = mkOption { userSettings = mkOption {
type = types.attrs; type = jsonFormat.type;
default = { }; default = { };
example = literalExample '' example = literalExample ''
{ {
@ -125,10 +127,10 @@ in {
toSymlink = concatMap toPaths cfg.extensions; toSymlink = concatMap toPaths cfg.extensions;
in foldr (a: b: a // b) { in foldr (a: b: a // b) {
"${configFilePath}" = mkIf (cfg.userSettings != { }) { "${configFilePath}" = mkIf (cfg.userSettings != { }) {
text = builtins.toJSON cfg.userSettings; source = jsonFormat.generate "vscode-user-settings" cfg.userSettings;
}; };
"${keybindingsFilePath}" = mkIf (cfg.keybindings != [ ]) { "${keybindingsFilePath}" = mkIf (cfg.keybindings != [ ]) {
text = builtins.toJSON cfg.keybindings; source = jsonFormat.generate "vscode-keybindings" cfg.keybindings;
}; };
} toSymlink; } toSymlink;
}; };

View file

@ -5,11 +5,13 @@ with lib;
let let
cfg = config.services.dwm-status; cfg = config.services.dwm-status;
jsonFormat = pkgs.formats.json { };
features = [ "audio" "backlight" "battery" "cpu_load" "network" "time" ]; features = [ "audio" "backlight" "battery" "cpu_load" "network" "time" ];
configText = builtins.toJSON ({ inherit (cfg) order; } // cfg.extraConfig); finalConfig = { inherit (cfg) order; } // cfg.extraConfig;
configFile = pkgs.writeText "dwm-status.json" configText; configFile = jsonFormat.generate "dwm-status.json" finalConfig;
in { in {
options = { options = {
@ -30,7 +32,7 @@ in {
}; };
extraConfig = mkOption { extraConfig = mkOption {
type = types.attrs; type = jsonFormat.type;
default = { }; default = { };
example = literalExample '' example = literalExample ''
{ {

View file

@ -6,12 +6,14 @@ let
cfg = config.services.hound; cfg = config.services.hound;
configFile = pkgs.writeText "hound-config.json" (builtins.toJSON { jsonFormat = pkgs.formats.json { };
configFile = jsonFormat.generate "hound-config.json" {
max-concurrent-indexers = cfg.maxConcurrentIndexers; max-concurrent-indexers = cfg.maxConcurrentIndexers;
dbpath = cfg.databasePath; dbpath = cfg.databasePath;
repos = cfg.repositories; repos = cfg.repositories;
health-check-url = "/healthz"; health-check-url = "/healthz";
}); };
houndOptions = [ "--addr ${cfg.listenAddress}" "--conf ${configFile}" ]; houndOptions = [ "--addr ${cfg.listenAddress}" "--conf ${configFile}" ];
@ -41,7 +43,7 @@ in {
}; };
repositories = mkOption { repositories = mkOption {
type = types.attrsOf (types.uniq types.attrs); type = types.attrsOf jsonFormat.type;
default = { }; default = { };
example = literalExample '' example = literalExample ''
{ {

View file

@ -6,6 +6,8 @@ let
cfg = config.services.xsuspender; cfg = config.services.xsuspender;
iniFormat = pkgs.formats.ini { };
xsuspenderOptions = types.submodule { xsuspenderOptions = types.submodule {
options = { options = {
matchWmClassContains = mkOption { matchWmClassContains = mkOption {
@ -139,7 +141,7 @@ in {
}; };
iniContent = mkOption { iniContent = mkOption {
type = types.attrsOf types.attrs; type = iniFormat.type;
internal = true; internal = true;
}; };
}; };
@ -170,7 +172,8 @@ in {
# To make the xsuspender tool available. # To make the xsuspender tool available.
home.packages = [ pkgs.xsuspender ]; home.packages = [ pkgs.xsuspender ];
xdg.configFile."xsuspender.conf".text = generators.toINI { } cfg.iniContent; xdg.configFile."xsuspender.conf".source =
iniFormat.generate "xsuspender.conf" cfg.iniContent;
systemd.user.services.xsuspender = { systemd.user.services.xsuspender = {
Unit = { Unit = {

View file

@ -1,4 +1,5 @@
{ {
alacritty-example-settings = ./example-settings.nix; alacritty-example-settings = ./example-settings.nix;
alacritty-empty-settings = ./empty-settings.nix; alacritty-empty-settings = ./empty-settings.nix;
alacritty-merging-settings = ./settings-merging.nix;
} }

View file

@ -0,0 +1 @@
{"font":{"bold":{"family":"SFMono"},"normal":{"family":"SFMono"}},"key_bindings":[{"chars":"\x0c","key":"K","mods":"Control"}],"window":{"dimensions":{"columns":200,"lines":3}}}

View file

@ -0,0 +1,39 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
programs.alacritty = {
enable = true;
package = pkgs.writeScriptBin "dummy-alacritty" "";
settings = {
window.dimensions = {
lines = 3;
columns = 200;
};
key_bindings = [{
key = "K";
mods = "Control";
chars = "\\x0c";
}];
font = let
defaultFont =
lib.mkMerge [ (lib.mkIf true "SFMono") (lib.mkIf false "Iosevka") ];
in {
normal.family = defaultFont;
bold.family = defaultFont;
};
};
};
nmt.script = ''
assertFileContent \
home-files/.config/alacritty/alacritty.yml \
${./settings-merging-expected.yml}
'';
};
}

View file

@ -27,7 +27,25 @@ let
else else
".config/Code/User/keybindings.json"; ".config/Code/User/keybindings.json";
expectedJson = pkgs.writeText "expected.json" (builtins.toJSON bindings); expectedJson = pkgs.writeText "expected.json" ''
[
{
"command": "editor.action.clipboardCopyAction",
"key": "ctrl+c",
"when": "textInputFocus && false"
},
{
"command": "deleteFile",
"key": "ctrl+c",
"when": ""
},
{
"command": "deleteFile",
"key": "d",
"when": "explorerViewletVisible"
}
]
'';
in { in {
config = { config = {
programs.vscode = { programs.vscode = {