Skip to content

Commit

Permalink
rename to compose2nix - full circle...
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiksi committed Nov 7, 2023
1 parent 79903ca commit 0c78ff2
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
mkdir -p bin/ && go build -o bin/ ./cmd/nix-compose
mkdir -p bin/ && go build -o bin/ ./cmd/compose2nix

test:
go test -v
Expand Down
19 changes: 8 additions & 11 deletions cmd/nix-compose/main.go → cmd/compose2nix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
"strings"
"time"

nixcompose "github.com/aksiksi/nix-compose"
"github.com/aksiksi/compose2nix"
)

var paths = flag.String("paths", "", "paths to Compose files")
var envFiles = flag.String("env_files", "", "paths to .env files")
var envFilesOnly = flag.Bool("env_files_only", false, "only use env files in the NixOS container definitions")
var output = flag.String("output", "", "path to output Nix file")
var project = flag.String("project", "", "project name used as a prefix for generated resources")
var projectSeparator = flag.String("project_separator", nixcompose.DefaultProjectSeparator, "seperator for project prefix")
var projectSeparator = flag.String("project_separator", compose2nix.DefaultProjectSeparator, "seperator for project prefix")
var serviceInclude = flag.String("service_include", "", "regex pattern for services to include")
var autoStart = flag.Bool("auto_start", true, "control auto-start setting for containers")
var runtime = flag.String("runtime", "podman", `"podman" or "docker"`)
Expand All @@ -37,11 +37,11 @@ func main() {
paths := strings.Split(*paths, ",")
envFiles := strings.Split(*envFiles, ",")

var containerRuntime nixcompose.ContainerRuntime
var containerRuntime compose2nix.ContainerRuntime
if *runtime == "podman" {
containerRuntime = nixcompose.ContainerRuntimePodman
containerRuntime = compose2nix.ContainerRuntimePodman
} else if *runtime == "docker" {
containerRuntime = nixcompose.ContainerRuntimeDocker
containerRuntime = compose2nix.ContainerRuntimeDocker
} else {
log.Fatalf("Invalid --runtime: %q", *runtime)
}
Expand All @@ -56,8 +56,8 @@ func main() {
}

start := time.Now()
g := nixcompose.Generator{
Project: nixcompose.NewProjectWithSeparator(*project, *projectSeparator),
g := compose2nix.Generator{
Project: compose2nix.NewProjectWithSeparator(*project, *projectSeparator),
Runtime: containerRuntime,
Paths: paths,
EnvFiles: envFiles,
Expand All @@ -73,12 +73,9 @@ func main() {
fmt.Printf("Generated NixOS config in %v\n", time.Since(start))

if *output != "" {
// Create the output directory if it does not exist.
dir := path.Dir(*output)
if _, err := os.Stat(dir); err != nil {
if err := os.MkdirAll(dir, 0755); err != nil {
log.Fatal(err)
}
log.Fatalf("Directory %q does not exist", dir)
}
if err := os.WriteFile(*output, []byte(containerConfig.String()), 0644); err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion compose.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nixcompose
package compose2nix

import (
"cmp"
Expand Down
23 changes: 12 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# https://ryantm.github.io/nixpkgs/builders/trivial-builders/#trivial-builder-runCommand
# https://nixpkgs-manual-sphinx-markedown-example.netlify.app/development/writing-modules.xml.html#structure-of-nixos-modules
{
description = "minimal configuration for nix-compose";
description = "minimal configuration for compose2nix";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
Expand All @@ -13,11 +13,12 @@
outputs = { self, nixpkgs, ... }: let
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = function: nixpkgs.lib.genAttrs supportedSystems (system: function nixpkgs.legacyPackages.${system});
pname = "nix-compose";
version = "v0.0.1";
pname = "compose2nix";
version = "0.0.1";
in {
# Nix package
packages = forAllSystems (pkgs: {
# TODO(aksiksi): Pull from GitHub.
default = pkgs.buildGoModule {
inherit pname;
inherit version;
Expand All @@ -37,11 +38,11 @@
nixosModules = forAllSystems (pkgs: {
default = { config, lib, pkgs, ... }:
with lib; let
cfg = config.nix-compose;
cfg = config.compose2nix;
in {
options.nix-compose = {
options.compose2nix = {
# https://nixos.org/manual/nixos/stable/#sec-option-declarations
enable = mkEnableOption "nix-compose";
enable = mkEnableOption "compose2nix";
paths = mkOption {
type = types.listOf types.pathInStore;
description = lib.mdDoc "One or more paths to Docker Compose files.";
Expand Down Expand Up @@ -88,12 +89,12 @@
};
};
configs = mkIf cfg.enable {
nix-compose = {
output = pkgs.runCommand "run-nix-compose" {
buildInputs = [ pkgs.nix-compose ];
compose2nix = {
output = pkgs.runCommand "run-compose2nix" {
buildInputs = [ pkgs.compose2nix ];
env = cfg.env;
} ''
${pkgs.nix-compose}/bin/nix-compose \
${pkgs.compose2nix}/bin/compose2nix \
-paths='${concatStringsSep "," cfg.paths}' \
-runtime=${cfg.runtime} \
-project=${cfg.project} \
Expand All @@ -102,7 +103,7 @@
-env_files_only=${cfg.envFilesOnly} \
-auto_start=${cfg.autoStart} \
-service_include='${cfg.serviceInclude}' \
-output=$out/output.nix
-output=$out
'';
};
};
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/aksiksi/nix-compose
module github.com/aksiksi/compose2nix

go 1.21

Expand Down
2 changes: 1 addition & 1 deletion helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nixcompose
package compose2nix

import (
"bufio"
Expand Down
2 changes: 1 addition & 1 deletion nix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nixcompose
package compose2nix

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion nix_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nixcompose
package compose2nix

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion template.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nixcompose
package compose2nix

import (
"embed"
Expand Down

0 comments on commit 0c78ff2

Please sign in to comment.