start	end	text
750	1440	All right.
1440	3420	Hello, Nix Vegas.
5500	6300	All right.
6300	7740	So, my name is Wes Payne.
7740	10440	Thank you for hanging out, learning more about Nix.
10440	15500	And this talk is Mesh Network Sidecars for NixOS Services.
16580	17320	All right.
17320	20420	So, first up, just a little bit about me.
21180	31640	I'm a Seattle-based software engineer interested in functional programming and distributed systems, specifically Clojure, and more recently, definitely Nix.
31920	49620	And then you can also find me rambling about Linux, about open source, about the lovely communities that build and shape open source, and nerdy kernel details like IOUring, eBPF, and, of course, my favorite, KExec, just about every week on the Linux Unplugged podcast,
49620	51960	we like to say the largest Linux podcast.
52520	55820	I'm a co-host there on the Jupyter Broadcasting Network.
56180	61060	And then, perhaps most importantly, pictured to the right here is my dog, Charlie, little old lady.
61060	68820	She's 12 years old and still keeps me busy when I'm not hacking, going on hikes in the Cascade Mountains.
69700	72340	But we're here for Nix.
72340	72700	Okay.
72700	75420	So, Mesh Networks, Sidecars, NixOS.
75420	77060	Let's define some terms.
77140	80300	So, first up is Mesh Network.
80300	88780	These go by many names, and the exact concept is not particularly important in terms of, you know, bike-shedding about the exact definition.
88780	92640	But they're called Overlay Networks, they're called Peer-to-Peer VPNs.
92640	98300	The basic idea is one flat network for all your devices and services.
98300	105200	And in particular, it's probably good to contrast this with more hub-and-spoke style traditional VPNs.
105200	106660	I'm sure many of us are familiar, right?
106660	119680	You open up OpenVPN on your laptop, and it connects to some endpoint that corporate IT set up, and you go through a VPN concentrator and a router, and then you can access all the internal services on some corporate LAN.
120160	124740	Well, with a Mesh Network or an Overlay Network, the idea is everything lives on the Mesh.
124740	136260	So, each one of your servers, maybe your laptop, maybe your mobile device, they all have first-class entries on your Mesh Network, and they can all talk to each other without having to route anywhere else.
136320	138660	Or at least that's obscured and handled below the scene.
138660	150740	So, instead of, like, me trying to talk from my laptop to another laptop that all has to go route through some central server, they just set up, they do NAT busting, it's all very clever, so they can get actual Peer-to-Peer connections to each other.
151600	156180	I've been interested in this stuff for a while, and it's actually been around longer than you might think.
156280	159760	In particular, Tink came out in 1998.
160160	164600	It kind of has that classic, old, first-era internet vibe to it.
164600	169560	It also feels very much like a traditional Unix daemon, so it's a little bit fun to work with.
169700	174640	I saw a great talk at Linux Fest Northwest, where people had set up basically their own private LAN.
174640	177740	This was probably 10 years ago, I don't know, 2015 or so.
177800	184980	But they'd gone so far as to, like, set up a proper domain, they had roaming user profiles, they had printers shared all between their houses.
185320	186960	So, I got interested.
186960	193260	I did basic stuff, like setting up backups from my house to my folks' place and vice versa.
194380	200040	But these days, by modern standards, Tink just... I mean, it doesn't have great performance.
200120	205360	But then also, it just was never really built with modern security principles in mind.
205400	213840	But thankfully, we don't have to stop at Tink, because I think we're in a bit of a mesh network renaissance, especially starting in 2019.
213880	220560	That saw Slack Open Source Nebula, which was a mesh overlay network they developed in-house.
220560	229400	In particular, they were doing stuff where they wanted to have multiple clouds, they had multiple VPCs, they tried to tie this together, and they added ACLs.
229400	232320	I mean, it's a cloud permissions first world.
232320	238400	And so, you do things like, oh, well, only users in these groups can talk to the database group and vice versa.
238400	246560	So, suddenly, it becomes easy to connect CI to the right staging places to do tests, as well as connect developers to the resources that they might need.
246900	250140	And then, of course, Tailscale also came out in 2019.
250300	251840	Netbird is another competitor.
251840	253320	There's, like, a whole bunch more now.
253320	254840	So, we're spoiled for choice.
254840	256480	Tailscale is probably the most popular.
258120	258900	There we go.
258900	259160	Yes.
259160	263560	And a great reminder, this talk is being streamed over Nebula right now.
264060	267380	So, it's increasingly popular across all kinds of different scales.
267380	272980	Simplifying Homelabs is something we see a lot, but also flattening, annoying multi-cloud and VPC networks.
274200	274580	Okay.
274580	277660	So, next up, then, for terms is Sidecar.
277660	279600	And here, I thought we'd start with an example.
279700	281240	I know this is the next talk, so I'm sorry.
281240	282260	There is some YAML.
282260	285540	I promise it's the only YAML sample that we'll see in this talk today.
285820	292780	So, this is just an example I stole from Tailscale Docs, where we're running a VaultWarden server, which is an open source BitWarden password manager.
292780	294760	That part's not too important.
295300	300040	Normal Docker Compose file, except we've got network mode.
300040	303680	And that's set to service Tailscale Sidecar.
303680	307020	And then we have a second container to find, and that's Tailscale Sidecar.
307020	308800	And we're running Tailscale.
308820	311540	In particular, here, we can customize the host name.
311540	313920	We feed it some environment variables to configure it.
314080	315740	And we poke some holes.
315740	319840	We give it some permanent state here with volumes that it can store anything it needs to.
319840	329520	And we give it additional capabilities, like NetAdmin, because it needs to go tell the kernel and do some other networking-related things that could have security compromises.
329520	333640	You don't want to give this to everything, but to be an effective VPN, it needs them.
334680	337720	So, this pattern got used a lot .
337800	339180	It's used in the cloud.
339180	340540	It's used in Kubernetes.
340540	344800	And it's used a ton in the home lab, just with Docker Compose like that.
345220	347020	And there are some reasons for this.
347020	350860	So, right out of the gate, Docker, of course, gives you network isolation.
351280	357620	You have to go the other way and go poke holes if you want to have host-mode networking or you want to share some ports or forward things.
358600	363000	And that means anything you run in this style is only exposed to the host if you want.
363140	366900	It also gives you application-level networking.
366900	378600	So, instead of having to think, like, oh, right, this service runs on host A, I have to kind of multiplex myself through that host to go get to maybe the 10 other services running on that particular box.
378600	385900	Now I can just sort of pick up this Docker Compose file, move it to another server, and nothing else on the mesh network has to care.
385900	392200	Because if they all use internal mesh addresses or names, from their perspective, nothing changed.
392200	401280	So, you essentially decouple the services you're running from the host infrastructure that it's on, but in, you know, a very home lab-friendly way.
403020	411560	It also is really enabled, I think, because we have this confluence of modern mesh networks that are super-configurable, made to run kind of wherever they can.
411560	415480	Many of them have both kernel and user-space implementations for their networking.
416140	418220	And we have containers.
418680	422880	But this is Nix, and I want to stop talking about containers, right?
422880	425260	So, let's talk about NixOS.
425260	426540	This is NixVegas.
426540	441400	Probably many of you, I hope, are familiar with Nix and NixOS, but if not, NixOS is a declarative operating system Linux distribution built on top of Nix, the glorious functional programming language and amazing software build tool.
441760	452860	And, I mean, it does a lot of things very well, but one of those in particular is it solves a lot of the sort of conflicting dependency problems that we're all too familiar with in traditional Linux distributions.
452900	456400	And this is also kind of what, you know, containers let us do in many cases.
456600	464000	I don't have to care what kind of language or tool chain or runtime VaultWarden runs, you know, or Redis runs.
464000	467960	They can run right together, even if one's based on Debian and another one's based on Alpine.
469160	483660	So, Nix can do this, but without having to stuff each of your apps into a container that might also contain, like, a whole half a dozen other OS or Python libraries or a bunch of tools that you don't actually need.
483820	488540	You know, we kind of create these containers and then end up having to run tools to scan them and slim them down.
488540	491360	And maybe we could just... we could just not.
491880	501780	It's also made very easy and just a lot of fun because it's powered by Nix packages, which is a giant cookbook of 120,000 plus different packages.
501780	505720	So, it pretty much has all the software you might need to run, and it's pretty easy to add your own.
505840	510780	And then you also get NixOS modules, which set up and run services for you.
510780	512060	So, it's not just a package.
512060	514500	It's also all of the configuration on your host.
514500	515920	It might poke holes in the firewall.
515920	517340	It's going to set up storage locations.
517340	519500	It's going to run systemd services for you.
519540	521600	And that's pre-configured, ready to go.
521620	525900	So, the one that really clicked for me the first time around, I mean, the Nginx module, great.
525940	527260	Postgres, super easy.
527320	528280	But Nix Cloud.
528500	538480	For the podcast, we run a Nix Cloud, and it's kind of how we exchange stuff between editors and the hosts, where we keep a lot of the assets we use for our soundboard and live streams.
538480	542820	So, we wanted to run it, and I was quite familiar with running it in a Docker style.
542820	544920	But sometimes you need to mess with stuff, right?
544920	548920	So, in the example on the right, we have max upload size.
549200	554180	We've also got some things in there where we're setting PHP options around the opcache.
555060	568660	And if you've ever done this with like a regular sort of Docker compose setup, oftentimes what ends up happening, because it's all just adding and appending layers, if you want to go modify something in an earlier layer, I mean, you can do it, but it's on you not to break anything.
568660	569800	There's no easy way to do it.
569800	571020	It's not declarative.
571380	578940	Versus here, I can just say, change the max upload size, and it doesn't matter if that needs to set like both a PHP option and an Nginx conf.
578940	581320	Like, all of that will just get updated for me.
582360	590260	And last but not least, Nix and NixOS have great support for Nebula, Tailscale, Netbird, like pretty much all these modern VPNs.
590260	592860	So, we're in good territory already.
595100	605540	But, as great as NixOS is for running Homelab services, running your desktop, your laptop, running servers, there is no native sidecar-like option.
605540	613060	With Docker, you can kind of copy and paste, make one little tweak to your network mode like we saw at the beginning, and you can do this sidecar style.
613420	616120	Unfortunately, with NixOS, it's not quite that easy.
616120	618160	And you may ask, you know, there's other ways to do it.
618160	622760	You can't just run regular old Tailscale on your host and get by with that.
622760	636420	But I find, especially once we started talking more about Nix in the show, that, you know, you can debate when you learn a new paradigm how much of your old workflow you should bring over versus how much you should embrace the new world.
636420	644980	But regardless, if you can bring over, like if you don't have to change your entire network architecture as you change, like your OS and build tooling, that's a little bit easier.
644980	659460	So, the solution we're seeing today, this mesh sidecar module, is kind of my attempt at providing a similar experience and a soft landing for folks who might be considering NixOS but are already very used to doing things in a containerized or Docker-first workflow.
659940	664040	And also, various people just were sort of on the internet asserting that you couldn't do this.
664040	666340	So, it's a bit of spike-driven development as well.
668060	668560	Okay.
668560	670920	So, part one, enter systemd.
670920	673740	We're all systemd fans here, right?
673800	674520	Right?
674860	678980	In any case, NixOS, I think, loves systemd.
678980	680760	I mean, you can use other things.
680760	681900	NixOS is very flexible.
681900	687240	But with Nix, you have this very powerful declarative build tool.
687300	690660	But that really only exists at build time.
690660	694740	And if you're running the system, runtime kind of matters.
695360	700040	And systemd has grown to be a very flexible tool that can do... I mean, it can manage mount points.
700040	701420	It can handle DNS queries.
701420	702480	It can do networking.
702480	706940	And, you know, you can configure just about everything on a modern Linux distribution with systemd.
707000	719020	And if you can then do complicated, sophisticated, arbitrary build time algorithms to determine what those systemd services should look like, you have a lot of availability to customize your system.
719720	725300	Also, as systemd has advanced, it's gotten a lot of new security and confinement options.
725300	726780	I mean, these days, it's not even that new.
726780	730620	But if you don't go spelunking in the docs, you might not know how many options exist.
730620	732760	Like, you can have private devices.
732760	734540	You can protect the home dir files.
734540	736160	You can protect system files.
736160	740540	You can make sure that no, you know, certain types of address families are allowed for connections or not.
740540	744740	And all of that's just in the regular old ini file for configuring systemd.
745600	755140	And in particular for today, it also now exposes many of the same cgroup and namespace controls as your favorite container runtimes.
757250	757890	Okay.
757890	767970	So, to make this a little more practical and not just a lecture on container runtimes, if you have a home lab, one thing you might want to start doing is monitoring your home lab.
767970	772170	I started my career off working in a NOC doing monitoring and observability.
772170	773910	So, those have always been important to me.
774130	782190	Thankfully, to make this a little easier, NixOS has modules for Grafana and Prometheus, which are both popular common choices for this.
782190	783510	So, we'll start there.
783510	797410	First things up, we'll get a basic config going that's just enough to run those things, a Grafana dashboard to look at, Prometheus to store our metrics, and a node exporter to export things, which we'll just do on my laptop here.
797990	799090	This is all great.
799090	804730	But, of course, without any help, it's all kind of trapped on one box or on one network.
806130	808290	So, here is that config.
808290	811210	Up top, we have services.grafana.
811210	813170	Pretty standard for NixOS modules.
813170	817130	Turn it on with enable, and then you can pass it some settings.
817130	822710	In this case, you can tweak the listening address, the port, enable optimizations like gzip, whatever.
822710	825130	This is a pretty basic stock config you might use.
825370	828570	And then, same thing down below, we have Prometheus.
828830	831890	Making a listen, you can tweak stuff like scrape interval.
832210	834810	And then in this case, we're setting up a node exporter.
834830	840950	So, you can also customize the collectors you want to run, add your own collectors that you're building from source using Nix if you want.
840950	842170	All totally possible.
842170	845190	But for this, just a sort of basic collector to start.
848130	850210	And what does that get us?
850210	855870	Well, up top, you'll see a snapshot of my personal tailscale dashboard.
855870	863470	And I'm really just using tailscale here because I have a lot more stuff on Nebula, so it was easier to delete things off tailscale to get a clean snapshot.
864290	866850	So, all we have is node one.
866850	869450	And that is this old ThinkPad running right here.
869450	873730	It just has a regular tailscale running on the host, exposing the whole host.
874590	879810	And then if we take a look below, we can look at what is listening on this host.
880170	881490	And we've got three things.
881490	883730	We've got Prometheus on 9090.
883730	886030	We have node exporter on 9000.
886030	888230	And Grafana on 3000.
888350	888630	Okay.
888630	888970	Great.
888970	889650	Kind of expected.
889650	891510	They're all exposed locally on the host.
891530	892890	Nothing too fancy is going on.
892890	896430	And all tailscale knows about is the actual host itself.
899160	902260	And this is where my module comes in.
902260	903820	The mesh sidecar module.
903820	905760	So, you've got to add this to your configuration somehow.
905760	906620	Not pictured.
906660	908380	Come talk to me after if you want help with that.
908380	909500	But Flakes make it easy.
909500	911940	You can build it into your NixOS config, pull it in.
912140	914000	Lots of options there.
914580	917400	And so far, we've got just a simple interface.
918160	919400	You start by turning it on.
919400	920100	Say enable.
920100	920680	Yep.
920780	922480	And then you select a provider.
922520	927400	Right now, the module supports tailscale and netbird, but open to others in the future.
927460	932520	You do have to tell that maybe considering perhaps letting you do both at once down the line.
932520	934100	But so far, one only.
934340	936580	And then you're going to need an auth key.
936800	941660	And both tailscale and netbird let you have auth keys to sort of dynamically add hosts.
941660	943440	So, that's what this module relies on.
943520	944780	Store it somewhere secure.
944820	946780	We'll pick it up with systemd credentials.
946780	948440	So, it never touches the Nix store.
948440	951140	So, as long as you secure it, we won't mess it up.
951720	954440	And then a little bit more manual config here.
954440	955820	The bridge name, totally optional.
955820	957140	You can customize that.
957140	959080	We are going to make ourselves a network bridge.
959080	960420	We'll get more into that.
960440	963220	But right now, you do need to set the outbound interface.
963280	969200	The services we run, at least the tailscale or netbird part, are going to go need to talk to the control plane.
969200	970900	So, they're going to need a connection.
970900	976220	So, we'll give them a regular NATed outbound connection, just kind of like Docker Compose does by default.
976620	979720	So, here I'm choosing a wireless network WLP.
980380	985960	And then the main meaty bit of this is the services section down there at the end.
986540	989500	So, to start, we're just going to wrap Grafana and Prometheus.
989600	990860	But I did include an example.
990860	994080	If you wanted to wrap the node exporter itself, totally possible.
994660	1003640	And we now have the ability, if you want, if you don't want the service name to match the name that shows up on your mesh network, you can customize that now, too.
1006240	1006860	Okay.
1006860	1009600	So, we've added ourselves a new module.
1009620	1015860	We've told it, go back, we've told it specifically that we want to wrap Grafana and Prometheus.
1016080	1019000	There we've just got empty dictionaries.
1019040	1022940	We're not doing any per-service config, but that's there if you want to.
1024340	1032060	Now we're going to make a couple little updates just to take better advantage now that we know we're transitioning to a mesh-first model.
1032200	1034580	So, first things up, we're going to update Prometheus.
1035080	1041920	In particular, what we're going to add here, because NixOS is great, you can do a lot of this configuration statically.
1041920	1049500	Instead of having to configure it after you get the service running, we can add static scrape configs at build time, at configuration time.
1049500	1061660	And so, in this case, we're going to add a single target, which is going to be node 1, and then you'll see that's a tailnet internal domain, local to tailscale, but basically that's the name for my mesh network.
1061920	1070040	So, it's going to find node 1 on the mesh, and then the second part is me just grabbing the port out of the config to be concise, but you totally don't need to do that.
1070040	1072580	You could hard-code it or pull it dynamically or whatever.
1072980	1081520	So, this says Prometheus, scrape over the mesh network to talk to node 1, and then we'll continue on with our Grafana.
1082140	1086280	Here, we will update Grafana also to add some static configuration.
1086400	1091380	In this case, we're going to tell it we want to do some provisioning and we want to configure a data source.
1091420	1092480	What data source is that?
1092480	1094580	Well, it's the Prometheus we've been setting up.
1094740	1099840	So, we can just go in there, data sources, name Prometheus, customize whatever you need.
1099840	1105780	Same thing, the main important point here is way at the bottom, we are going to talk to Prometheus.
1105780	1109980	Grafana is going to talk to Prometheus over the tail net, over the mesh network.
1109980	1112040	It doesn't have to care anything else about it.
1114900	1125740	Okay, and then this is the part where we have to wait to make it... I mean, I'm not doing a live demo because, you know, conference Wi-Fi, though it sounds like they've done incredible work to get that going pretty well.
1125800	1128580	So, I'm just going to do a NixOS rebuild switch here.
1128580	1131640	This is going to apply those changes that we were just talking about.
1131720	1134220	It also gives me a chance to just take a minute .
1134220	1135140	We can wait for that to happen.
1135140	1137460	I'll take a drink.
1143680	1145060	We're almost there.
1145060	1149160	Probably should have used a smaller system config, but, you know, I like to have a lot of packages.
1153060	1157000	And this is the part where we figure out, okay, so we're done.
1157200	1166700	We've stopped grafana.service and prometheus.service and then we'll see the combination of NixOS and the activation scripts and systemd.
1167260	1173680	NixOS figured out we changed grafana and prometheus, so it knows it needs to stop and restart those with the new configurations.
1174080	1186020	And then, because we've set systemd up to know about all sort of the dependencies to make the networking work, we'll see that it then spits out the following new units were started with a whole bunch of crap.
1186020	1190160	So, that's kind of the new stuff that the module has added to make it work.
1193060	1197620	And then, I think, if we continue here, we'll take a quick peek.
1198380	1198740	Okay.
1198740	1205220	So, that is me rerunning the modern netstat to take a look at what is listening on the host.
1205940	1208920	And all we see now is the node exporter.
1208920	1217600	So, we did that update, we did a NixOS rebuild to apply the configuration changes, and suddenly, grafana and prometheus have vanished from our system.
1221280	1222080	Okay.
1222080	1226500	So, surveying our work, we head over to the TailScale dashboard.
1226500	1227500	What do we see?
1227660	1233760	Well, now, we see same node one we had before, but we also see grafana and prometheus.
1233760	1240740	And they get automatically assigned an internal IP address by TailScale, and they get DNS entries added in TailScale's internal DNS.
1240740	1246080	So, now, anything connected to that network can just ask to talk to grafana, and it's going to get the right thing.
1248440	1252480	And then, locally, we can just pop into our browser and type in prometheus.
1252480	1262800	In this case, I went with the full domain, but if you set up search domain, which TailScale does by default, you can just go on a, you know, just type prometheus or grafana into the browser, and the rest will just work.
1262900	1267720	So, we pop over, we pull up a browser, we type in prometheus, and what do we get?
1267720	1270900	Well, for one, we actually connect to it.
1270900	1274820	And then, after that, we see that it did, in fact, take that configuration.
1274900	1282120	It now has a single endpoint to scrape, which is our node one, and it is up and online and was able to complete a scrape.
1282720	1284740	So, did it work with grafana?
1286100	1295480	Oh, actually, before we get to grafana, my bad, just to confirm here, we do also see that that connection to... oh, no, this is... oh, yeah, right.
1296400	1298780	Go back, prometheus.
1298780	1299920	Here we go.
1299920	1301060	We are onto grafana.
1301060	1307520	So, when we reconfigured grafana, we had told it to talk to prometheus, because we needed data for our dashboards.
1307520	1314480	So, this is just a quick first glance to confirm, yes, indeed, prometheus server URL is pointing to our mesh network name.
1315040	1319640	And then, we can continue on in grafana, pull up a dashboard, and what do we get?
1319640	1321700	We get node one's metrics.
1322000	1324680	Now, doesn't seem like much has happened.
1324860	1333080	On the surface, it all kind of just works like it was before, except now, we're no longer trapped to a single box or a single layer.
1333800	1341620	We have node exporter running on the laptop just totally as normal, exposed by a tail scale out to the wider network.
1341900	1356100	And then, prometheus and grafana running wherever they want, it just happens to be on the same laptop, wrapped by the mesh sidecar module, isolated from the host, that's why they vanished from our port scan, and they're exposed only via the tail scale sidecar.
1356100	1360180	So, we've actually managed to escape the LAN with mesh network sidecars.
1361560	1362980	Okay, how does it work?
1362980	1363960	What actually happened?
1363960	1371440	Well, most of it is network namespaces, which is a delightful kernel feature that gives you a totally separate networks deck, essentially.
1371640	1377420	You can think of it as just the networking isolation of container engines and docker and podman and the like.
1377420	1388560	So, you can still see the root file system, you can still use all your files, but it's a great way to run things isolated, either just with no network connectivity, say you're doing, you know, a software build, you want to make sure it doesn't reach out anywhere,
1389420	1391560	or just for VPNs, like we'll do today.
1391900	1394560	But to make that work, first things first, we're going to need to switch.
1394560	1398900	So, in this case, we build a virtual bridge, and that's just on the normal host networking stack.
1399420	1406100	And then, to connect everything together, and this is the part where we're kind of just aping Docker Compose's style and building ourselves a virtual local network.
1407020	1419900	To connect things together, we need to use network namespaces per service for isolation, and then virtual Ethernet pairs, or VEs, which you can think of as basically just a virtual Ethernet cable.
1419900	1426980	It has two ends, you know, and they'll let you connect networks or hosts or services or whatever you want between your different network namespaces.
1426980	1429360	Just a little bit of network plumbing for the kernel.
1429760	1435300	So, we have one end on the host in this case, and the other one goes in our per service namespace.
1435300	1443220	So, each service has its own namespace, and each namespace gets a link back to the main host namespace, which actually has access to the outside world.
1444180	1446320	From that, we add each of those pairs.
1446320	1462880	We essentially plug in the host side into our virtual switch so that they can all talk outward, and then we do some basic routing, some NAT, DHCP, that kind of thing, just like Docker Compose does, so that anything on the gets a NAT-ed connection out by that outbound interface that we configured.
1463440	1467140	And then, after that, you get a whole lot of system D2.
1468100	1473420	But, just because that was a lot of text, here's a simplified version in a mermaid diagram.
1474000	1478020	This is just, let's say we weren't running Prometheus, this is just a Grafana example.
1478460	1488600	Go to your host OS, the browser talks via the host tail scale over the mesh, over to the Grafana namespace, where it comes in over the Grafana sidecar tail scale.
1488660	1494580	That lets it talk to the Grafana service, and then that can go all the way back and actually render Grafana in your browser.
1495080	1512160	And then, at the same time, the Grafana service can use the Grafana sidecar, well, really, the Grafana sidecar uses the VEF to talk to bridge 0 so that it can actually go talk to the tail scale control plane, connect things, and ultimately forward all of your mesh VPN traffic out to the rest of the network.
1513820	1522020	Same deal here, just the expanded example that was the demo we actually did today, where we have Grafana, Prometheus, and our node exporter.
1522080	1529280	And the main takeaway really is just that the node exporter lives regularly on the laptop.
1529280	1536120	Prometheus and Grafana do too, but they don't care because as long as they just talk over the mesh, they don't have to care.
1536120	1539580	Tail scale, Netbird, Nebula, it'll figure the rest out.
1539580	1543540	And especially it just works nicely because you can just move them wherever you'd like.
1545220	1555560	And you can maybe see hopefully in the diagram that each one has its own namespace, there's the host one, and then probably the node exporter should be in the host namespace too, but main point is they talk over the mesh.
1557400	1559580	Okay, here's a bit of systemd.
1560180	1561340	What did we actually do?
1561340	1563720	We're wrapping services, but what does that mean?
1563720	1564960	How did it change?
1564960	1568440	It didn't really look like we touched Grafana or Prometheus.
1568720	1577740	Under the hood, we modified the systemd config that NixOS modules gave us to start, and then we added this little block highlighted in red.
1577740	1581240	Well, not the description, the sorting just isn't great, so ignore that part.
1581240	1587620	In particular, we added binds to, and that tells systemd basically that tail scale is a hard dependency.
1587620	1592220	So if we stop Grafana or we stop tail scale, they'll both stop.
1592220	1594020	If we start one, they'll both start.
1594080	1595260	Things like that.
1595340	1598620	And that's where the nice graph dependency aspect of systemd comes in.
1598920	1601140	And then joins namespace out.
1601140	1612260	That's the killer feature here, where if we start a service with its own namespace, in this case tail scale, we run tail scale, it gets its own network namespace with joins namespace of.
1612260	1618940	Whatever we add that to will automatically join that namespace and be network isolated, won't get the default behavior.
1621200	1627040	And if we go take a look at what the networking looks like on the host, you can ignore probably the first four.
1627040	1629120	Those are normal standard connections.
1629120	1631940	But starting at number five, we've got tail scale zero.
1631940	1635900	And that's the normal host tail scale, like if you just run tail scale anywhere.
1636300	1640420	Br zero, that is our virtual switch or bridge on the host.
1640420	1644160	And then we see we have Grafana and Prometheus interfaces.
1644920	1648800	Those are the host side of those virtual ethernet pairs I was talking about.
1648800	1651820	And we'll see their other side as we go take a look.
1651820	1660680	Next, we can do sudo ip net ns exec Grafana to run commands in our Grafana service network namespace.
1660680	1665180	And so here we just did ip adder, sorry if config, we did ip adder again.
1665180	1668960	And here we have a separate loopback, each namespace gets its own loopback.
1668960	1670680	And then we have eth zero.
1671720	1674780	Eth zero is the other side of that virtual ethernet pair.
1674780	1680480	So you have Grafana on the host, and you have eth zero, each service will have its own eth zero living in its namespace.
1680480	1684820	And then of course, because we have a sidecar, you get tail scale zero in here as well.
1684820	1688600	And that's the per service tail scale running just for Grafana.
1691280	1694020	Okay, so that's how it works.
1694020	1695460	But it's all new.
1695660	1698260	I think it's safe to call it alpha.
1698480	1700540	It still could have breaking changes.
1700540	1704680	In particular, I would like to add Nebula support as a sort of first thing at the gate.
1704680	1707060	So if that takes breaking changes, it'll happen.
1707060	1709060	After that, I'm going to try not to.
1709700	1711360	Yeah, like I said, more VPNs.
1711360	1712860	I don't know, zero tier.
1713220	1714900	There's a whole bunch of options.
1714900	1716960	So if we can support it, I'm totally open.
1717240	1724000	Also, one thing you can do with network namespaces, let's say you just have like a regular open VPN connection, you spin that up.
1724000	1736200	If you make a network namespace, and then you move that VPN interface into that namespace as the only interface in there, then anything that runs in that namespace, that's all it gets.
1736200	1741720	So if tail scale or open VPN goes down, it loses connectivity, it doesn't get a regular NAT and connection.
1741780	1749620	And this is possible, because the kernel remembers, it essentially knows that like, when you started that open VPN interface, it lived in network namespace zero.
1749700	1753400	And so it's still allowed that link, but nothing else in the new namespace gets it.
1753400	1756540	So we could have more isolation than we have by default here.
1756540	1760300	I was kind of copying the style Docker is familiar with, but we could take it to the next level.
1760460	1766300	And then of course, whatever anyone else wants, you guys, the community, PR is welcome.
1767180	1769460	And then just a final review at the end.
1769460	1772520	This has been Mesh Network Sidecars for NixOS Services.
1772540	1782780	We embrace the flat mesh network with per-application network entities, of course, powered by tail scale, network namespace, and systemd, and very much Nix.
1782780	1785160	And if you'd like to try it, it's out now.
1785160	1789200	Head on over to github.com slash NoblePane slash Mesh Sidecar.
1789200	1793500	Thank you very much, and feel free to come find me for questions afterwards.
1793700	1794340	Take care.
