40 lines
1.2 KiB
Nix
40 lines
1.2 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
cfg = config.nix.shorturls;
|
|
|
|
configFile = pkgs.writeText "shorturl.json" (builtins.toJSON {
|
|
schemes = lib.mapAttrs (_: v: { template = v; }) cfg.schemes;
|
|
});
|
|
in {
|
|
options.nix.shorturls = {
|
|
enable = lib.mkEnableOption "nix-shorturl-plugin, user-defined short URL schemes for Nix flake references";
|
|
|
|
package = lib.mkPackageOption pkgs "nix-shorturl-plugin" {
|
|
default = null;
|
|
};
|
|
|
|
schemes = lib.mkOption {
|
|
type = lib.types.attrsOf lib.types.str;
|
|
default = {};
|
|
example = lib.literalExpression ''
|
|
{
|
|
myorg = "github:my-organization/{path}";
|
|
internal = "git+ssh://git.internal.corp/{path}";
|
|
gl = "gitlab:mycompany/{path}";
|
|
}
|
|
'';
|
|
description = ''
|
|
Attribute set of short URL schemes. Each key is the scheme name
|
|
and the value is the URL template. Use `{path}` as a placeholder
|
|
for the path component of the short URL.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
nix.settings.plugin-files = [ "${cfg.package}/lib/nix/plugins/libnix-shorturl-plugin.so" ];
|
|
|
|
environment.variables.NIX_SHORTURL_CONFIG = toString configFile;
|
|
};
|
|
}
|