Repository: aksiksi/compose2nix
Pull request #37 (2024-09-16 12:26:24)

Add support for long device syntax, bump compose-go from 2.1.6 to 2.2.0
Bumps [github.com/compose-spec/compose-go/v2](https://github.com/compose-spec/compose-go) from 2.1.6 to 2.2.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/compose-spec/compose-go/releases">github.com/compose-spec/compose-go/v2's releases</a>.</em></p>
<blockquote>
<h2>v2.2.0</h2>
<h2>What's Changed</h2>
<ul>
<li>long syntax for device mapping by <a href="https://github.com/ndeloof"><code>@​ndeloof</code></a> in <a href="https://redirect.github.com/compose-spec/compose-go/pull/676">compose-spec/compose-go#676</a></li>
<li>Support multiple values for extra_hosts by <a href="https://github.com/ndeloof"><code>@​ndeloof</code></a> in <a href="https://redirect.github.com/compose-spec/compose-go/pull/678">compose-spec/compose-go#678</a></li>
<li>Update include definition in JSON schema to fix strings marked as Invalid type by <a href="https://github.com/SolanoJason"><code>@​SolanoJason</code></a> in <a href="https://redirect.github.com/compose-spec/compose-go/pull/674">compose-spec/compose-go#674</a></li>
<li>Fix a small func name typo: GetConfigFiles by <a href="https://github.com/jordanstephens"><code>@​jordanstephens</code></a> in <a href="https://redirect.github.com/compose-spec/compose-go/pull/671">compose-spec/compose-go#671</a></li>
<li>prevent panic accesing services in extended file by <a href="https://github.com/ndeloof"><code>@​ndeloof</code></a> in <a href="https://redirect.github.com/compose-spec/compose-go/pull/679">compose-spec/compose-go#679</a></li>
<li>Revert &quot;accept dashes in variable names&quot; by <a href="https://github.com/ndeloof"><code>@​ndeloof</code></a> in <a href="https://redirect.github.com/compose-spec/compose-go/pull/680">compose-spec/compose-go#680</a></li>
<li>feat(compose-spec): Add content property for secrets in compose-spec.json by <a href="https://github.com/idsulik"><code>@​idsulik</code></a> in <a href="https://redirect.github.com/compose-spec/compose-go/pull/669">compose-spec/compose-go#669</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/SolanoJason"><code>@​SolanoJason</code></a> made their first contribution in <a href="https://redirect.github.com/compose-spec/compose-go/pull/674">compose-spec/compose-go#674</a></li>
<li><a href="https://github.com/jordanstephens"><code>@​jordanstephens</code></a> made their first contribution in <a href="https://redirect.github.com/compose-spec/compose-go/pull/671">compose-spec/compose-go#671</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/compose-spec/compose-go/compare/v2.1.6...v2.2.0">https://github.com/compose-spec/compose-go/compare/v2.1.6...v2.2.0</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/compose-spec/compose-go/commit/9601b457e8045a643e0e5dbdf94fa1ff812f6317"><code>9601b45</code></a> loaders fixes</li>
<li><a href="https://github.com/compose-spec/compose-go/commit/57698408c832c074c80b12b00575a3c9b1dc5777"><code>5769840</code></a> fix(secrets): Fix secrets environment to content mapping</li>
<li><a href="https://github.com/compose-spec/compose-go/commit/aa1db26a987c000b7842013d6f64f0f294d2caf8"><code>aa1db26</code></a> Revert &quot;accept dashes in variable names&quot;</li>
<li><a href="https://github.com/compose-spec/compose-go/commit/4f02e4279c9b6a6aedf1b824801829e861b40883"><code>4f02e42</code></a> prevent panic accesing services in extended file</li>
<li><a href="https://github.com/compose-spec/compose-go/commit/7b77fc9fd0b12ef7342cc7ae783d3792d12867bf"><code>7b77fc9</code></a> fix fn name typo: GetConfigFiles</li>
<li><a href="https://github.com/compose-spec/compose-go/commit/3e083dbecbf8ba0779612d48fcbad08faec1219c"><code>3e083db</code></a> Update include definition in JSON schema</li>
<li><a href="https://github.com/compose-spec/compose-go/commit/6b514a880b22096a2e91c7e34e89e24f2a235d30"><code>6b514a8</code></a> Support multiple values for extra_hosts</li>
<li><a href="https://github.com/compose-spec/compose-go/commit/e2590ce7b6ac107aa5fd34aac16c62206b5c553e"><code>e2590ce</code></a> long syntax for device mapping</li>
<li>See full diff in <a href="https://github.com/compose-spec/compose-go/compare/v2.1.6...v2.2.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/compose-spec/compose-go/v2&package-manager=go_modules&previous-version=2.1.6&new-version=2.2.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/compose.go b/compose.go
index c87d53b..57e94ba 100644
--- a/compose.go
+++ b/compose.go
@@ -448,7 +448,23 @@ func (g *Generator) buildNixContainer(service types.ServiceConfig, networkMap ma
 	for _, cap := range service.CapDrop {
 		c.ExtraOptions = append(c.ExtraOptions, "--cap-drop="+cap)
 	}
-	for _, device := range service.Devices {
+	for _, d := range service.Devices {
+		device := d.Source
+
+		// Special case: Nvidia CDI devices use short syntax.
+		if strings.HasPrefix(device, "nvidia.com") {
+			c.ExtraOptions = append(c.ExtraOptions, "--device="+device)
+			continue
+		}
+
+		// Otherwise, we default to using the long syntax.
+		// https://docs.docker.com/reference/cli/docker/container/run/#device
+		if d.Target != "" {
+			device += fmt.Sprintf(":%s", d.Target)
+		}
+		if d.Permissions != "" {
+			device += fmt.Sprintf(":%s", d.Permissions)
+		}
 		c.ExtraOptions = append(c.ExtraOptions, "--device="+device)
 	}
 	if service.Runtime != "" {
diff --git a/flake.nix b/flake.nix
index 71c431f..5040c01 100644
--- a/flake.nix
+++ b/flake.nix
@@ -27,7 +27,7 @@
           inherit pname;
           inherit version;
           src = ./.;
-          vendorHash = "sha256-SwJzyOXE23BLoJ+efFuSIhDTMjirEUmBhGGmgrnKhXw=";
+          vendorHash = "sha256-yGBdsej6DjRMWzS13WyqCLaY5M/N9BrMARAM3oHsc+s=";
         };
       }
     );
diff --git a/go.mod b/go.mod
index 481a85e..5b45017 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.21
 
 require (
 	github.com/Masterminds/sprig v2.22.0+incompatible
-	github.com/compose-spec/compose-go/v2 v2.1.6
+	github.com/compose-spec/compose-go/v2 v2.2.0
 )
 
 // Test
diff --git a/go.sum b/go.sum
index 997f374..d350e91 100644
--- a/go.sum
+++ b/go.sum
@@ -4,8 +4,8 @@ github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3Q
 github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
 github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
 github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
-github.com/compose-spec/compose-go/v2 v2.1.6 h1:d0Cs0DffmOwmSzs0YPHwKCskknGq2jfGg4uGowlEpps=
-github.com/compose-spec/compose-go/v2 v2.1.6/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
+github.com/compose-spec/compose-go/v2 v2.2.0 h1:VsQosGhuO+H9wh5laiIiAe4TVd73kQ5NWwmNrdm0HRA=
+github.com/compose-spec/compose-go/v2 v2.2.0/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=


Test patch:
diff --git a/testdata/TestBasic.docker.nix b/testdata/TestBasic.docker.nix
index f7fdd80..5dc4faa 100644
--- a/testdata/TestBasic.docker.nix
+++ b/testdata/TestBasic.docker.nix
@@ -220,7 +220,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=my-torrent-client"
diff --git a/testdata/TestBasic.podman.nix b/testdata/TestBasic.podman.nix
index cd78e98..3373472 100644
--- a/testdata/TestBasic.podman.nix
+++ b/testdata/TestBasic.podman.nix
@@ -219,7 +219,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=transmission"
diff --git a/testdata/TestBasicAutoFormat.docker.nix b/testdata/TestBasicAutoFormat.docker.nix
index 0911821..a514fd1 100644
--- a/testdata/TestBasicAutoFormat.docker.nix
+++ b/testdata/TestBasicAutoFormat.docker.nix
@@ -198,7 +198,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=my-torrent-client"
diff --git a/testdata/TestBasicAutoFormat.podman.nix b/testdata/TestBasicAutoFormat.podman.nix
index d071c41..72a73b4 100644
--- a/testdata/TestBasicAutoFormat.podman.nix
+++ b/testdata/TestBasicAutoFormat.podman.nix
@@ -197,7 +197,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=transmission"
diff --git a/testdata/TestDeployDevices.compose.yml b/testdata/TestDeployDevices.compose.yml
index 414d042..062ef0e 100644
--- a/testdata/TestDeployDevices.compose.yml
+++ b/testdata/TestDeployDevices.compose.yml
@@ -5,6 +5,9 @@ services:
       - label=disable
     devices:
       - nvidia.com/gpu=abc
+      - source: /dev/abc
+        target: /dev/def
+        permissions: rw
     deploy:
       resources:
         reservations:
diff --git a/testdata/TestDeployDevices.docker.nix b/testdata/TestDeployDevices.docker.nix
index be73220..a6039c3 100644
--- a/testdata/TestDeployDevices.docker.nix
+++ b/testdata/TestDeployDevices.docker.nix
@@ -14,6 +14,7 @@
     log-driver = "journald";
     autoStart = false;
     extraOptions = [
+      "--device=/dev/abc:/dev/def:rw"
       "--device=nvidia.com/gpu=abc"
       "--device=nvidia.com/gpu=all"
       "--network-alias=test"
diff --git a/testdata/TestDeployDevices.podman.nix b/testdata/TestDeployDevices.podman.nix
index b07d904..d89de4b 100644
--- a/testdata/TestDeployDevices.podman.nix
+++ b/testdata/TestDeployDevices.podman.nix
@@ -19,6 +19,7 @@
     log-driver = "journald";
     autoStart = false;
     extraOptions = [
+      "--device=/dev/abc:/dev/def:rw"
       "--device=nvidia.com/gpu=abc"
       "--device=nvidia.com/gpu=all"
       "--network-alias=test"
diff --git a/testdata/TestEnvFilesOnly.docker.nix b/testdata/TestEnvFilesOnly.docker.nix
index 456817f..2d2ce9a 100644
--- a/testdata/TestEnvFilesOnly.docker.nix
+++ b/testdata/TestEnvFilesOnly.docker.nix
@@ -199,7 +199,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=my-torrent-client"
diff --git a/testdata/TestEnvFilesOnly.podman.nix b/testdata/TestEnvFilesOnly.podman.nix
index b275efd..90c0b45 100644
--- a/testdata/TestEnvFilesOnly.podman.nix
+++ b/testdata/TestEnvFilesOnly.podman.nix
@@ -198,7 +198,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=transmission"
diff --git a/testdata/TestNoWriteNixSetup.docker.nix b/testdata/TestNoWriteNixSetup.docker.nix
index 60b5d8b..9a7e677 100644
--- a/testdata/TestNoWriteNixSetup.docker.nix
+++ b/testdata/TestNoWriteNixSetup.docker.nix
@@ -218,7 +218,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=my-torrent-client"
diff --git a/testdata/TestNoWriteNixSetup.podman.nix b/testdata/TestNoWriteNixSetup.podman.nix
index 5565dd9..a03520a 100644
--- a/testdata/TestNoWriteNixSetup.podman.nix
+++ b/testdata/TestNoWriteNixSetup.podman.nix
@@ -212,7 +212,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=transmission"
diff --git a/testdata/TestOverrideSystemdStopTimeout.docker.nix b/testdata/TestOverrideSystemdStopTimeout.docker.nix
index d195a86..7a375b8 100644
--- a/testdata/TestOverrideSystemdStopTimeout.docker.nix
+++ b/testdata/TestOverrideSystemdStopTimeout.docker.nix
@@ -227,7 +227,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=my-torrent-client"
diff --git a/testdata/TestOverrideSystemdStopTimeout.podman.nix b/testdata/TestOverrideSystemdStopTimeout.podman.nix
index 0863869..ad8826f 100644
--- a/testdata/TestOverrideSystemdStopTimeout.podman.nix
+++ b/testdata/TestOverrideSystemdStopTimeout.podman.nix
@@ -226,7 +226,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=transmission"
diff --git a/testdata/TestProject.docker.nix b/testdata/TestProject.docker.nix
index bc12be9..72db66d 100644
--- a/testdata/TestProject.docker.nix
+++ b/testdata/TestProject.docker.nix
@@ -224,7 +224,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=my-torrent-client"
diff --git a/testdata/TestProject.podman.nix b/testdata/TestProject.podman.nix
index 3b7fafc..27236a8 100644
--- a/testdata/TestProject.podman.nix
+++ b/testdata/TestProject.podman.nix
@@ -223,7 +223,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=transmission"
diff --git a/testdata/TestRemoveVolumes.docker.nix b/testdata/TestRemoveVolumes.docker.nix
index a3d9d0d..195a4fd 100644
--- a/testdata/TestRemoveVolumes.docker.nix
+++ b/testdata/TestRemoveVolumes.docker.nix
@@ -224,7 +224,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=my-torrent-client"
diff --git a/testdata/TestRemoveVolumes.podman.nix b/testdata/TestRemoveVolumes.podman.nix
index 1f6623c..791f615 100644
--- a/testdata/TestRemoveVolumes.podman.nix
+++ b/testdata/TestRemoveVolumes.podman.nix
@@ -223,7 +223,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=transmission"
diff --git a/testdata/TestSystemdMount.docker.nix b/testdata/TestSystemdMount.docker.nix
index a8d5bcc..f0df9f5 100644
--- a/testdata/TestSystemdMount.docker.nix
+++ b/testdata/TestSystemdMount.docker.nix
@@ -233,7 +233,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=my-torrent-client"
diff --git a/testdata/TestSystemdMount.podman.nix b/testdata/TestSystemdMount.podman.nix
index db15a7c..d8c99fd 100644
--- a/testdata/TestSystemdMount.podman.nix
+++ b/testdata/TestSystemdMount.podman.nix
@@ -232,7 +232,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=transmission"
diff --git a/testdata/TestUpheldBy.docker.nix b/testdata/TestUpheldBy.docker.nix
index bac4310..3e963e9 100644
--- a/testdata/TestUpheldBy.docker.nix
+++ b/testdata/TestUpheldBy.docker.nix
@@ -227,7 +227,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=my-torrent-client"
diff --git a/testdata/TestUpheldBy.podman.nix b/testdata/TestUpheldBy.podman.nix
index 2ba8b81..22966d7 100644
--- a/testdata/TestUpheldBy.podman.nix
+++ b/testdata/TestUpheldBy.podman.nix
@@ -226,7 +226,7 @@
       "--add-host=abc:93.184.216.34"
       "--add-host=abc:::1"
       "--cap-add=NET_ADMIN"
-      "--device=/dev/net/tun:/dev/net/tun"
+      "--device=/dev/net/tun:/dev/net/tun:rwm"
       "--dns=8.8.4.4"
       "--dns=8.8.8.8"
       "--network-alias=transmission"