start	end	text
800	1420	All right.
1420	3180	Let's get started here.
4160	6000	Welcome, everybody.
6000	7500	I'm Sean Gilligan.
7500	11340	My talk is Cypherpunk Java with Nix.
12380	17360	Welcome to Nix Vegas 2025, the first Nix Vegas.
19640	21980	My name is Sean Gilligan.
21980	27840	You can find me on GitHub as msgilligan and my email is here, too.
28340	32920	Feel free to reach out if you have any questions or comments.
33180	38340	I will make this kind of interactive, so if you have a question, just let me know.
43300	46600	So I'm going to talk a little bit about Cypherpunk principles.
46600	48640	I think I'll be preaching to the choir.
48880	52620	The disclaimer is I don't consider myself a Cypherpunk yet.
52620	56140	I'm more of an aspiring Cypherpunk, but I'm trying.
56900	68200	I'm going to talk a little bit about how I got to Nix and how it's kind of becoming more of a Cypherpunk has led me to Nix.
69120	85560	I know that a lot of people in the Nix community and also in the Bitcoin community that I deal with a lot tend to be pretty hostile to Java, so I'm going to talk about what has Java done for us lately, and the answer is a lot.
86520	102520	I'm going to talk about the some of the projects that I'm working on that I'm hoping that are both responsible for my transformation and that I'm hoping to to kind of deliver on these Cypherpunk principles.
103500	106640	The first, there are two related projects.
106640	115960	The first one is a cryptography library for elliptic curve cryptography with the wonderful name secp256k1jdk.
117120	124120	There's also a library called BitcoinJ that I'm the junior co-maintainer of.
124460	138300	And then I'm going to talk about how Nix solved some of the problems we're having in developing these libraries, and then I'm going to present an example that uses Nix derivations to do some builds.
144910	151770	So how many people are familiar with Eric Hughes and the Cypherpunks manifesto?
152430	157590	Okay, it's a famous document from 1993.
157590	160990	It has the famous phrase, Cypherpunks write code.
161130	165910	We publish our code so that our fellow Cypherpunks may practice and play with it.
165910	169750	Our code is free for all to use worldwide.
170070	171670	I wonder what he would think of Nix.
171670	173090	I think he would like it.
173090	175690	He's still around, I haven't asked him.
175710	177300	I keep pushing the wrong button.
179010	181410	What are Cypherpunk values?
181410	182570	Privacy.
183050	188610	They want to make privacy tools available and they want them to come from a trusted source.
188610	190990	That's where Nix comes in.
191690	200100	People want to have autonomy over their software and hardware and there's not much more autonomous than a Nix config.
202280	209800	I left out the quote where he talks about software that you can play with.
209800	211380	Did I edit that down?
214380	215500	No, no.
215620	218320	Cypherpunks may practice and play with it.
218380	221640	That is also a very Nix-like principle.
223220	231380	I really loved the art and the whole concept of the great tree that they were using with Nix Vegas.
231380	241960	So I wore my existing Yggdrasil t-shirt and now I have a new one that I got from the conference.
241960	243400	It makes me really happy.
243560	255040	One of the cool things about Nix, as most of you know, is it has one of the largest, the largest library of open source software of all the package managers.
255220	261300	And that's what they were calling, first time I've heard it was in reading about this conference, the great tree.
263810	274610	Another excerpt from the Cypherpunk manifesto that's near and dear to my heart is where he talks about we need anonymous systems with electronic money.
277850	280770	So I'm a Unix person at heart.
280770	288910	I did my undergrad at UC Berkeley and UC Santa Cruz and Unix and C are kind of in my DNA.
288910	293970	But I also became a Macintosh developer in the early days of Macintosh.
294090	300390	And it was really hard for me to not have Unix underneath this beautiful GUI that they had.
300390	313570	And now, of course, I'm on Mac OS X and I use Mac OS X and I use Nix because it runs on both Mac and Darwin.
313570	318490	So all my demos are going to be on Darwin and Linux.
318810	326770	I actually played with Darwin when it was an open source operating system that you could install before Apple backed away from that.
328430	337590	So when I started working on Bitcoin J, the lead developer, Andreas Schilbach, had made some decisions that really frustrated me.
337590	343630	The first of which was there were no binaries allowed in the repository.
344150	349250	And for those of you that are Java developers, I don't I think there's at least one or two here.
349250	354710	You may be familiar with like the Gradle wrapper, which is a binary used to bootstrap your build.
354710	356970	Not allowed in Bitcoin J.
357910	374470	The second thing is that he insisted that everything be able to build according to Debian free software guidelines, which meant using this ancient version of Gradle known as FrankenGradle that's included with Debian.
374470	381010	It's actually a build of Gradle 4.4 when the latest version is Gradle 9.
381610	387250	The reason is that Gradle now needs Kotlin, and Kotlin is really hard to bootstrap.
387410	389510	And Gradle is really hard to bootstrap.
389510	396310	So they stick with this ancient version and they patch it to make it work with the newer JDKs.
398210	401350	Now, of course, Nix is going to solve this, right?
401690	416810	But so these are some of the things that led me more to the Cypherpunk world, working with Andreas, contributing to Bitcoin J, and dealing with some of these issues around Java that aren't very friendly to
420030	422030	the free software world.
424230	427930	All right, I'm going to take a little detour and talk about modern Java.
429170	433650	A lot's changed between 2014 and now.
434610	441690	As of Friday, Java 25 went to release candidate.
442410	450930	For the last 10 years or so, they've been doing a new release every six months, and they've really done a nice job.
450930	468710	I'm not a fan of Oracle, the corporation, but I will say that they've kept their good engineers, they've given them a lot of autonomy to do the right thing, and they've really cleaned up a lot of long-standing issues with Java.
468710	470750	Things that I thought I'd never see fixed.
472110	482470	They put out a new long-term support release every two years, Java 25 will be the long-term support release.
482470	484160	It's coming out in September.
484590	487370	It's not numbered by year.
487430	492730	There will be a 26 in early 26, and a 27 in September 26.
493710	499250	There's an algebraic formula where you subtract and multiply by two.
503430	507470	I'm just going to run through all the features that have been added in the last 10 years.
507470	511790	I'm showing which version of Java is listed.
512850	521150	I'm showing the LTS version that added that feature, not when it was previewed or when it was first released in a general availability.
521210	530770	So with 8, we got lambdas, streams, default methods and interface, optional type, which is like a promise.
531870	539810	It's also for the functional programmers, it's actually a monad.
540550	548390	New time API, 11 added modules, a new HTTP API, reactive streams.
548470	550850	You can use VAR if you want to.
550850	555370	A REPL and Shebang execution are now supported.
556070	565490	JLink lets you build a custom JRE just for your project, and it's used nicely in mixed packages these days.
566770	572230	They added switch expressions, which are a lot like the match expression in Rust.
572470	575750	They also have pattern matching that works with them.
576370	585630	Records are immutable objects without a lot of the verbosity of Java beans, and immutability and verbosity of Java beans forever banished.
586270	593090	Sealed classes allow you to do things like Rust enums, if you're a Rust developer.
593990	598850	They created a packaging tool, which can be used to bundle a JDK.
599170	602230	You have multiline text blocks.
602370	607090	Hex format is like a little thing, but damn it, why did it take them so long to add that?
607970	617430	Virtual threads is like go routines, pattern matching in switch, snippets in your code, sequence collections.
617430	619370	Panama is a really important thing.
619370	621830	It's known as the foreign function and memory API.
621830	624690	It became final in Java 22.
624690	636450	It's a new way of calling native code from your Java, and I'm going to talk about that, because my demo uses it very effectively, I think.
636470	642730	It went final in Java 22, and it's becoming long-term available in 25.
643970	651730	The nice thing is you don't have to... if anybody's used JNI, you know that it's very painful, it's tedious, and it's error-prone.
651830	659210	The Panama API, which I won't have time to get into, really makes it a lot simpler and a lot nicer.
659210	676270	And it also works pretty well with Nix when you bring in a dynamic library as a Nix dependency, you can link to it and use it directly versus the older JNI way, you typically bundle things inside of a jar.
677550	684550	They also finally simplified Hello World with something called implicit classes and instance main methods.
685930	688310	They've added structured concurrency.
688310	697460	There's a vector API that's early access, and Valhalla adds value types where you're able to not create things on the heap.
698340	704760	And then GraalVM is the native compilation tool.
704760	711640	It includes a native compilation tool, it also has polyglot language support, and a Java VM actually written in Java.
711640	719600	It's a pretty advanced piece of compiler technology, and I can't say that I really understand it, but I do really like the native image.
719600	734780	And so the example that I'm going to give is something compiled with GraalVM to generate a native image, and then it's using a native C library that's linked with the Panama FFM API.
735620	738320	They've also removed a lot of stuff.
738320	739820	Applets are gone.
739820	746200	They removed the security manager because it wasn't... well, they removed the security manager.
746200	761860	They also removed the secp256k1 elliptic cryptography, elliptic curve cryptography curve, but I have added it back using a library from Bitcoin called blipsec256k1.
763160	785280	Okay, so I'm going to go through this fairly quickly, but the example that I'm using and a project I've been working on is to create a new reference implementation of the secp256k1 curve for the JDK and JVM languages.
786800	792160	It's based on this C API, which is wrapped with the foreign function manager.
792840	799360	It uses the standards for efficient cryptography group secp256k1 curve.
799560	808580	The Java library is modeled after the C library because they did a really nice job of making it hard to shoot yourself in the foot.
808620	814680	And so with Java, we're just able to simplify it and make it a little less verbose.
814680	817000	We're using functional return types.
817000	817520	We're using...
817520	824320	you know, we've got garbage collection, so you don't have to worry about pointers and things like that.
825240	831100	The interesting thing that we've done with secp256k1 is we have two implementations.
831100	840200	One that uses this best-of-breed C library, and another that uses a library known as bouncycastle.
841080	851660	Not going to demo the bouncycastle today because I'm really focused on the native thing because that's kind of... it's been my main focus and it's most interesting from a Nix perspective.
853380	862380	So the libsecp library was created by the Bitcoin core group after they moved away from OpenSSL.
864060	868220	I'm going to go through this pretty quickly because I think we're limited on time.
877600	880540	So these are the library jars.
880540	883300	You can see they're pretty... they're probably a little bit bigger now.
884160	895770	But there's an API jar that you use, and then there's the foreign function, the FFM implementation, and there's a bouncycastle implementation.
896780	904710	When you compile against it, you just compile against the API jar, and then at runtime you can deploy it either way.
909710	921910	The native one, of course, requires 22 or later, and with 25 being the LTS, we're actually going to just set the requirement to be 25.
922050	925950	This is the example program that I'm going to show.
925950	930610	It basically generates a key.
930610	934810	It's based on the C example from the C library.
934810	940810	It basically generates a secret key, generates a public key, signs and verifies.
945490	950970	This is the signing code.
953440	955480	This is the verification.
955480	960380	This is not using the simplified hello world yet.
962140	968580	Because one of the things is that JDK 25 is not available in Nix yet.
968580	976820	I actually created a fork and put in the GraalVM 25 early access, and I'm using that for this demo.
976820	992360	But one of the things I'm hoping to personally contribute to the Nix ecosystem is to help get new releases of Java supported faster so that packages can migrate so that we can start debugging them earlier.
996400	1008020	BitcoinJ is a library that is about 15 years old, and when I started working on it, I realized that it really needed some major updates.
1008020	1024120	So we've been kind of modernizing it along the principles of modern functional style Java, while maintaining a lot of backward compatibility, because one of the major use cases has been Android wallets.
1024120	1043220	Andreas really feels that it should support a wide variety of inexpensive Android phones, and he holds us back so that it can be used all over the world from people that maybe can't afford newer phones.
1043980	1048120	And it's available in the...
1049520	1053100	I'm drawing a blank on the name of the app store, the Android app store.
1054500	1056140	No, not the Play Store.
1056400	1057420	It's F-Droid.
1057420	1058900	It's available in F-Droid.
1062740	1065600	There's a few apps powered in it.
1065600	1070200	The Bitcoin Wallet by Andreas Schilbach is one of the major drivers.
1070200	1072960	There's a Bisk peer-to-peer networking app.
1074740	1077540	There's also... this is the history of the project.
1077540	1079360	I'm going to skip over that.
1080440	1085800	Release 18 is going to have the new SecP library.
1086980	1089500	All right, so how does Nix help?
1092140	1100200	How many people here are familiar with the way Maven repositories and Java packaging is done?
1100480	1102360	Two, okay.
1102400	1103200	It's...
1103200	1106460	No, actually not.
1106460	1124540	I actually think that Maven and Gradle may have their problems, but having pre-built binaries that you can pull based on a coordinate of group, artifact, and version works pretty well.
1124540	1132460	And it's actually very similar to Nix, with one major thing that's missing, being able to rebuild it from source.
1133500	1138580	But, you know, a lot of times you get into these dependency hell situations with...
1139860	1143200	we try to get everything onto the same dependency.
1143720	1145100	Gradle... I mean, not Gradle.
1145100	1158140	The Maven repository system, like Nix, allows each app to declare its dependencies and have its own tool chain that can essentially be version locked.
1159760	1171260	So when you bring that into Maven, you get some mismatch issues because they work differently, and there's some hacks to resolve that.
1171260	1173520	And I'll show that briefly.
1175160	1179640	As just before I do the demo.
1179760	1188280	One of the other things that's interesting to me about Nix is that source is the metadata called source provenance.
1188280	1190460	Is everybody familiar with that?
1192500	1193440	Yeah?
1193440	1194160	Yeah?
1194160	1196700	So in the package... I'll go over it briefly.
1196700	1206320	In the package metadata, there's a metadata field called source provenance, and there's a handful of values that you can use for it.
1206360	1208900	So you can say it's source code.
1208900	1210180	It's built from the source.
1210180	1213860	You can say that it's a precompiled binary.
1213860	1220820	There's also a category called bytecode, which is what you'll use if you pull in a precompiled Java jar library.
1221940	1231780	One of the reasons I think for Nix's success is that it does allow you to bring in these things that were built as binaries.
1231780	1235620	That's why the package repository is so large.
1235620	1247700	But if you really want bootstrapability, which for me is the holy grail and something that I'm pursuing, then you want to see more things having source provenance.
1247700	1255600	So for example, for this demo, I'm using a GraalVM build that's not built from source.
1256260	1259660	OpenJDK is built from source.
1259660	1266920	There's also Zulu and Temarin, which are other builds of the JDK that are brought in as binaries.
1269040	1279000	So one of my long-term goals is to see more bootstrapability in the components that I'm working on.
1283690	1286250	All right.
1291090	1297890	So I originally got this working with a bit of a hack.
1297890	1314690	If you don't want to do a full Nix package, you can use a dev shell and just say... and just call... and just run the dev shell to do your build.
1314690	1319270	I do that in GitHub actions, for example.
1319490	1323830	But seeing Fareed's demo yesterday, I said... God damn it.
1323930	1324930	I'm gonna stay.
1324930	1333590	I'm gonna convert this to actually being a full Nix package, which I basically did with a few caveats.
1333590	1335010	This thing keeps rotating.
1341130	1342790	Was there a clamp?
1343050	1343790	Yeah.
1354510	1355910	Thank you.
1358110	1360830	Can everybody see this?
1361990	1362810	All right.
1362810	1369230	So this is a little bit of a hack , because this is my first time doing this, actually, for real.
1369230	1374050	But I have two packages of the same utility.
1374050	1378010	Again, it's that Schnorr signature example.
1378010	1379690	I have one build that uses...
1380990	1384650	that generates the Java bytecode and runs it with the JIT.
1384650	1388570	And I have another that compiles it completely native to C.
1389370	1395190	I didn't use Flake Utils, so right now it only works on R64 Darwin.
1395190	1400750	But I have tested some of this on Linux and on x86.
1404310	1418970	So because the build is done with Gradle, I mentioned there's this thing called the... there's this extra step called fetch steps that pulls the jars down and basically version locks them.
1418970	1423430	I think it's called a fixed output derivation, I believe.
1423910	1424970	Yeah.
1426750	1434130	So you have to run like a pre-step to build this deps.json file.
1436310	1441110	And then it runs the Gradle task to do the build.
1442070	1448390	And then in the install phase, it just copies the jars and then it makes a wrapper.
1448430	1458430	Note that this is using the Java module system, which is the newer way of deploying... of running Java.
1458430	1468730	It provides more tightly, you know, tighter boundaries and access control between modules, which I think is quite good for security.
1468730	1482090	For example, you can see in here that it specifically enables which modules are allowed to call native code.
1482270	1492910	One of the things that's been added to Java recently is this whole initiative around secure by default or integrity by default.
1492990	1500230	So you now have to, if anything's going to access native code, you have to explicitly permit it when you compile your app.
1500230	1509370	So in theory, this could provide some protection against a supply chain attack where you bring in another module that tries to do something fishy.
1509370	1514290	If it's not enabled to talk to your native libraries, it won't be able to.
1524530	1535730	This one here is the build of the native package, which also uses Gradle, but it uses a different Gradle task, which does the native compile.
1536110	1541330	And then in the install phase, I learned a few things about this.
1542270	1549710	It actually creates a, it actually uses wrap program to create a link to the library.
1549710	1563710	You can use patch elf or there's something on the Mac, I forget what it's called, an equivalent thing on the Mac, but you can't use that with the GraalVM code that calls a native image because it uses DLOpen.
1563710	1567650	So the actual library name isn't there in the executable.
1567650	1571190	So you have to use this technique of, oh, here it is.
1571190	1573170	You can see I haven't commented out.
1573310	1575210	Install name tool won't work.
1575210	1577730	You have to use a wrap program.
1577950	1588150	There are ways of telling native image to build a more static executable, and I'm going to look into that in the future.
1588210	1594630	But for this current build, at least, this wrap program was the way to go.
1619610	1620410	Okay.
1622550	1628610	So I thought I'd run, I showed that these examples actually run.
1628970	1632170	First we will run, can everybody see this or should I make it bigger?
1632970	1634070	A little bigger?
1644490	1655910	So you can see when I run the Schnorr example, which is the one that actually uses the JVM, it runs in about 186 milliseconds.
1659870	1667670	And the output's the same, but if I run it, if I run the native version, we're down to 35 milliseconds.
1669310	1676930	And then the other thing I was going to show is the, is what the wrappers look like.
1676930	1682010	So this is the wrapper for the JVM version.
1682010	1693950	You can see that on the Mac, OpenJDK actually maps to Zulan, and you can see that it's directly pulling it from the Nix store.
1693970	1699170	You can see the enable native access for just the FFM module that I mentioned.
1699170	1703310	And you can see the library, you can see the library paths.
1705050	1708630	And that's how, that's how the native version is run.
1710130	1715390	For, for the, I'm sorry, that's how the JIT version is run.
1715390	1729870	For the native version, you can see that it's setting up this dynamic load library path to the native C library in, in the Nix store, and then running based upon that.
1730610	1739490	So, so what you're seeing when, when, when this runs is you're seeing natively compiled Java calling the Panama FFM
1742790	1747610	capability , which then calls a natively compiled library.
1748890	1754930	And built with all the native stuff being pulled in via Nix, which is really nice.
1755650	1760930	So this is maybe the future of Cypherpunk Java.
1761990	1763810	Any questions?
1775070	1776210	All right.
1777230	1778890	Oh,
1790730	1793290	that's a really good question.
1793290	1794570	Let me restate the question.
1794570	1804710	The question is, if some organization took this on, would there be a way to replace the public Maven repository with the Nix cache?
1809430	1811210	Or your local Maven?
1811430	1815450	That, that's a, that's a great question, and I think about that a lot.
1816390	1822930	I, I, you can, you can do it yourself for a small project using Nix.
1822970	1824870	I've, I've played around with that.
1824870	1826850	I think Fareed has done that.
1829950	1834650	But to, to try to move the entire ecosystem would be really difficult.
1838090	1855590	But maybe some, maybe some subset, you know, I'm wondering if, you know, if there could be some, you know, more, like, like, for example, one of the things I've done with the Secp JDK library is I've, and BitcoinJ, both of them, I've really worked hard to minimize dependencies.
1855830	1870510	So Secp, you know, has the dependency on the C library, and it has only one other dependency, which is something called jspecify, which actually gives you really good null annotations, almost as good as Kotlin.
1870510	1872670	And it's interoperable with Kotlin.
1872670	1874630	So it's, it's, it's really nice.
1874630	1881550	But with only those two dependencies, I do have the option of just pulling them in directly from Nix.
1881550	1889550	The thing is, you also, if, if you publish a Java library, you also want to support the non-Nix Java community.
1889550	1897030	So, you know, one of my goals with the Secp library is to do, is to use Nix for the reference build.
1897090	1906230	BitcoinJ, because I'm the junior maintainer, I, I, I defer to Andreas, who likes to do that using Debian and Podman.
1906270	1912030	But, but I would like to be able to do a reference build of the Secp library using Nix.
1912030	1917830	It should be, you know, it should be reproducible with other build tools, if you set all your options right.
1918330	1932070	But, but, you know, would it be possible to create something that, that sort of looks like a Maven repository, more, sort of more dynamically, and not use this man-in-the-middle deps.json technique?
1932630	1935430	That's something I'd, I'd like to, to learn more about.
1935430	1940470	And, and, you know, once I, you know, maybe in a year or so, it's something I might look at a little.
1940470	1945250	And if anybody has any ideas about that, please, please, you know, I'd love to chat.
1947770	1949230	Any other questions?
1951610	1952170	Okay.
1952170	1952450	Thank you.
1952450	1953490	Thank you, everybody.
