From b3d5e5072b958f80aea73f50c8595f574764c8a5 Mon Sep 17 00:00:00 2001 From: Assil Ksiksi Date: Tue, 7 Nov 2023 20:58:44 -0500 Subject: [PATCH] import attrset via runCommand --- flake.nix | 43 ++++++++++++++----------- templates/main.nix.tmpl | 2 -- testdata/TestDocker_WithProject_out.nix | 2 -- testdata/TestDocker_out.nix | 2 -- testdata/TestPodman_WithProject_out.nix | 2 -- testdata/TestPodman_out.nix | 2 -- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/flake.nix b/flake.nix index e33bd58..4c7fb4b 100644 --- a/flake.nix +++ b/flake.nix @@ -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 { @@ -88,27 +87,35 @@ 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" { - env = cfg.env; + # 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 = let + env = cfg.env; + paths = cfg.paths; + runtime = cfg.runtime; + project = cfg.project; + projectSeparator = cfg.projectSeparator; + envFilesOnly = cfg.envFilesOnly; + serviceInclude = cfg.serviceInclude; + autoStart = cfg.autoStart; + in + import (pkgs.runCommandLocal "compose2nix" { + env = 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} \ + -paths='${concatStringsSep "," paths}' \ + -runtime=${runtime} \ + -project=${project} \ + -project_separator='${projectSeparator}' \ + -env_files='${concatStringsSep "," envFiles}' \ + -env_files_only=${envFilesOnly} \ + -service_include='${serviceInclude}' \ + -auto_start=${autoStart} \ -output=$out - ''; - }; + ''); }; }); }; diff --git a/templates/main.nix.tmpl b/templates/main.nix.tmpl index 7499347..0a2e25a 100644 --- a/templates/main.nix.tmpl +++ b/templates/main.nix.tmpl @@ -1,6 +1,4 @@ {{- $runtime := .Runtime | printf "%s" -}} -{ pkgs, ... }: - { # Runtime virtualisation.{{$runtime}} = { diff --git a/testdata/TestDocker_WithProject_out.nix b/testdata/TestDocker_WithProject_out.nix index b0b8c2c..a669fa2 100644 --- a/testdata/TestDocker_WithProject_out.nix +++ b/testdata/TestDocker_WithProject_out.nix @@ -1,5 +1,3 @@ -{ pkgs, ... }: - { # Runtime virtualisation.docker = { diff --git a/testdata/TestDocker_out.nix b/testdata/TestDocker_out.nix index fcb1383..0cb299f 100644 --- a/testdata/TestDocker_out.nix +++ b/testdata/TestDocker_out.nix @@ -1,5 +1,3 @@ -{ pkgs, ... }: - { # Runtime virtualisation.docker = { diff --git a/testdata/TestPodman_WithProject_out.nix b/testdata/TestPodman_WithProject_out.nix index 4fc7dab..45726bb 100644 --- a/testdata/TestPodman_WithProject_out.nix +++ b/testdata/TestPodman_WithProject_out.nix @@ -1,5 +1,3 @@ -{ pkgs, ... }: - { # Runtime virtualisation.podman = { diff --git a/testdata/TestPodman_out.nix b/testdata/TestPodman_out.nix index da69ab9..ccfdb3d 100644 --- a/testdata/TestPodman_out.nix +++ b/testdata/TestPodman_out.nix @@ -1,5 +1,3 @@ -{ pkgs, ... }: - { # Runtime virtualisation.podman = {