1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-14 07:09:45 +01:00
home-manager/modules/programs/papis.nix

93 lines
2.4 KiB
Nix
Raw Normal View History

2023-01-27 05:20:00 +01:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.papis;
defaultLibraries = remove null
(mapAttrsToList (n: v: if v.isDefault then n else null) cfg.libraries);
settingsIni = (lib.mapAttrs (n: v: v.settings) cfg.libraries) // {
settings = cfg.settings // { "default-library" = head defaultLibraries; };
};
in {
meta.maintainers = [ ];
2023-01-27 05:20:00 +01:00
options.programs.papis = {
enable = mkEnableOption "papis";
2023-01-27 05:20:00 +01:00
settings = mkOption {
type = with types; attrsOf (oneOf [ bool int str ]);
default = { };
example = literalExpression ''
{
editor = "nvim";
file-browser = "ranger"
add-edit = true;
}
'';
description = ''
2023-01-27 05:20:00 +01:00
Configuration written to
{file}`$XDG_CONFIG_HOME/papis/config`. See
<https://papis.readthedocs.io/en/latest/configuration.html>
2023-01-27 05:20:00 +01:00
for supported values.
'';
};
libraries = mkOption {
type = types.attrsOf (types.submodule ({ config, name, ... }: {
options = {
name = mkOption {
type = types.str;
default = name;
readOnly = true;
description = "This library's name.";
2023-01-27 05:20:00 +01:00
};
isDefault = mkOption {
type = types.bool;
default = false;
example = true;
description = ''
2023-01-27 05:20:00 +01:00
Whether this is a default library. There must be exactly one
default library.
'';
};
settings = mkOption {
type = with types; attrsOf (oneOf [ bool int str ]);
default = { };
example = literalExpression ''
{
dir = "~/papers/";
}
'';
description = ''
2023-01-27 05:20:00 +01:00
Configuration for this library.
'';
};
};
}));
description = "Attribute set of papis libraries.";
2023-01-27 05:20:00 +01:00
};
};
config = mkIf cfg.enable {
assertions = [{
assertion = cfg.libraries == { } || length defaultLibraries == 1;
message = "Must have exactly one default papis library, but found "
+ toString (length defaultLibraries)
+ optionalString (length defaultLibraries > 1)
(", namely " + concatStringsSep "," defaultLibraries);
}];
home.packages = [ pkgs.papis ];
xdg.configFile."papis/config" =
mkIf (cfg.libraries != { }) { text = generators.toINI { } settingsIni; };
};
}