<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Deployment on paradigmatic.systems</title>
    <link>https://paradigmatic.systems/tags/deployment/</link>
    <description>Recent content in Deployment on paradigmatic.systems</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 30 Jan 2025 14:30:00 +0000</lastBuildDate><atom:link href="https://paradigmatic.systems/tags/deployment/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Setting up deploy-rs for NixOS</title>
      <link>https://paradigmatic.systems/posts/setting-up-deploy-rs/</link>
      <pubDate>Thu, 30 Jan 2025 14:30:00 +0000</pubDate>
      
      <guid>https://paradigmatic.systems/posts/setting-up-deploy-rs/</guid>
      <description>&lt;p&gt;Our starting point here is &lt;a href=&#34;https://paradigmatic.systems/posts/provisioning-nixos-node-digital-ocean&#34;&gt;a node that is freshly infected with NixOS&lt;/a&gt;. For changing the system, we have 2 options.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;SSH in and edit the configuration files (or copy them over) and then run &lt;code&gt;nixos-rebuild switch&lt;/code&gt; which triggers the node to pull and build all the necessary items.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check and build the configuration locally, and copy the entire closure across.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;At a glance there might not be an advantage to one or the other. But consider if you&amp;rsquo;re deploying custom content that isn&amp;rsquo;t part of nixOS builtin configuration. To use method (1) you would need to clone all your repos on the server to be able to rebuild. Then every update requires you to ssh in and pull.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>Our starting point here is <a href="/posts/provisioning-nixos-node-digital-ocean">a node that is freshly infected with NixOS</a>. For changing the system, we have 2 options.</p>
<ol>
<li>
<p>SSH in and edit the configuration files (or copy them over) and then run <code>nixos-rebuild switch</code> which triggers the node to pull and build all the necessary items.</p>
</li>
<li>
<p>Check and build the configuration locally, and copy the entire closure across.</p>
</li>
</ol>
<p>At a glance there might not be an advantage to one or the other. But consider if you&rsquo;re deploying custom content that isn&rsquo;t part of nixOS builtin configuration. To use method (1) you would need to clone all your repos on the server to be able to rebuild. Then every update requires you to ssh in and pull.</p>
<p>That&rsquo;s why (2) is the much better option. We will use <a href="https://github.com/serokell/deploy-rs">deploy-rs</a> to implement it on DigitalOcean.</p>
<h3 id="1-enable-flakes-on-the-server">1) Enable flakes on the server</h3>
<p>If you followed the previous instructions you&rsquo;ve got a local folder full of configuration pulled from your node. Go ahead and turn that into a git repo before getting too far into this.</p>
<p>Adjust your <code>configuration.nix</code></p>
<pre tabindex="0"><code>{ pkgs, ... }: {
  imports = [
    ./hardware-configuration.nix
    ./networking.nix
  ];

  environment.systemPackages = with pkgs; [ vim ];

  boot.tmp.cleanOnBoot = true;
  zramSwap.enable = true;
  networking.hostName = &#34;your-hostname&#34;;
  networking.domain = &#34;&#34;;
  services.openssh.enable = true;
  users.users.root.openssh.authorizedKeys.keys = [&#39;&#39;your key here&#39;&#39; ];
  system.stateVersion = &#34;25.05&#34;;

  nix.settings.experimental-features = [ &#34;nix-command&#34; &#34;flakes&#34; ];
}
</code></pre><p>The main changes are to add the content of <code>host.nix</code> (personal preference but you can go ahead and delete that), and enable the flakes feature. Push the whole configuration folder back up and do a rebuild:</p>
<pre tabindex="0"><code>rsync -av --delete --exclude=&#39;.git&#39; ./ [node-name]:/etc/nixos/
ssh [node-name] &#34;sudo nixos-rebuild switch --flake /etc/nixos#default&#34;
</code></pre><h3 id="2-wrap-the-original-configuration-in-a-flake">2) Wrap the original configuration in a flake</h3>
<p>Now, working locally again, create a new <code>flake.nix</code>:</p>
<pre tabindex="0"><code>{
  description = &#34;NixOS configuration&#34;;

  inputs = {
    nixpkgs.url = &#34;github:nixos/nixpkgs/nixos-25.05&#34;;
    deploy-rs = {
      url = &#34;github:serokell/deploy-rs&#34;;
      inputs.nixpkgs.follows = &#34;nixpkgs&#34;;
    };
  };

  outputs = { self, nixpkgs, deploy-rs }: let
    system = &#34;x86_64-linux&#34;;
  in {
    nixosConfigurations.default = nixpkgs.lib.nixosSystem {
      inherit system;
      modules = [
        ./configuration.nix
      ];
    };

    deploy.nodes.default = {
      hostname = &#34;[node-name]&#34;;
      profiles.system = {
        sshUser = &#34;root&#34;;
        path = deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.default;
        user = &#34;root&#34;;
      };
    };
    checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
  };
}
</code></pre><p>This flake:</p>
<ol>
<li>wraps the original system, importing it to <code>nixosConfigurations.default</code>.</li>
<li>describes the deployment target in <code>deploy.nodes.default</code>.</li>
</ol>
<h3 id="3-deploy-it">3) Deploy it</h3>
<p>You can run <code>deploy-rs</code> straight from github:</p>
<p><code>nix run github:serokell/deploy-rs .#default</code></p>
<p>or hit a <code>nix profile install github:serokell/deploy-rs</code> so that you can just use the <code>deploy</code> command.</p>
<p>This should succeed and leave your server right where you started (since the actual configuration is unchanged), but now you have a nice flake to work with locally.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
