diff --git a/blog/2023-11-14-easy-nixos-remote-deployments.markdown b/blog/2023-11-14-easy-nixos-remote-deployments.markdown new file mode 100644 index 0000000..2be5f3a --- /dev/null +++ b/blog/2023-11-14-easy-nixos-remote-deployments.markdown @@ -0,0 +1,78 @@ +--- +layout: post +title: "Easy NixOS remote deployments" +date: 2023-11-14 +comments: true +tags: nixos, nix, flakes +--- + +There exists a [mutitude](https://github.com/NixOS/nixops) +[of](https://github.com/DBCDK/morph) [tooling](https://github.com/krebs/krops) +to remotely manage nixos machines, each with its own features and compromises. + +In my experience, for a simple deployment of few hosts +`nixos-rebuild --target-host` is pretty powerful. + +This is the workflow I've been using to manage my personal systems: + +I bootstrap the machines manually by following the [nixos install +guide](https://nixos.org/manual/nixos/stable/#sec-installation), and copy over +the generated configuration to `config//configuration.nix`. + +On the root directory create `flake.nix`: + +```nix +{ + description = "systems needed"; + inputs = { + # extra inputs go here + }; + + outputs = { self, nixpkgs }@attrs: { + # this is where we add new machines + nixosConfigurations = { + # host fancyHostname + fancyHostname = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = attrs; + modules = [ + # This points to the actual machine configuration + (import ./config/nixmachine/configuration.nix) + ]; + }; + }; + }; +} +``` + +From there, hosts can deployed over SSH! + +``` +nixos-rebuild switch --target-host root@fancyHostname --flake '.#fancyHostname' +``` + + +More hosts can be added by adding them to the `nixosConfigurations` attribute set. + +``` +nixosConfigurations = { + fancySecondHost = { ... } + ... +} +``` + +## Should I do this? + +I think this is an easier workflow for me to manage and debug, However a lot of +things in this space has non-linear learning curves and has sparse documentation +at best. + +So maybe a tool with better documentation might work well for you? + +This also relies heavily on `flakes`, which is "experimental". In my experience, +ground reality is everyone uses flakes, but good documentation is hard to come by + +I've herd good things about Nix [Flakes Book](https://nixos-and-flakes.thiscute.world/), but +haven't read it + +*This was first published at * diff --git a/flake.nix b/flake.nix index bb2e574..45d3a97 100644 --- a/flake.nix +++ b/flake.nix @@ -48,6 +48,7 @@ ghcid cabal-install nodePackages.prettier + python3 ]; }; devShell = self.devShells.${system}.default; diff --git a/templates/default.html b/templates/default.html index c9859ea..29dca6c 100644 --- a/templates/default.html +++ b/templates/default.html @@ -21,6 +21,7 @@