Repository: aksiksi/compose2nix (go)

Issue:
Support "hostname" on services
When adding tailscale as a side-car container hostname gets mapped onto the tailnet machine name. 

Pull request description:
Teach compose to output 'hostname' when present in the compose file
Fixes #6 

This is support for this natively on oci-containers NixOs/nixpkgs#258299, however it's still on unstable

Patch:
diff --git a/compose.go b/compose.go
index f652183..507e0df 100644
--- a/compose.go
+++ b/compose.go
@@ -399,6 +399,10 @@ func (g *Generator) buildNixContainer(service types.ServiceConfig) (*NixContaine
 		c.ExtraOptions = append(c.ExtraOptions, fmt.Sprintf("--add-host=%s:%s", hostname, ip))
 	}
 
+	if service.Hostname != "" {
+		c.ExtraOptions = append(c.ExtraOptions, "--hostname="+service.Hostname)
+	}
+
 	// https://docs.docker.com/compose/compose-file/05-services/#sysctls
 	// https://docs.docker.com/engine/reference/commandline/run/#sysctl
 	// https://docs.podman.io/en/latest/markdown/podman-run.1.html#sysctl-name-value


Test patch:
diff --git a/testdata/TestDocker_EnvFilesOnly_out.nix b/testdata/TestDocker_EnvFilesOnly_out.nix
index 493c047..3524fee 100644
--- a/testdata/TestDocker_EnvFilesOnly_out.nix
+++ b/testdata/TestDocker_EnvFilesOnly_out.nix
@@ -81,6 +81,7 @@
     autoStart = false;
     extraOptions = [
       "--health-cmd='curl -f http://localhost/'"
+      "--hostname=sabnzbd"
       "--log-opt=compress=true"
       "--log-opt=max-file=3"
       "--log-opt=max-size=10m"
diff --git a/testdata/TestDocker_RemoveVolumes_out.nix b/testdata/TestDocker_RemoveVolumes_out.nix
index 10bcbee..f88caaf 100644
--- a/testdata/TestDocker_RemoveVolumes_out.nix
+++ b/testdata/TestDocker_RemoveVolumes_out.nix
@@ -89,6 +89,7 @@
     autoStart = false;
     extraOptions = [
       "--health-cmd='curl -f http://localhost/'"
+      "--hostname=sabnzbd"
       "--log-opt=compress=true"
       "--log-opt=max-file=3"
       "--log-opt=max-size=10m"
diff --git a/testdata/TestDocker_SystemdMount_out.nix b/testdata/TestDocker_SystemdMount_out.nix
index c280115..b43371b 100644
--- a/testdata/TestDocker_SystemdMount_out.nix
+++ b/testdata/TestDocker_SystemdMount_out.nix
@@ -91,6 +91,7 @@
     autoStart = false;
     extraOptions = [
       "--health-cmd='curl -f http://localhost/'"
+      "--hostname=sabnzbd"
       "--log-opt=compress=true"
       "--log-opt=max-file=3"
       "--log-opt=max-size=10m"
diff --git a/testdata/TestDocker_WithProject_out.nix b/testdata/TestDocker_WithProject_out.nix
index e07dd91..9eb1ace 100644
--- a/testdata/TestDocker_WithProject_out.nix
+++ b/testdata/TestDocker_WithProject_out.nix
@@ -89,6 +89,7 @@
     autoStart = false;
     extraOptions = [
       "--health-cmd='curl -f http://localhost/'"
+      "--hostname=sabnzbd"
       "--log-opt=compress=true"
       "--log-opt=max-file=3"
       "--log-opt=max-size=10m"
diff --git a/testdata/TestDocker_out.nix b/testdata/TestDocker_out.nix
index 9805522..a9d7f26 100644
--- a/testdata/TestDocker_out.nix
+++ b/testdata/TestDocker_out.nix
@@ -87,6 +87,7 @@
     log-driver = "journald";
     extraOptions = [
       "--health-cmd='curl -f http://localhost/'"
+      "--hostname=sabnzbd"
       "--log-opt=compress=true"
       "--log-opt=max-file=3"
       "--log-opt=max-size=10m"
diff --git a/testdata/TestPodman_WithProject_out.nix b/testdata/TestPodman_WithProject_out.nix
index 314f724..055ee15 100644
--- a/testdata/TestPodman_WithProject_out.nix
+++ b/testdata/TestPodman_WithProject_out.nix
@@ -88,6 +88,7 @@
     autoStart = false;
     extraOptions = [
       "--health-cmd='curl -f http://localhost/'"
+      "--hostname=sabnzbd"
       "--log-opt=compress=true"
       "--log-opt=max-file=3"
       "--log-opt=max-size=10m"
diff --git a/testdata/TestPodman_out.nix b/testdata/TestPodman_out.nix
index 2af245a..e285309 100644
--- a/testdata/TestPodman_out.nix
+++ b/testdata/TestPodman_out.nix
@@ -86,6 +86,7 @@
     log-driver = "journald";
     extraOptions = [
       "--health-cmd='curl -f http://localhost/'"
+      "--hostname=sabnzbd"
       "--log-opt=compress=true"
       "--log-opt=max-file=3"
       "--log-opt=max-size=10m"
diff --git a/testdata/docker-compose.yml b/testdata/docker-compose.yml
index 46e1e52..060d142 100644
--- a/testdata/docker-compose.yml
+++ b/testdata/docker-compose.yml
@@ -3,6 +3,7 @@ name: "myproject"
 services:
   sabnzbd:
     image: lscr.io/linuxserver/sabnzbd
+    hostname: sabnzbd
     environment:
       PUID: ${PUID}
       PGID: ${PGID}