all repos — scriptura @ db065bc49d2639788545b2e9060d45c82e78c99c

a corner in $HOME for your scripts

add home-manager module

Alin
commit

db065bc49d2639788545b2e9060d45c82e78c99c

parent

baa93ca20f6525c97091d5ece5861d4526b5591c

1 file changed, 87 insertions(+), 0 deletions(-)

changed files
A nix/home-manager/default.nix
@@ -0,0 +1,87 @@
+{ + config, + pkgs, + lib, + ... +}: +let + inherit (lib) + mkEnableOption + mkPackageOption + mkOption + mkIf + types + literalExpression + filterAttrs + hasPrefix + hasInfix + mapAttrs' + removePrefix + nameValuePair + ; + cfg = config.programs.scriptura; +in +{ + options.programs.scriptura = { + enable = mkEnableOption "scriptura"; + + package = mkPackageOption pkgs "scriptura" { }; + + settings = mkOption { + default = { }; + type = types.attrsOf types.str; + example = literalExpression '' + { + SCRIPTURA_ROOT = "''${config.home.homeDirectory}/.sd"; + SCRIPTURA_EDITOR = "nvim"; + SCRIPTURA_CAT = "lolcat"; + } + ''; + description = '' + Scriptura configuration, for options take a look at the + [documentation](https://git.alin.ovh/scriptura). + ''; + }; + + shellAliases = mkOption { + default = { }; + type = types.attrsOf types.str; + example = literalExpression '' + { + sf = "scriptura run"; + sfm = "scriptura"; + } + ''; + description = '' + Shell aliases for the scriptura command. This makes it easier to use + shorter aliases like `sf` and `sfm`. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + home.sessionVariables = + let + scripturaSettings = filterAttrs (name: value: hasPrefix "SCRIPTURA_" name) cfg.settings; + + sdSettings = filterAttrs (name: value: hasPrefix "SD_" name) cfg.settings; + + sdConverted = mapAttrs' ( + name: value: + let + suffix = removePrefix "SD_" name; + in + nameValuePair ("SCRIPTURA_" + suffix) value + ) sdSettings; + + unprefixed = filterAttrs (name: value: !(hasInfix "_" name)) cfg.settings; + + unprefixedConverted = mapAttrs' (name: value: nameValuePair ("SCRIPTURA_" + name) value) unprefixed; + in + unprefixedConverted // sdConverted // scripturaSettings; + + home.shellAliases = cfg.shellAliases; + }; +}