Skip to content

Commit

Permalink
import attrset via runCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiksi committed Nov 8, 2023
1 parent f681ae3 commit c7fd6f1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 30 deletions.
37 changes: 17 additions & 20 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
# https://nixos.org/manual/nixos/stable/#sec-option-declarations
paths = mkOption {
type = types.listOf types.path;
default = [];
description = lib.mdDoc "One or more paths to Docker Compose files.";
};
runtime = mkOption {
Expand Down Expand Up @@ -88,27 +87,25 @@
description = lib.mdDoc "Auto-start all containers.";
};
};
config.compose2nix = mkIf (cfg.paths != []) {
# 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
output = pkgs.runCommandLocal "run-compose2nix" {
# 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
config = mkIf (cfg.paths != []) (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
'';
};
} ''
${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
'');
};
});
};
Expand Down
2 changes: 0 additions & 2 deletions templates/main.nix.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{{- $runtime := .Runtime | printf "%s" -}}
{ pkgs, ... }:

{
# Runtime
virtualisation.{{$runtime}} = {
Expand Down
2 changes: 0 additions & 2 deletions testdata/TestDocker_WithProject_out.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{ pkgs, ... }:

{
# Runtime
virtualisation.docker = {
Expand Down
2 changes: 0 additions & 2 deletions testdata/TestDocker_out.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{ pkgs, ... }:

{
# Runtime
virtualisation.docker = {
Expand Down
2 changes: 0 additions & 2 deletions testdata/TestPodman_WithProject_out.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{ pkgs, ... }:

{
# Runtime
virtualisation.podman = {
Expand Down
2 changes: 0 additions & 2 deletions testdata/TestPodman_out.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{ pkgs, ... }:

{
# Runtime
virtualisation.podman = {
Expand Down

0 comments on commit c7fd6f1

Please sign in to comment.