hercules-ci / arion

Run docker-compose with help from Nix/NixOS
Apache License 2.0
622 stars 48 forks source link

passing non-pkgs stuff like flake `inputs` to container #247

Open KiaraGrouwstra opened 2 months ago

KiaraGrouwstra commented 2 months ago

given a flake-based way of working, it would be nice to pass more stuff to containerized machines than just pkgs, such as inputs, so as to also grab e.g. nix modules. while i've found one can technically smuggle stuff thru what arion presumes to be just pkgs, i... am not sure i'm particularly proud of that idea. would anyone perhaps have found a nicer way to do this?

KiaraGrouwstra commented 2 months ago

bit hacky, but i got this to work using a few different approaches:

# flake.nix

  outputs = { nixpkgs, ... }@inputs: let
    pkgs = nixpkgs.legacyPackages.x86_64-linux;
  in {
    inherit inputs pkgs;
  };

then either separating them but having arion confusingly call the wrapper pkgs:

# arion-pkgs.nix
let
  flake = builtins.getFlake (toString ./.);
  inherit (flake) inputs pkgs;
in
  {
    # bits i wanna pass to my containers
    inherit inputs pkgs;
    # stuff arion wants to see me return
    inherit (pkgs) lib writeText nix nixos path dockerTools closureInfo runCommand;
  }
# arion-compose.nix
{
  # smuggling in `inputs` thru `pkgs`: https://github.com/hercules-ci/arion/issues/247
  pkgs,
  ...
}:
{
  project.name = "nixos container";
  services.webserver = {
    nixos = {
      useSystemd = true;
      configuration = import ./servers/manual/configuration.nix pkgs;
    };
    service = ...;
  };
}

or instead hide your other stuff like inputs in pkgs:

# arion-pkgs.nix

let
  flake = builtins.getFlake (toString ./.);
  inherit (flake) inputs pkgs;
in
  pkgs // { inherit inputs; }
# arion-compose.nix
{
  # smuggling in `inputs` thru `pkgs`: https://github.com/hercules-ci/arion/issues/247
  pkgs,
  ...
}:
let
  inherit (pkgs) lib inputs;
in
{
  project.name = "nixos container";
  services.webserver = {
    nixos = {
      useSystemd = true;
      configuration = import ./servers/manual/configuration.nix { inherit lib pkgs inputs; };
    };
    service = ...;
  };
}