This repository has been archived on 2024-10-13. You can view files and clone it, but cannot push or open issues or pull requests.
nix-packages/ipfs/kubo/default.nix
2023-08-22 13:10:40 +01:00

77 lines
2.7 KiB
Nix

{
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
cd $out
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"
'';
outputs = ["out" "systemd_unit" "systemd_unit_hardened"];
buildPhase = ''
make build
'';
installPhase = ''
GOBIN=$out/bin make install
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"
'';
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
'';
passthru.updateScript' = writeScript "update-matrix-media-repo" ''
${../../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
'';
passthru.repoVersion = "13"; # Also update kubo-migrator when changing the repo version
}