Skip to content

Commit

Permalink
use runCommandLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiksi committed Nov 7, 2023
1 parent 5b2947c commit 3ca377c
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# References:
# https://blog.lenny.ninja/part-1-quickly-packaging-services-using-nix-flakes.html
# https://ayats.org/blog/no-flake-utils/
# https://ryantm.github.io/nixpkgs/builders/trivial-builders/#trivial-builder-runCommand
# https://nixpkgs-manual-sphinx-markedown-example.netlify.app/development/writing-modules.xml.html#structure-of-nixos-modules
# https://nixos.org/manual/nixos/stable/#sec-writing-modules
# https://nixos.org/manual/nixpkgs/stable/#ssec-language-go
{
description = "minimal configuration for compose2nix";

Expand Down Expand Up @@ -44,6 +44,7 @@
# 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,24 +88,26 @@
description = lib.mdDoc "Auto-start all containers.";
};
};
configs = mkIf (cfg.paths != []) {
compose2nix = {
output = pkgs.runCommand "run-compose2nix" {
buildInputs = [ pkgs.compose2nix ];
env = cfg.env;
} ''
${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
'';
};
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;
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
'';
};
};
});
Expand Down

0 comments on commit 3ca377c

Please sign in to comment.