nixos/deploy-rs: Show container unit log while deploying
This commit is contained in:
		
							
								
								
									
										64
									
								
								nixos/boxes/colony/vms/shill/containers/chatterbox.nix
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								nixos/boxes/colony/vms/shill/containers/chatterbox.nix
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,64 @@
 | 
			
		||||
{ lib, ... }: {
 | 
			
		||||
  nixos.systems.chatterbox = {
 | 
			
		||||
    system = "x86_64-linux";
 | 
			
		||||
    nixpkgs = "mine";
 | 
			
		||||
 | 
			
		||||
    assignments = {
 | 
			
		||||
      internal = {
 | 
			
		||||
        name = "chatterbox-ctr";
 | 
			
		||||
        domain = lib.my.colony.domain;
 | 
			
		||||
        ipv4.address = "${lib.my.colony.start.ctrs.v4}5";
 | 
			
		||||
        ipv6 = {
 | 
			
		||||
          iid = "::5";
 | 
			
		||||
          address = "${lib.my.colony.start.ctrs.v6}5";
 | 
			
		||||
        };
 | 
			
		||||
      };
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    configuration = { lib, pkgs, config, assignments, ... }:
 | 
			
		||||
    let
 | 
			
		||||
      inherit (lib) mkMerge mkIf;
 | 
			
		||||
      inherit (lib.my) networkdAssignment;
 | 
			
		||||
    in
 | 
			
		||||
    {
 | 
			
		||||
      config = mkMerge [
 | 
			
		||||
        {
 | 
			
		||||
          my = {
 | 
			
		||||
            deploy.enable = false;
 | 
			
		||||
            server.enable = true;
 | 
			
		||||
 | 
			
		||||
            secrets = {
 | 
			
		||||
              #key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICkly/tnPmoX05lDjEpQOkllPqYA0PY92pOKqvx8Po02";
 | 
			
		||||
              files."synapse.yaml" = {};
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            firewall = {
 | 
			
		||||
              tcp.allowed = [ 8008 ];
 | 
			
		||||
            };
 | 
			
		||||
          };
 | 
			
		||||
 | 
			
		||||
          systemd = {
 | 
			
		||||
            network.networks."80-container-host0" = networkdAssignment "host0" assignments.internal;
 | 
			
		||||
          };
 | 
			
		||||
 | 
			
		||||
          services = {
 | 
			
		||||
            #matrix-synapse = {
 | 
			
		||||
            #  enable = true;
 | 
			
		||||
            #  withJemalloc = true;
 | 
			
		||||
            #  settings = {
 | 
			
		||||
 | 
			
		||||
            #  };
 | 
			
		||||
            #};
 | 
			
		||||
          };
 | 
			
		||||
        }
 | 
			
		||||
        (mkIf config.my.build.isDevVM {
 | 
			
		||||
          virtualisation = {
 | 
			
		||||
            forwardPorts = [
 | 
			
		||||
              { from = "host"; host.port = 8080; guest.port = 80; }
 | 
			
		||||
            ];
 | 
			
		||||
          };
 | 
			
		||||
        })
 | 
			
		||||
      ];
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@@ -27,6 +27,27 @@ let
 | 
			
		||||
    ${keepGensSnippet "$PROFILE" cfg'.keepGenerations}
 | 
			
		||||
  '';
 | 
			
		||||
 | 
			
		||||
  systemdUtil = pkgs.writeShellApplication {
 | 
			
		||||
    name = "systemd-util.sh";
 | 
			
		||||
    text = ''
 | 
			
		||||
      svcActionWatch() {
 | 
			
		||||
        action="$1"
 | 
			
		||||
        shift
 | 
			
		||||
        unit="$1"
 | 
			
		||||
        shift
 | 
			
		||||
 | 
			
		||||
        journalctl -o cat --no-pager -n 0 -f -u "$unit" &
 | 
			
		||||
        jPid=$!
 | 
			
		||||
        cleanup() {
 | 
			
		||||
          kill $jPid
 | 
			
		||||
        }
 | 
			
		||||
        trap cleanup EXIT
 | 
			
		||||
 | 
			
		||||
        systemctl "$@" "$action" "$unit"
 | 
			
		||||
      }
 | 
			
		||||
    '';
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  ctrProfiles = optionalAttrs cfg.generate.containers.enable (mapAttrs' (n: c:
 | 
			
		||||
  let
 | 
			
		||||
    ctrConfig = systems."${n}".configuration.config;
 | 
			
		||||
@@ -35,6 +56,7 @@ let
 | 
			
		||||
    name = "container-${n}";
 | 
			
		||||
    value = {
 | 
			
		||||
      path = pkgs.deploy-rs.lib.activate.custom ctrConfig.my.buildAs.container ''
 | 
			
		||||
        source ${systemdUtil}/bin/systemd-util.sh
 | 
			
		||||
        ${if c.hotReload then ''
 | 
			
		||||
          if systemctl show -p StatusText systemd-nspawn@${n} | grep -q "Dummy container"; then
 | 
			
		||||
            action=restart
 | 
			
		||||
@@ -42,9 +64,9 @@ let
 | 
			
		||||
            action=reload
 | 
			
		||||
          fi
 | 
			
		||||
 | 
			
		||||
          systemctl "$action" systemd-nspawn@${n}
 | 
			
		||||
          svcActionWatch "$action" systemd-nspawn@${n}
 | 
			
		||||
        '' else ''
 | 
			
		||||
          systemctl restart systemd-nspawn@${n}
 | 
			
		||||
          svcActionWatch restart systemd-nspawn@${n}
 | 
			
		||||
        ''}
 | 
			
		||||
 | 
			
		||||
        ${keepGensSnippet "$PROFILE" cfg.generate.containers.keepGenerations}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user