# Build-time parts of the bugpass extension (kept out of extension/ so # they are not zipped into the xpi). Returns { lib, host }. { pkgs, ext ? ../extension }: let lesspass = pkgs.fetchFromGitHub { owner = "lesspass"; repo = "lesspass"; rev = "d8f29da390d4492a5ea7c106779c93f71aa976ff"; hash = "sha256-4BqNYIQFozNEf+XEMdb3uTqjU9JyadadF9DQUIyMtxk="; }; core = "${lesspass}/packages/lesspass/src"; in { # lesspass.js (bundled LessPass core) + psl.js (Public Suffix List rules), checked against official vectors. lib = pkgs.runCommand "bugpass-lib" { nativeBuildInputs = [ pkgs.esbuild pkgs.nodejs pkgs.python3 ]; } '' mkdir -p $out echo 'export * from "${core}/index.ts"; export { FingerprintIcons } from "${core}/fingerprint/fingerprint.ts";' > entry.ts esbuild entry.ts --bundle --format=esm --target=es2022 --outfile=$out/lesspass.js python3 - ${pkgs.publicsuffix-list}/share/publicsuffix/public_suffix_list.dat > $out/psl.js <<'EOF' import json, sys def idna(rule): return ".".join(l if l in ("*", "!") else l.encode("idna").decode() for l in rule.split(".")) rules = [] for line in open(sys.argv[1], encoding="utf-8"): r = line.split()[0] if line.strip() else "" if r and not r.startswith("//"): bang = r.startswith("!") rules.append(("!" if bang else "") + idna(r.lstrip("!"))) print("export default new Set(" + json.dumps(rules, separators=(",", ":")) + ");") EOF cp $out/*.js ${ext}/domain.js ${ext}/icons.js ${ext}/background.js . && cp ${./test.mjs} test.mjs && cp ${./test-bg.mjs} test-bg.mjs node test.mjs && node test-bg.mjs ''; # Native messaging host: stores profiles (never passwords) in $XDG_DATA_HOME/bugpass/profiles.json. host = pkgs.runCommand "bugpass-host" { nativeBuildInputs = [ pkgs.python3 ]; } '' install -Dm755 ${pkgs.writeScript "bugpass-host" "#!${pkgs.python3}/bin/python3\n${builtins.readFile ./host.py}"} $out/bin/bugpass-host mkdir -p $out/lib/mozilla/native-messaging-hosts cat > $out/lib/mozilla/native-messaging-hosts/bugpass.json <