Files
nixpkgs/pkgs/by-name/ku/kubo-fs-repo-migrations/package.nix
Luflosi 5fcc08a907 kubo: 0.36.0 -> 0.37.0
https://github.com/ipfs/kubo/releases/tag/v0.37.0

Kubo v0.37.0 embeds the repository migration from repo version v16 to v17 and the kubo-fs-repo-migrations package will not reveive any more updates.
I'll keep the `kubo-fs-repo-migrations` and `kubo-migrator` packages around for now until a future version of Kubo no longer supports calling the external migration binaries.
Since the (newest) migrations are now built into Kubo, the NixOS module now needs to call `ipfs repo migrate --to=xx --allow-downgrade` instead of `fs-repo-migrations --to xx -y`.
The `--allow-downgrade` flag is only there for the unlikely situation that someone downgrades their local Kubo version with an overlay, separate channel input or similar means. It does however not work for rolling back the NixOS generation after a Kubo upgrade which increases the repo version (not all Kubo upgrades increase the repo version). This is because the Kubo version of the previous NixOS generation doesn't have the code for upgrading to or downgrading from the newer repo version.
Since we only have one version of Kubo in Nixpkgs at a time, migrations cannot be tested automatically. I manually verified that `ipfs repo migrate` uses binaries like `fs-repo-15-to-16` provided by the `kubo-fs-repo-migrations` packages for older migrations. I also tested that the migration from v16 to v17 works on my machine using the NixOS module.
2025-11-01 00:19:03 +01:00

266 lines
7.6 KiB
Nix

