2024-09-24 15:40:56 +01:00
{
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 = " f s - r e p o - ${ toString from } - t o - ${ toString to } " ;
src = fetchFromGitHub {
owner = " i p f s " ;
repo = " f s - r e p o - m i g r a t i o n s " ;
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 \
' " c o n t a i n e r / l i s t " ' \
' " c o n t a i n e r / l i s t "
" c o n t e x t " ' \
- - 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
''
2024-09-24 16:26:34 +01:00
else if to <= 15 then
2024-09-24 15:40:56 +01:00
''
cd not-sharness
./test.sh
''
2024-09-24 16:26:34 +01:00
else
''
cd test-e2e
./test.sh
''
2024-09-24 15:40:56 +01:00
}
runHook postCheck
'' ;
# Check that it does not crash
doInstallCheck = true ;
installCheckPhase = ''
runHook preInstallCheck
" $ o u t / b i n / ${ pname } " - help
runHook postInstallCheck
'' ;
meta = {
inherit ( kubo-migrator-unwrapped . meta )
homepage
license
platforms
maintainers
;
mainProgram = pname ;
description = " M i g r a t e t h e f i l e s y s t e m r e p o s i t o r y o f K u b o f r o m r e p o v e r s i o n ${ toString from } t o ${ 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 = " f s - r e p o - ${ toString from } - t o - ${ 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 = " s h a 2 5 6 - 2 m K t r 6 Z X Z d O O Y + 9 G N a C 8 5 H K j O M s f e M 9 1 o x V u x H I W D O 4 = " ;
}
{
from = 1 ;
to = 2 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - 6 / B e w N c Z c / f I B a 8 G 1 l u N O 2 w q T d e H i 8 v L 7 o j J D j B f W Y I = " ;
}
{
from = 2 ;
to = 3 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - k E S X / R 2 5 n b 7 G / u g g w a 7 G B 7 I 2 I r d g e K e 0 c h R z j r 7 0 K u w = " ;
}
{
from = 3 ;
to = 4 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - M v 3 / 7 e U S 8 j 7 Z z b N R 5 2 b a e k D c X P w c a N p U f q k t 0 e R p P 2 0 = " ;
}
{
from = 4 ;
to = 5 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - a E q X F h Z G O B U 5 q l 2 R R q z w D 5 I X G y S V G r o a H x j r k p I G A e U = " ;
}
{
from = 5 ;
to = 6 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - E h M e / 3 g I l 3 V j S h 6 K z B P G H 4 s 6 B 3 A W R n b J + e H S c 8 G O H M w = " ;
}
{
from = 6 ;
to = 7 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - + 5 k I P Q Z c k l o P u j L S 0 Q Q T + o j I I n d f C Q a H 6 g r f t Z d Y Q 8 8 = " ;
}
{
from = 7 ;
to = 8 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - 8 2 o S U 7 q h l d P V T d b b o l 3 x S n l 8 K o 7 N U P v G p A n m F x v A c e Q = " ;
}
{
from = 8 ;
to = 9 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - 9 k n C 2 C f i T U N J R l r O L R p K y 7 0 H l 9 p 9 D Q f 6 r f X n U 2 a 0 f i g = " ;
}
{
from = 9 ;
to = 10 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - 7 3 2 k 7 6 K i j s 5 i z u 4 0 4 E S / Y S n Y f C 9 V 8 8 d 9 Q q 5 o H v 5 Q o n 0 = " ;
}
{
from = 10 ;
to = 11 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - W i e B Z p D 8 d p F D i f 7 Q x T G j R o Z t N B b k I 3 K U 4 w 4 a v 7 b + d 4 Q = " ;
}
{
from = 11 ;
to = 12 ;
release = " 1 . 0 . 2 " ;
hash = " s h a 2 5 6 - x / 4 p s 7 0 5 H n f + / 8 7 5 / t n 3 A s E H g a H H C c + c G X y m X p R t 0 x A = " ;
}
{
from = 12 ;
to = 13 ;
release = " 1 . 0 . 0 " ;
hash = " s h a 2 5 6 - H j t Z 2 i z o Z + 0 B r h z X G / Q J H c n w s x i 0 o Y 4 Q 3 C H j T i 2 9 W 9 o = " ;
}
{
from = 13 ;
to = 14 ;
release = " 1 . 0 . 0 " ;
hash = " s h a 2 5 6 - z v N q + A F p 7 H D H H Z C J O h 9 O W / l a l k 3 b X O l 1 P i + r v J t j u S A = " ;
}
{
from = 14 ;
to = 15 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - u 7 P M 6 k F C Q U n 0 7 N G p e R Y p B D E w c 2 p P + r 5 m f 4 4 L Z U 4 D V 5 Y = " ;
}
2024-09-24 16:26:34 +01:00
{
from = 15 ;
to = 16 ;
release = " 1 . 0 . 1 " ;
hash = " s h a 2 5 6 - / T G 5 G N S y V 8 g s n g R T / 0 j a z k L 2 n 2 R z A 9 h 1 g C T L q G O r I 0 A = " ;
}
2024-09-24 15:40:56 +01:00
] ;
maxRepoVersion = builtins . length releases ;
minRepoVersionValidated =
if minRepoVersion >= 0 then
minRepoVersion
else
throw " T h e m i n i m u m s u p p o r t e d r e p o v e r s i o n i s 0 . S e t ` m i n R e p o V e r s i o n ` t o a n o n - z e r o v a l u e . " ;
latestMigration = builtins . foldl' ( x : y : if y . to == maxRepoVersion then y else x ) {
release = throw " C o u l d n o t g e t t h e l a t e s t K u b o m i g r a t i o n " ;
} 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 = builtins . map mkMigrationOrStub releases ;
packageNotBroken = package : ! package . meta . broken ;
migrationsBrokenRemoved = builtins . filter packageNotBroken migrations ;
migrationsBrokenStubbed = builtins . map (
x : if packageNotBroken x then x else ( stubBecauseBroken x . pname )
) migrations ;
in
symlinkJoin {
name = " k u b o - f s - r e p o - m i g r a t i o n s - ${ version } " ;
paths = if stubBrokenMigrations then migrationsBrokenStubbed else migrationsBrokenRemoved ;
meta = ( builtins . removeAttrs kubo-migrator-unwrapped . meta [ " m a i n P r o g r a m " ] ) // {
description = " S e v e r a l i n d i v i d u a l m i g r a t i o n s f o r m i g r a t i n g t h e f i l e s y s t e m r e p o s i t o r y o f K u b o o n e v e r s i o n a t a t i m e " ;
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
'' ;
} ;
}