Last active
April 22, 2023 20:17
-
-
Save tim-tx/7eb77fe78f419d0873d4b459464c6f63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ lib | |
, stdenv | |
, fetchFromGitHub | |
, flatbuffers | |
, libb2 | |
, libuv | |
, lmdb | |
, openssl | |
, perl | |
, perlPackages | |
, secp256k1 | |
, zlib | |
, zstd | |
}: | |
stdenv.mkDerivation { | |
pname = "strfry"; | |
version = "master-f192adb4-git"; | |
src = fetchFromGitHub { | |
owner = "hoytech"; | |
repo = "strfry"; | |
rev = "f192adb4982279f730c35f3d255cd75301239466"; | |
fetchSubmodules = true; | |
sha256 = "sha256-KIuEOQZYwuzN0HskQmO7vyfAO/W0ye5pJO6IunY/PDg="; | |
}; | |
patches = [ | |
./fix-make-rules.patch | |
]; | |
buildInputs = [ | |
flatbuffers | |
libb2 | |
libuv | |
lmdb | |
openssl | |
perl | |
perlPackages.TemplateToolkit | |
perlPackages.YAML | |
secp256k1 | |
zlib | |
zstd | |
]; | |
buildPhase = '' | |
make | |
''; | |
installPhase = '' | |
mkdir -p $out/bin | |
cp strfry $out/bin | |
''; | |
meta = with lib; { | |
homepage = "https://github.com/hoytech/strfry"; | |
description = "A nostr relay"; | |
platforms = platforms.linux; | |
license = licenses.gpl3; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/golpe/rules.mk b/golpe/rules.mk | |
index d8c83c2..c96c8d9 100644 | |
--- a/golpe/rules.mk | |
+++ b/golpe/rules.mk | |
@@ -46,7 +46,7 @@ build/golpe.h: golpe/golpe.h.tt golpe/gen-golpe.h.pl $(wildcard global.h) $(wild | |
%.d : ; | |
build/defaultDb.h: $(wildcard golpe.yaml) | |
- golpe/external/rasgueadb/rasgueadb-generate golpe.yaml build | |
+ perl golpe/external/rasgueadb/rasgueadb-generate golpe.yaml build | |
clean: | |
rm -rf $(BIN) src/*.o src/*.d build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, lib, pkgs, ... }: | |
let | |
cfg = config.services.strfry; | |
strfryConf = let | |
mkAtom = key: val: lib.generators.mkKeyValueDefault { | |
mkValueString = v: | |
if builtins.isString v then ''"${v}"'' | |
else lib.generators.mkValueStringDefault {} v; | |
} " = " key val; | |
mkSection = key: val: [ | |
"${key} {" | |
(map (x: " " + x) (mkSectionsAndAtoms val)) | |
"}" | |
]; | |
mkSectionOrAtom = key: val: | |
if builtins.isAttrs val then | |
mkSection key val | |
else | |
mkAtom key val; | |
mkSectionsAndAtoms = attrs: lib.lists.flatten (lib.mapAttrsToList mkSectionOrAtom attrs); | |
in pkgs.writeText "strfry.conf" ( | |
lib.lists.foldl (x: y: x + y + "\n") "" (mkSectionsAndAtoms cfg.settings) | |
); | |
in | |
{ | |
options.services.strfry = { | |
enable = lib.mkEnableOption (lib.mdDoc "strfry nostr relay"); | |
user = lib.mkOption { | |
type = lib.types.str; | |
default = "strfry"; | |
description = lib.mdDoc '' | |
User to run strfry as. | |
''; | |
}; | |
group = lib.mkOption { | |
type = lib.types.str; | |
default = "strfry"; | |
description = lib.mdDoc '' | |
Group to run strfry as. | |
''; | |
}; | |
settings = lib.mkOption { | |
type = lib.types.submodule { | |
freeformType = lib.types.lazyAttrsOf (lib.types.uniq lib.types.unspecified); | |
options.db = lib.mkOption { | |
type = lib.types.str; | |
default = "./strfry-db/"; | |
description = lib.mdDoc '' | |
Directory that contains the strfry LMDB database. If this | |
is a relative path, the directory will be created in the | |
service working directory (/var/lib/strfry) prior to | |
launching. | |
''; | |
}; | |
options.relay = lib.mkOption { | |
type = lib.types.submodule { | |
freeformType = lib.types.lazyAttrsOf (lib.types.uniq lib.types.unspecified); | |
options.nofiles = lib.mkOption { | |
type = lib.types.int; | |
default = 65536; | |
description = lib.mdDoc '' | |
Set OS-limit on maximum number of open files/sockets. | |
''; | |
}; | |
}; | |
default = { }; | |
}; | |
}; | |
default = { }; | |
description = lib.mdDoc '' | |
Configuration for strfry. See sample configuration | |
<https://github.com/hoytech/strfry/blob/master/strfry.conf> | |
for available options. | |
''; | |
}; | |
}; | |
config = let | |
workingDir = "/var/lib/strfry"; | |
dbIsRelative = builtins.substring 0 1 cfg.settings.db != "/"; | |
dbDir = if dbIsRelative then "${workingDir}/${cfg.settings.db}" else cfg.settings.db; | |
in lib.mkIf cfg.enable { | |
systemd.services.strfry = { | |
after = [ "network.target" ]; | |
wantedBy = [ "multi-user.target" ]; | |
serviceConfig = { | |
User = "strfry"; | |
Group = "strfry"; | |
WorkingDirectory = workingDir; | |
StateDirectory = builtins.baseNameOf workingDir; | |
Restart = "on-failure"; | |
ExecStart = "${pkgs.strfry}/bin/strfry --config=${strfryConf} relay"; | |
# LimitNOFILE = cfg.settings.relay.nofiles; | |
}; | |
}; | |
systemd.tmpfiles.rules = [ "d ${dbDir} 0750 strfry strfry -" ]; | |
users.groups.strfry = {}; | |
users.users.strfry = { | |
isSystemUser = true; | |
description = "strfry user"; | |
group = "strfry"; | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment