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 cab0207
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
16 changes: 12 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@
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;
default = [];
description = lib.mdDoc "One or more paths to Docker Compose files.";
};
runtime = mkOption {
Expand Down Expand Up @@ -87,13 +91,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 != []) {
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
output = pkgs.runCommandLocal "run-compose2nix" {
compose2nix.output = mkIf (cfg.enable) (import pkgs.runCommandLocal "compose2nix" {
env = cfg.env;
buildInputs = [ pkgs.compose2nix ];
} ''
Expand All @@ -107,7 +115,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 cab0207

Please sign in to comment.