From c7fd6f104f7cd5cff00657850e48a43fddc5f1f1 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 | 37 ++++++++++++------------- 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, 17 insertions(+), 30 deletions(-) diff --git a/flake.nix b/flake.nix index e33bd58..76cc97f 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,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 + ''); }; }); }; 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 = {