mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +01:00
papis: add module
This commit is contained in:
parent
bb4b25b302
commit
08a778d803
7 changed files with 150 additions and 0 deletions
3
.github/CODEOWNERS
vendored
3
.github/CODEOWNERS
vendored
|
@ -249,6 +249,9 @@ Makefile @thiagokokada
|
|||
/modules/programs/pandoc.nix @kirelagin
|
||||
/tests/modules/programs/pandoc @kirelagin
|
||||
|
||||
/modules/programs/papis.nix @marsam
|
||||
/tests/modules/programs/papis @marsam
|
||||
|
||||
/modules/programs/password-store.nix @pacien
|
||||
|
||||
/modules/programs/pazi.nix @marsam
|
||||
|
|
|
@ -886,6 +886,13 @@ in
|
|||
'wayland.windowManager.sway.config.[window|floating].titlebar' now default to 'true'.
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
time = "2023-01-28T17:35:49+00:00";
|
||||
message = ''
|
||||
A new module is available: 'programs.papis'.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -144,6 +144,7 @@ let
|
|||
./programs/oh-my-posh.nix
|
||||
./programs/opam.nix
|
||||
./programs/pandoc.nix
|
||||
./programs/papis.nix
|
||||
./programs/password-store.nix
|
||||
./programs/pazi.nix
|
||||
./programs/pet.nix
|
||||
|
|
91
modules/programs/papis.nix
Normal file
91
modules/programs/papis.nix
Normal file
|
@ -0,0 +1,91 @@
|
|||
{ 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 = [ maintainers.marsam ];
|
||||
|
||||
options.programs.papis = {
|
||||
enable = mkEnableOption "papis";
|
||||
|
||||
settings = mkOption {
|
||||
type = with types; attrsOf (oneOf [ bool int str ]);
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{
|
||||
editor = "nvim";
|
||||
file-browser = "ranger"
|
||||
add-edit = true;
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
Configuration written to
|
||||
<filename>$XDG_CONFIG_HOME/papis/config</filename>. See
|
||||
<link xlink:href="https://papis.readthedocs.io/en/latest/configuration.html"/>
|
||||
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.";
|
||||
};
|
||||
|
||||
isDefault = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = true;
|
||||
description = ''
|
||||
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 = ''
|
||||
Configuration for this library.
|
||||
'';
|
||||
};
|
||||
};
|
||||
}));
|
||||
};
|
||||
};
|
||||
|
||||
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; };
|
||||
};
|
||||
}
|
|
@ -102,6 +102,7 @@ import nmt {
|
|||
./modules/programs/nushell
|
||||
./modules/programs/oh-my-posh
|
||||
./modules/programs/pandoc
|
||||
./modules/programs/papis
|
||||
./modules/programs/pet
|
||||
./modules/programs/pistol
|
||||
./modules/programs/pls
|
||||
|
|
1
tests/modules/programs/papis/default.nix
Normal file
1
tests/modules/programs/papis/default.nix
Normal file
|
@ -0,0 +1 @@
|
|||
{ papis = ./papis.nix; }
|
46
tests/modules/programs/papis/papis.nix
Normal file
46
tests/modules/programs/papis/papis.nix
Normal file
|
@ -0,0 +1,46 @@
|
|||
{ ... }:
|
||||
|
||||
{
|
||||
programs.papis = {
|
||||
enable = true;
|
||||
settings = {
|
||||
picktool = "fzf";
|
||||
file-browser = "ranger";
|
||||
add-edit = true;
|
||||
};
|
||||
libraries = {
|
||||
papers = {
|
||||
isDefault = true;
|
||||
settings = {
|
||||
dir = "~/papers";
|
||||
opentool = "okular";
|
||||
};
|
||||
};
|
||||
books.settings = {
|
||||
dir = "~/books";
|
||||
opentool = "firefox";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.papis = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContent home-files/.config/papis/config \
|
||||
${builtins.toFile "papis-expected-settings.ini" ''
|
||||
[books]
|
||||
dir=~/books
|
||||
opentool=firefox
|
||||
|
||||
[papers]
|
||||
dir=~/papers
|
||||
opentool=okular
|
||||
|
||||
[settings]
|
||||
add-edit=true
|
||||
default-library=papers
|
||||
file-browser=ranger
|
||||
picktool=fzf
|
||||
''}
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue