-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert Compose restart policies to systemd configs
- Loading branch information
Showing
8 changed files
with
289 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package nixose | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
"strings" | ||
"text/template" | ||
|
||
"github.com/Masterminds/sprig" | ||
) | ||
|
||
//go:embed templates/*.tmpl | ||
var templateFS embed.FS | ||
var nixTemplates = template.New("nix").Funcs(sprig.FuncMap()).Funcs(funcMap) | ||
|
||
func labelMapToLabelFlags(l map[string]string) []string { | ||
// https://docs.docker.com/engine/reference/commandline/run/#label | ||
// https://docs.podman.io/en/latest/markdown/podman-run.1.html#label-l-key-value | ||
labels := mapToKeyValArray(l) | ||
for i, label := range labels { | ||
labels[i] = fmt.Sprintf("--label=%s", label) | ||
} | ||
return labels | ||
} | ||
|
||
func execTemplate(t *template.Template) func(string, any) (string, error) { | ||
return func(name string, v any) (string, error) { | ||
var s strings.Builder | ||
err := t.ExecuteTemplate(&s, name, v) | ||
return s.String(), err | ||
} | ||
} | ||
|
||
func derefInt(v *int) int { | ||
return *v | ||
} | ||
|
||
func toNixValue(v any) any { | ||
switch v.(type) { | ||
case string: | ||
return fmt.Sprintf("%q", v) | ||
default: | ||
return v | ||
} | ||
} | ||
|
||
var funcMap template.FuncMap = template.FuncMap{ | ||
"derefInt": derefInt, | ||
"labelMapToLabelFlags": labelMapToLabelFlags, | ||
"mapToKeyValArray": mapToKeyValArray, | ||
"toNixValue": toNixValue, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.