all repos — scriptura @ db065bc49d2639788545b2e9060d45c82e78c99c

a corner in $HOME for your scripts

add home-manager module

Alin
commit

db065bc49d2639788545b2e9060d45c82e78c99c

parent

baa93ca20f6525c97091d5ece5861d4526b5591c

3 files changed, 123 insertions(+), 8 deletions(-)

changed files
M README.mdREADME.md
@@ -40,21 +40,21 @@ scriptura.overlays.default
] ``` -And then configure the script-directory module: +And then configure the scriptura module: ```nix -programs.script-directory = { +programs.scriptura = { enable = true; - package = pkgs.scriptura + package = pkgs.scriptura; settings = { - SD_ROOT = "${config.home.homeDirectory}/.sd"; - SD_EDITOR = "nvim"; - SD_CAT = "lolcat"; + ROOT = "${config.home.homeDirectory}/.sd"; + EDITOR = "nvim"; + CAT = "lolcat"; }; }; ``` -Any `SD_*` variables will be respected as long as their `SCRIPTURA_*` counterpart is not set. +The `settings` attribute accepts environment variable suffixes (e.g., `ROOT` becomes `SCRIPTURA_ROOT`). For a list of available options, see the [configuration documentation](#configuration). ### Shorter command name
@@ -72,11 +72,13 @@
In home-manager you can do this with ```nix -home.shellAliases = { +programs.scriptura.shellAliases = { sf = "scriptura run"; sfm = "scriptura"; }; ``` + +(This is just another way to set `home.shellAliases`). ## Usage
@@ -117,3 +119,24 @@ - `SCRIPTURA_EDITOR`: used by `scriptura edit foo` and `scriptura new foo`. Defaults to `$VISUAL`, then `$EDITOR`, then, if neither of those are set, tries `vim`,`nano`, and finally, `vi`.
- `SCRIPTURA_CAT`: program used when printing files, in case you want to use something like `bat`. Defaults to `cat`. If not defined, each variable will try the `SD_` equivalent before using default values. + +In home-manager, use the `settings` option. Prefixes are optional (added by module; this won't overwrite `$EDITOR`) + +```nix +programs.scriptura.settings = { + ROOT = "${config.home.homeDirectory}/.sd"; + EDITOR = "nvim"; + CAT = "lolcat"; +}; +``` + +Or using full variable names: + +```nix +programs.scriptura.settings = { + SCRIPTURA_ROOT = "${config.home.homeDirectory}/.sd"; + SD_EDITOR = "nvim"; # also works for easy migration +}; +``` + +The `SD_` prefixed variables are automatically converted to their `SCRIPTURA_` equivalents. If both prefixes are defined for the same variable, `SCRIPTURA_` takes precedence.
M flake.nixflake.nix
@@ -53,6 +53,11 @@ default = scriptura;
} ); + homeModules = { + default = self.homeModules.scriptura; + scriptura = import ./nix/home-manager; + }; + overlays = { default = final: prev: { scriptura = self.packages.${prev.system}.scriptura;
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; + }; +}