Skip to content

Commit

Permalink
revert NixOS module; does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiksi committed Nov 8, 2023
1 parent 22f3b65 commit 4410b4b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 96 deletions.
89 changes: 2 additions & 87 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# https://nixos.org/manual/nixos/stable/#sec-writing-modules
# https://nixos.org/manual/nixpkgs/stable/#ssec-language-go
{
description = "minimal configuration for compose2nix";
description = "Convert Docker Compose to Nix";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
Expand All @@ -14,6 +14,7 @@
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = function: nixpkgs.lib.genAttrs supportedSystems (system: function nixpkgs.legacyPackages.${system});
pname = "compose2nix";
owner = "aksiksi";
version = "0.0.1";
in {
# Nix package
Expand All @@ -33,91 +34,5 @@
buildInputs = [ pkgs.go pkgs.gopls ];
};
});

# NixOS module
nixosModules = forAllSystems (pkgs: {
default = { config, lib, pkgs, ... }:
with lib; let
cfg = config.compose2nix;
in {
options.compose2nix = {
# https://nixos.org/manual/nixos/stable/#sec-option-declarations
enable = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc "Enable compose2nixos.";
};
paths = mkOption {
type = types.listOf types.path;
description = lib.mdDoc "One or more paths to Docker Compose files.";
};
runtime = mkOption {
type = types.enum [ "docker" "podman" ];
default = "podman";
description = lib.mdDoc "Container runtime to use.";
};
project = mkOption {
type = types.str;
default = "";
description = lib.mdDoc "Project name. Used as a prefix for all generated resources.";
};
projectSeparator = mkOption {
type = types.str;
default = "_";
description = lib.mdDoc "Defines the prefix between the project and resource name - i.e., [project][sep][resource].";
};
env = mkOption {
type = types.attrsOf types.str;
default = {};
description = lib.mdDoc "Environment to use. Note that these will be merged with environment files, if any.";
};
envFiles = mkOption {
type = types.listOf types.path;
default = [];
description = lib.mdDoc "One or more paths to environment files.";
};
envFilesOnly = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc "Only include env files in the output Nix file. Useful in cases where env variables contain secrets.";
};
serviceInclude = mkOption {
type = types.str;
default = "";
description = lib.mdDoc "Regex pattern for Docker Compose services to include.";
};
autoStart = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc "Auto-start all containers.";
};
output = mkOption {
type = types.anything;
description = lib.mdDoc "Output config.";
};
};
config = {
# runCommandLocal ensures that we always build this derivation on the local machine.
# This allows us to circumvent the Nix binary cache and minimize the time spent outside
# of building the derivation.
# https://nixos.org/manual/nixpkgs/stable/#trivial-builder-runCommandLocal
compose2nix.output = mkIf (cfg.enable) (import pkgs.runCommandLocal "compose2nix" {
env = cfg.env;
buildInputs = [ pkgs.compose2nix ];
} ''
${pkgs.compose2nix}/bin/compose2nix \
-paths='${concatStringsSep "," cfg.paths}' \
-runtime=${cfg.runtime} \
-project=${cfg.project} \
-project_separator='${cfg.projectSeparator}' \
-env_files='${concatStringsSep "," cfg.envFiles}' \
-env_files_only=${cfg.envFilesOnly} \
-service_include='${cfg.serviceInclude}' \
-auto_start=${cfg.autoStart} \
-output=$out
'');
};
};
});
};
}
2 changes: 1 addition & 1 deletion templates/container.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ virtualisation.oci-containers.containers."{{.Name}}" = {
{{- end}}

{{- if .LogDriver}}
logDriver = "{{.LogDriver}}";
log-driver = "{{.LogDriver}}";
{{- end}}

{{- if not .AutoStart}}
Expand Down
8 changes: 0 additions & 8 deletions templates/main.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,4 @@
{{execTemplate "volume.nix.tmpl" . | indent 2}}
{{- end}}
{{- end}}

# Scripts
up = writeShellScript "compose-{{.Project.With "up"}}.sh" ''
echo "TODO: Create resources."
'';
down = writeShellScript "compose-{{.Project.With "down"}}.sh" ''
echo "TODO: Remove resources."
'';
}

0 comments on commit 4410b4b

Please sign in to comment.