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 722a1c3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
19 changes: 11 additions & 8 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 @@ -87,13 +86,17 @@
default = true;
description = lib.mdDoc "Auto-start all containers.";
};
output = mkOption {
type = types.anything;
description = lib.mdDoc "Output config.";
};
};
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 = {
compose2nix.output = mkIf (cfg.paths != []) (import pkgs.runCommandLocal "compose2nix" {
env = cfg.env;
buildInputs = [ pkgs.compose2nix ];
} ''
Expand All @@ -107,7 +110,7 @@
-service_include='${cfg.serviceInclude}' \
-auto_start=${cfg.autoStart} \
-output=$out
'';
'');
};
};
});
Expand Down
2 changes: 1 addition & 1 deletion templates/main.nix.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- $runtime := .Runtime | printf "%s" -}}
{ pkgs, ... }:
{ ... }:

{
# Runtime
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestDocker_WithProject_out.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, ... }:
{ ... }:

{
# Runtime
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestDocker_out.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, ... }:
{ ... }:

{
# Runtime
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestPodman_WithProject_out.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, ... }:
{ ... }:

{
# Runtime
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestPodman_out.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, ... }:
{ ... }:

{
# Runtime
Expand Down

0 comments on commit 722a1c3

Please sign in to comment.