{
lib,
stdenv,
symlinkJoin,
buildGoModule,
fetchFromGitHub,
kubo-migrator-unwrapped,
writeShellApplication,
minRepoVersion ? 0, # The minimum supported Kubo repo version from which the migrations can start. Increasing this reduces the closure size
stubBrokenMigrations ? true, # This prevents the fs-repo-migrations program from downloading binaries off the internet without even checking any signatures
}:
let
mkMigration =
from: to: version: hash:
let
pname = "fs-repo-${toString from}-to-${toString to}";
src = fetchFromGitHub {
owner = "ipfs";
repo = "fs-repo-migrations";
rev = "${pname}/v${version}";
inherit hash;
sparseCheckout = [ pname ];
};
in
buildGoModule {
inherit pname version src;
sourceRoot = "${src.name}/${pname}";
vendorHash = null;
# Fix build on Go 1.17 and later: panic: qtls.ClientHelloInfo doesn't match
# See https://github.com/ipfs/fs-repo-migrations/pull/163
postPatch =
lib.optionalString
(lib.elem to [
11
12
])
''
substituteInPlace 'vendor/github.com/marten-seemann/qtls-go1-15/common.go' \
--replace-fail \
'"container/list"' \
'"container/list"
"context"' \
--replace-fail \
'config *Config' \
'config *Config
ctx context.Context'
'';
checkPhase = ''
runHook preCheck
${
if to <= 11 then
"" # Migrations fs-repo-10-to-11 and earlier require too much effort to test, making it not worth it
else if to == 12 then
''
cd migration
go test -mod=vendor
''
else if to <= 15 then
''
cd not-sharness
./test.sh
''
else
''
cd test-e2e
./test.sh
''
}
runHook postCheck
'';
# Check that it does not crash
doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
"$out/bin/${pname}" -help
runHook postInstallCheck
'';
meta = {
inherit (kubo-migrator-unwrapped.meta)
homepage
license
platforms
maintainers
;
mainProgram = pname;
description = "Migrate the filesystem repository of Kubo from repo version ${toString from} to ${toString to}";
broken =
to == 7 && stdenv.hostPlatform.isDarwin # fs-repo-6-to-7 is broken on macOS: gx/ipfs/QmSGRM5Udmy1jsFBr1Cawez7Lt7LZ3ZKA23GGVEsiEW6F3/eventfd/eventfd.go:27:32: undefined: syscall.SYS_EVENTFD2
|| (lib.elem to [
11 # fs-repo-10-to-11 fails (probably since Go 1.21) with: panic: qtls.ClientSessionState doesn't match
12 # fs-repo-11-to-12 fails (probably since Go 1.21) with: panic: qtls.ClientSessionState doesn't match
]);
};
};
stubBecauseDisabled =
from: to: release:
let
pname = "fs-repo-${toString from}-to-${toString to}";
in
writeShellApplication {
name = pname;
text = ''
echo 'The kubo-fs-repo-migrations package was not buit with support for ${pname}.'
echo 'To enable support, set the minRepoVersion argument of this package to a lower value.'
echo 'The purpose of this stub is to prevent the fs-repo-migrations program from downloading unsigned binaries from the internet.'
'';
};
stubBecauseBroken =
pname:
writeShellApplication {
name = pname;
text = ''
echo '${pname} is broken with the latest Go version.'
echo 'The purpose of this stub is to prevent the fs-repo-migrations program from downloading unsigned binaries from the internet.'
'';
};
releases = [
{
from = 0;
to = 1;
release = "1.0.1";
hash = "sha256-2mKtr6ZXZdOOY+9GNaC85HKjOMsfeM91oxVuxHIWDO4=";
}
{
from = 1;
to = 2;
release = "1.0.1";
hash = "sha256-6/BewNcZc/fIBa8G1luNO2wqTdeHi8vL7ojJDjBfWYI=";
}
{
from = 2;
to = 3;
release = "1.0.1";
hash = "sha256-kESX/R25nb7G/uggwa7GB7I2IrdgeKe0chRzjr70Kuw=";
}
{
from = 3;
to = 4;
release = "1.0.1";
hash = "sha256-Mv3/7eUS8j7ZzbNR52baekDcXPwcaNpUfqkt0eRpP20=";
}
{
from = 4;
to = 5;
release = "1.0.1";
hash = "sha256-aEqXFhZGOBU5ql2RRqzwD5IXGySVGroaHxjrkpIGAeU=";
}
{
from = 5;
to = 6;
release = "1.0.1";
hash = "sha256-EhMe/3gIl3VjSh6KzBPGH4s6B3AWRnbJ+eHSc8GOHMw=";
}
{
from = 6;
to = 7;
release = "1.0.1";
hash = "sha256-+5kIPQZckloPujLS0QQT+ojIIndfCQaH6grftZdYQ88=";
}
{
from = 7;
to = 8;
release = "1.0.1";
hash = "sha256-82oSU7qhldPVTdbbol3xSnl8Ko7NUPvGpAnmFxvAceQ=";
}
{
from = 8;
to = 9;
release = "1.0.1";
hash = "sha256-9knC2CfiTUNJRlrOLRpKy70Hl9p9DQf6rfXnU2a0fig=";
}
{
from = 9;
to = 10;
release = "1.0.1";
hash = "sha256-732k76Kijs5izu404ES/YSnYfC9V88d9Qq5oHv5Qon0=";
}
{
from = 10;
to = 11;
release = "1.0.1";
hash = "sha256-WieBZpD8dpFDif7QxTGjRoZtNBbkI3KU4w4av7b+d4Q=";
}
{
from = 11;
to = 12;
release = "1.0.2";
hash = "sha256-x/4ps705Hnf+/875/tn3AsEHgaHHCc+cGXymXpRt0xA=";
}
{
from = 12;
to = 13;
release = "1.0.0";
hash = "sha256-HjtZ2izoZ+0BrhzXG/QJHcnwsxi0oY4Q3CHjTi29W9o=";
}
{
from = 13;
to = 14;
release = "1.0.0";
hash = "sha256-zvNq+AFp7HDHHZCJOh9OW/lalk3bXOl1Pi+rvJtjuSA=";
}
{
from = 14;
to = 15;
release = "1.0.1";
hash = "sha256-u7PM6kFCQUn07NGpeRYpBDEwc2pP+r5mf44LZU4DV5Y=";
}
{
from = 15;
to = 16;
release = "1.0.1";
hash = "sha256-/TG5GNSyV8gsngRT/0jazkL2n2RzA9h1gCTLqGOrI0A=";
}
];
maxRepoVersion = builtins.length releases;
minRepoVersionValidated =
if minRepoVersion >= 0 then
minRepoVersion
else
throw "The minimum supported repo version is 0. Set `minRepoVersion` to a non-zero value.";
latestMigration = builtins.foldl' (x: y: if y.to == maxRepoVersion then y else x) {
release = throw "Could not get the latest Kubo migration";
} releases;
version = "${toString maxRepoVersion}.${latestMigration.release}";
mkMigrationOrStub =
x:
let
builder = if x.from >= minRepoVersionValidated then mkMigration else stubBecauseDisabled;
in
builder x.from x.to x.release x.hash;
migrations = map mkMigrationOrStub releases;
packageNotBroken = package: !package.meta.broken;
migrationsBrokenRemoved = builtins.filter packageNotBroken migrations;
migrationsBrokenStubbed = map (
x: if packageNotBroken x then x else (stubBecauseBroken x.pname)
) migrations;
in
symlinkJoin {
name = "kubo-fs-repo-migrations-${version}";
paths = if stubBrokenMigrations then migrationsBrokenStubbed else migrationsBrokenRemoved;
meta = (removeAttrs kubo-migrator-unwrapped.meta [ "mainProgram" ]) // {
description = "Several individual migrations for migrating the filesystem repository of Kubo one version at a time";
longDescription = ''
This package contains all the individual migrations in the bin directory.
This is used by fs-repo-migrations and could also be used by Kubo itself
when starting it like this: `ipfs daemon --migrate`
or when calling `ipfs repo migrate --to=16`.
'';
};
}