We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Nix at Home - Configuration management for your House!

00:00

Formal Metadata

Title
Nix at Home - Configuration management for your House!
Subtitle
Or...How I use enterprise level tools to have sanity at home!
Title of Series
Number of Parts
27
Author
License
CC Attribution 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
My talk I'm proposing is on how to use nix at home in a variety of different ways. We'll start with the basics, a single git repository with multiple machine configurations cloned to /etc/nixos. From there we'll talk about how to deploy machines using nixops with the none backend, specifically in the context of a home router machine with multiple interfaces running all the basic services needed for a secure usable home network. From their we'll foray into how nixos generations works under the hood a bit and talk about IOHK's work at making a remote deployable mac system using nix-darwin, as well as some custom code I wrote that allows you to run nix systemd services (example being prometheus node exporter) on any linux system. We'll wrap the talk up with some discussion about using nix for home automation and monitoring as well as a chance for Q&A. --- Bio: I've been involved with the nix community for a little over a year. I help out on IRC whenever I have a chance (disasm). I work on the devops team of IOHK using nix and haskell on a daily basis. I've been using nixops to deploy my main home router for a little over 6 months, and have been using custom haskell to deploy my mac systems using nix-darwin for about 3 months.
Data managementLevel (video gaming)Enterprise architectureMultiplication signSoftwareVirtual machineLaptopConfiguration managementEnterprise architectureLatent heatScaling (geometry)Level (video gaming)Control flowMathematicsSoftware testingDirectory serviceSoftware repositoryType theoryServer (computing)System programmingoutputGodPhysicalismComputer configurationOnline helpState of matterRepository (publishing)FreewareShared memoryLecture/ConferenceMeeting/Interview
Software developerData managementEnterprise architectureLevel (video gaming)Computer animation
Software developerComputer hardwareModul <Datentyp>Content (media)Power (physics)File formatLatent heatIntegrated development environmentRouter (computing)FamilyKey (cryptography)Computer networkLaptopElectronic data interchangeCodeSystem programmingElectronic visual displayScripting languageMachine codeMultiplicationConfiguration managementMaß <Mathematik>Service (economics)Web serviceDemonRight angleKey (cryptography)Server (computing)Computer fileVirtual machineDifferent (Kate Ryan album)Repository (publishing)Type theoryConfiguration managementRevision controlLaptopSoftware repositoryComputer hardwareModule (mathematics)Scripting languageMixed realityLatent heatPlug-in (computing)Default (computer science)Tracing (software)BuildingResultantSystem programmingBootingCodeDemonExecution unitOperator (mathematics)Remote procedure callWeb serviceSoftwareSlide ruleBinary fileRule of inferenceoutputService (economics)MehrplatzsystemData miningMultiplication signMathematicsNormal (geometry)Installation artIP addressTurtle graphicsCloningAttribute grammarPasswordGoodness of fitDirectory serviceCASE <Informatik>Shared memoryRootkitProfil (magazine)Router (computing)Electronic mailing listProcess (computing)Public key certificateInternetworkingStructural loadContent (media)String (computer science)File formatMappingMachine codeLink (knot theory)SimulationPhysicalismPoint (geometry)
System programmingComputer programmingElectric generatorScalabilityProduct (business)Service (economics)System programmingMultiplicationProfil (magazine)
Modul <Datentyp>System programmingRadio-frequency identificationCodeImplementationComputer configurationUser profileSoftware design patternConfiguration managementConfiguration managementComputer configurationImplementationMaxima and minimaProfil (magazine)Software repositoryAbstractionTouch typingHacker (term)System programmingCodeMultiplication signProcess (computing)CodecSoftware design patternDirectory serviceSource code
System programmingConfiguration managementServer (computing)Computer networkVirtuelles privates NetzwerkWind tunnelRight angleSoftware testingState transition systemOpen setLoginRouter (computing)SpacetimeSoftwareControl flowServer (computing)PlastikkarteSoftware repositoryPoint (geometry)Stability theorySemiconductor memoryPlanningMiniDiscBootingComputer animation
BefehlsprozessorPower (physics)Router (computing)Hard disk driveInterface (computing)Default (computer science)Solid geometryDrop (liquid)BootingVirtual LANWhiteboardState of matterSoftwareSystem programmingVirtuelles privates NetzwerkMusical ensembleRoutingLaptopFerry CorstenFirewall (computing)Server (computing)Public-key cryptographyModule (mathematics)Configuration managementBitSource code
Transcript: English(auto-generated)
All righty, so it's time for the last talk of the day and so we've already heard about like Nixle set scale and deploying to large physics things and God knows what But similar is actually going to talk about Nix at home configuring Nix for your laptop and
Yeah, let's start Hello everyone I'm Samuel leathers. I work at IOH K I'm a senior DevOps engineer there And I will be talking about Nix at home Configuration management for your house or I like to subtitle it how I use enterprise level tools to have sanity at home
Credit where credit is due Graham Christensen and Clever helped me out a lot with getting this in the state it is now So thank you very much for all your help over the last couple years getting this repo where it is
So why Nix is great for home devices most of us don't have dedicated test networks to test changes out breakage is scary with anything else with Nix just roll back and It's free and easy CI to notify you when things break before you deploy so Types of configuration management with Nix this is how many of you actually use Nix at home
Almost everyone. Okay, so you probably all know all this stuff So I'll run through it pretty quickly, but on a laptop you have a few options You can do Nix OS rebuild switch
From a git repo clone Datsy Nix OS and then just manage all your stuff using git. That's nice But what if you have two laptops and you want to share stuff between those? You can do Nix ops deploy from git repository Cloned anywhere so you can clone it in your home directory and do Nix ops deploy to your localhost or to other servers
in your house But you still run into the state issue that was mentioned earlier With Nix ops where you can only do it from one machine at home. That's usually not too big of a problem though And then what if you have OS X machines and you want to remote deploy those because who wants to
Actually log into an OS X machine and run Nix Darwin rebuild not me So and then what if you have other Linux systems that are not Nix OS, but you really want to run something Consistently using Nix OS on it. So like if you want to run Prometheus node exporter on centos
But you don't really want to have to deal with the hassle of updating young packages and everything So all those things we're going to be talking about here today So for laptops managed locally we want to share some configuration we want some stuff specific per laptop and we want to be able to rebuild a laptop quickly or spin up a new one and
We usually have bleeding-edge software here. Some of you might not I usually run Nix OS unstable on my laptop We have some custom commits cherry-picked That are not on my not in yet sometimes from pull requests or something
And we want to easily test different channels At the same time. So here's how I kind of do it Etsy Nix OS that's where all your configurations go. That's just a is it not going. Oh
No
There now we're going Okay, so how I do it Etsy Nix OS is a clone of my network repo on my github repository These slides will be shared later. If you want to look at that There's plenty of good stuff in there and I'm open to any questions later about it For configuration dot Nix. I actually do a sim link to machine slash host name dot Nix so I can have the same
Git repository clone to multiple hosts that have different configurations and hardware configurations. I do the same thing It's assembling to hardware dash configuration slash host name dot Nix If I want to share stuff between modules, I have a modules directory that contains profiles roles and custom services
I'll talk more about that a little later I include it with custom modules equals import modules module list dot Nix and then custom modules Is added to the imports attribute in the configuration dot Nix file?
After defining a profile I can just do profiles dot vim dot enable equals true And now I have my special vim configuration that I want on all my systems For public shared content, I just create a Nix file called shared dot Nix that just has Content in it. So it's just a huge attribute set
So I put things like my home CA certificate there and my public SSH keys something that I don't care being in the internet Where everyone can see it, but it's still something I want to split across multiple things But what about the secret stuff like the passwords you don't want everyone to know so I create
It I can get ignore I create a secrets dot Nix file In the same format as shared dot Nix and then I add a layer of misdirection for CI using load dash secrets dot Nix, which just does a
Built-ins path exists secrets dot Nix then import it. Otherwise use this other Attribute set that basically usually defines empty strings for everything. So Hydra continues to work For Home deployments. So like I have a server and my main router at home both run Nix OS
So that's easy. I just use Nix ops deploy for that I have an infrastructure dot Nix file that lists all my infrastructure files and you'll see that right here and Then I can use the same Secrets type stuff there as well as the shared stuff and the custom modules that I use on my laptop So now all that stuff is shared across all my systems
So if I change it in one place It can affect everything Which is great when you add a new vim plugin and you don't want to have to SSH into all your servers and install it again So this is just a general Nix ops config here with the network and the name of the server and the deployment
This is the none type. So there's no automatically creating it because it's a physical thing at home And then I can add deployment keys in for secrets that I don't want to be living on the server after a reboot So it has to be deployed again To create the deployment we use the Nix ops create command and you can basically give the deployment a name and then you
Can specify I pinned the Nix pkgs version? to a specific version that one I believe it was the tip of 1809 When I created the slide deck here
But basically you can specify dash I Nix pkg is equals and then the path to the tar ball on GitHub and then that will pin it so you have to run Nix ops modify then Which is shown just below that to update it to a new version later And then you just do Nix ops deploy home. That's simple enough deploy dash d home
and Then for remote OS X deployments, I don't use OS X very often even though this is a Mac It's running Nix OS like ninety nine point nine nine nine percent of the time. I do have another laptop at home That's a MacBook Air that's just thrown in the closet somewhere that I don't want to climb over everything to get to
Or I don't really want to be and see into it either or SSH and manually run stuff So Nix Darwin is great for Giving you the same configuration management on Linux on Mac OS so Buddy of mine at IOHK Rodney. He's not here today, but he created a really cool tool
for us there that basically Prepares a system using Haskell installing Nix installing Nix Darwin and everything and then runs deployments Remotely using turtle SSH and I did some improvements to that I won't go into the code here as this talk isn't about Haskell, but Nix
So remote OS X deployments the premise is to build two tools one called prepare and one called deploy These two tools remotely SSH into the host and handle the Nix Darwin stuff prepare installs Nix and multi-user and deploys Deploy deploys new changes a caveat here is Nix Darwin and Nix OS modules don't always have the same design
So some breakage may occur if you share configuration Code is in Nix Darwin tools in my repo The prepare script is slightly outdated if you want to do this I highly recommend looking at the IOHK version of this stuff, even though it has a few IOHK specific things in there
It actually installs with multi-user now with prepare I haven't updated that in my repo because I ran repair since the default change to using single-user on OS X again And it requires an OS X build slave to build the tool
Running prepare will nuke all traces of Nix from the remote system so don't do this on a system that you've like very carefully crafted your pet on and For deployments you just do Nix build dash a tools and then you can run result bin prepare Mac And then the IP address of it and then result bin deploy rule
Role and then the role is just a Nix file. That's like a configuration dot Nix file that you'd have on your Darwin system and Yeah, and then you can use the same modules you're using for Nix OS as long as you write them in a way that They work on both
Darwin and Linux For Linux deployments. This is kind of cool, but I kind of abandoned it because everything runs Nix OS now at home So I don't have much use for it anymore But I wanted to share this anyways, because I'm sure there's a lot of people here that might benefit from it the initial premise was to set up Prometheus node exporter running on non Nix OS Linux systems like CentOS 7 and
To do this I basically it looks like a normal Nix OS configuration that you'd run Nix OS rebuild on But you do an import of Nix pkgs Nix OS and then all it only supports services
So it only does system D services. It doesn't do users This is probably good as it would probably Break other things on the system if you started trying to mess with Etsy password and whatnot on a system That's being managed some other way and then you just specify your services out and then there's this recursive attribute set that does
some build ENV stuff and maps the paths to it and it literally dumps out a so you can then Nix build that on the system and if you do find dot slash results, you'll see everything in there
All you're gonna see are service files and then Nix ENV dash P specify Where your user root is for it? So in this case I have user root centos monitor and then I specify the file I want to
Install there and I specify that I want to grab the all units attribute here And then I just sim link that to Etsy system D system centos monitor do system CTL demon reload system CTL start Prometheus node exporter and I now have Prometheus node being managed with Nix code that could be automated further using
Haskell to like write a tool or Python fabric or any other automation tool that uses SSH to Make this a simple process very similar to how the next Darwin stuff above was done This works I tested it before I wiped my last non Nix OS system
New runs of Nix ENV create a new generation so you can roll back with this too, which is pretty cool You really just need the Prometheus node exporter But I included other services so you can see that it's scalable and run multiple services this way To use in production. Like I said, I'd recommend using some other
Deployment tool rather than just manually SSHing in and running Nix ENV. That's never a good idea So the custom modules profiles and roles I said I was gonna touch back on later I first used the profiles and roles design pattern with puppet in a previous job If anyone's used puppet, they've probably heard about the profiles and roles design pattern
When used properly each system should only have one role and a role should only define profiles My repo does not follow this at all. The initial code came from a repo by offline hacker But it's pretty different from his original implementation in essence both profiles and roles are just Nix OS modules with a different prefix
I don't use roles a lot at all and my repo I have a base role that doesn't have an enable option for things I want on any system But that's pretty much all I use roles for Profiles are glue around Nix OS configuration So for example something like profiles vim enable equals true abstracts away lots of vim configuration setup
And most profiles have an enable option if you don't have one It's gonna be on all your systems, which is probably not what you want and My goal here is to clean up all the stuff and my legacy and Nix configs directory Which is kind of a mess and have just like the bare minimum and Nix configs and everything else is just profiles
But I just haven't had time to play with it yet and These can be shared across all Linux OS X systems So you might have to do some conditional things based on how Nix Darwin does something in Nix OS does something and then most
Importantly we need CI to test everything so Hydra to test everything I define a Nix OS funk stable Nix OS funk unstable and a Nix Darwin funk Unstable that point to these that are defined in Hydra if you want to see how they're defined in Hydra you can look at my
Hydra configs repo under the same username on github And then Nix Darwin tools is what I told you about with the tools to actually deploy and So those are all tested as well, so when they break from some
LTS upgrade and latest Nix I know about it and this will actually test with every single commit that hits Nix OS unstable for serov and The Mac one for all the unstable commits and
For my servers optina and portal it will hit 1809 any commits that hit it it will rerun and make sure everything's going so I know as soon as Something upstream breaks something that I did that I need to fix And some other cool features about my network repo that I not gonna get into a whole lot of detail
Here, but I have full I pixie network booting. Thanks to clever. He really helped me with that one I have full IPv6 compatibility on my router my routers fully running Nix OS and I have wired guard VPN tunnels open VPN tunnels Prometheus monitoring and I had an elk stack for central logging by disabled it
Because of lack of resources on my server and just like running out of memory and disk space And it was like I don't need to keep all my logs anymore That is pretty much my talk here I can jump in I see we're at about 16 Well, no, we're not at 16 minutes because we refreshed this so I don't remember how far and we are
Okay, so we can jump in here and I can walk you through some of the stuff I've done in my repo that requires Me to mirror this though. No, I had a different plan. That's right
We are going to seven not attached to the same tmux session. That's not good
Let's just exit this one and try a tmux attach There we go
Typing one-handed and holding a microphone is very difficult Let's look at the router config a bit here because this might be interesting to some people that want to
There we go That might be interesting to some people that want to run a router at home so we can look at that
and The default dot nix. I basically define some internal interfaces these are V lands on This interface here and then I have some wire guard stuff and those are my VPNs one of the cool things here is
The I pixie stuff I mentioned and this basically Creates a TFTP route that I pixie can boot And builds a nyx OS module nyx OS System that basically can be booted over the network
And then I define interfaces here for the firewall a lot of this stuff came from Graham I have some cool extra commands here for like drop port no log Except port on interface ford port to host And then I can basically just map across ports and then yeah wire guard
Interfaces those are public keys, so don't worry about it Does anyone have any specific questions about this?
My router does not boot from the network My router is running a TFTP server so I can boot any laptop over the network So It's very useful for installing nyx on things. I've been playing with trying to get raspberry pi
to network boot as well, but that's a little more difficult because you have to Actually Disable some GPI opens Michael can tell you more about it later if you're interested. He was showing me some of it But Yeah, my router does not network boot. It's it has a solid-state hard drive in it and it
Has monitoring on it and all that good stuff Any other questions? Well, I guess we can all go drink beer then