nix-packages/ipfs/kubo/default.nix

78 lines
2.7 KiB
Nix
Raw Normal View History

2023-05-09 16:42:05 +00:00
{
buildGoApplication,
fetchFromGitHub,
gnumake,
stdenv,
openssl,
pkg-config,
writeScript,
}: let
source = builtins.fromJSON (builtins.readFile ./source.json);
src = stdenv.mkDerivation {
pname = "kubo-source";
version = source.date;
src = fetchFromGitHub {
owner = "ipfs";
repo = "kubo";
inherit (source) rev sha256;
};
buildPhase = "";
installPhase = ''
cp -r $src $out
chmod -R +w $out
2023-05-10 08:11:19 +00:00
cd $out
2023-05-09 16:42:05 +00:00
cp ${./go.mod} go.mod
cp ${./go.sum} go.sum
echo -e "\nstorjds storj.io/ipfs-go-ds-storj/plugin 0" >> plugin/loader/preload_list
patchShebangs .
'';
};
in
buildGoApplication rec {
pname = "kubo";
version = source.date;
inherit src;
modules = ./gomod2nix.toml;
buildInputs = [openssl];
nativeBuildInputs = [gnumake pkg-config];
subPackages = ["cmd/ipfs"];
tags = ["openssl"];
postPatch = ''
substituteInPlace 'misc/systemd/ipfs.service' \
--replace '/usr/bin/ipfs' "$out/bin/ipfs"
substituteInPlace 'misc/systemd/ipfs-hardened.service' \
--replace '/usr/bin/ipfs' "$out/bin/ipfs"
'';
2023-05-10 07:29:31 +00:00
outputs = ["out" "systemd_unit" "systemd_unit_hardened"];
2023-05-10 07:21:29 +00:00
buildPhase = ''
2023-05-21 14:41:36 +00:00
make build
2023-05-10 07:21:29 +00:00
'';
2023-05-09 16:42:05 +00:00
2023-05-10 07:21:29 +00:00
installPhase = ''
GOBIN=$out/bin make install
2023-05-10 07:29:31 +00:00
install --mode=444 -D 'misc/systemd/ipfs-api.socket' "$systemd_unit/etc/systemd/system/ipfs-api.socket"
install --mode=444 -D 'misc/systemd/ipfs-gateway.socket' "$systemd_unit/etc/systemd/system/ipfs-gateway.socket"
install --mode=444 -D 'misc/systemd/ipfs.service' "$systemd_unit/etc/systemd/system/ipfs.service"
install --mode=444 -D 'misc/systemd/ipfs-api.socket' "$systemd_unit_hardened/etc/systemd/system/ipfs-api.socket"
install --mode=444 -D 'misc/systemd/ipfs-gateway.socket' "$systemd_unit_hardened/etc/systemd/system/ipfs-gateway.socket"
install --mode=444 -D 'misc/systemd/ipfs-hardened.service' "$systemd_unit_hardened/etc/systemd/system/ipfs.service"
2023-05-09 16:42:05 +00:00
'';
2023-08-22 12:10:26 +00:00
postConfigure = ''
chmod -R +w vendor/
for f in $(find vendor/github.com/ipfs/boxo/gateway/assets -type l) vendor/github.com/ipfs/go-graphsync/message/ipldbind/*.ipldsch; do
cp -v --remove-destination -f `readlink $f` $f
done
'';
2023-06-08 19:02:25 +00:00
passthru.updateScript' = writeScript "update-matrix-media-repo" ''
2023-05-09 16:42:05 +00:00
${../../scripts/update-git.sh} "https://github.com/ipfs/kubo" ipfs/kubo/source.json
if [ "$(git diff -- ipfs/kubo/source.json)" ]; then
SRC_PATH=$(nix-build -E '(import ./. {}).${pname}.src')
${../../scripts/add-go-module.sh} $SRC_PATH ipfs/kubo "storj.io/ipfs-go-ds-storj/plugin@latest"
fi
'';
2023-05-10 06:56:28 +00:00
passthru.repoVersion = "13"; # Also update kubo-migrator when changing the repo version
2023-05-09 16:42:05 +00:00
}