Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify how to define full (non-useHostStore) image contents? #259

Open
srd424 opened this issue Aug 13, 2024 · 2 comments
Open

Clarify how to define full (non-useHostStore) image contents? #259

srd424 opened this issue Aug 13, 2024 · 2 comments

Comments

@srd424
Copy link

srd424 commented Aug 13, 2024

Dipping my toes into arion today and already confused! The minimal example works with useHostStore = true, but without it the generated image does not contain either python or the nix manual:

webapp-webserver-1[402022]: sh: line 1: cd: /nix/store/fc2i53vzn7j3lp5lidj4hm9b9cx9rn99-nix-2.18.5-doc/share/doc/nix/manual: No such file or directory
webapp-webserver-1[402022]: sh: line 2: /nix/store/pfv4raslwhi3101k342752v65zxkwrxq-python3-3.11.9/bin/python: No such file or directory

The flake example explicitly sets image.contents but that doesn't seem to be documented, and I'm unclear exactly what is needed - at the very least it looks like it might involve a fair amount of boilerplate?

@srd424
Copy link
Author

srd424 commented Aug 14, 2024

The following seems to more or less work, not sure why I need to use image.command instead of service.command. Perhaps in the "non-full NixOS" case service.command could be automatically written into the store to allow dependency resolution to work for image building? (I'm not going to pretend my Nix skills are up to crafting a patch for that..)

{ pkgs, ... }:
let
  cmd = pkgs.writeScriptBin "start" ''
#!${pkgs.bash}/bin/bash
cd "$WEB_ROOT"
${pkgs.python3}/bin/python -m http.server
'';
in {
  project.name = "webapp";
  services = {

    webserver = {
      image.enableRecommendedContents = true;
#      service.useHostStore = true;
      image.contents = [ cmd ];
      image.command = [ "${cmd}/bin/start" ];
#      service.command = [ "${cmd}/bin/start" ];
      service.ports = [
        "8000:8000" # host:container
      ];
      service.environment.WEB_ROOT = "${pkgs.nix.doc}/share/doc/nix/manual";
      service.stop_signal = "SIGINT";
    };
  };
}

@srd424
Copy link
Author

srd424 commented Aug 14, 2024

Oh, this is simpler:

{ pkgs, ... }:
{
  project.name = "webapp";
  services = {

    webserver = {
      image.enableRecommendedContents = true;
#      service.useHostStore = true;
      image.command = [ "sh" "-c" ''
                  cd "${pkgs.nix.doc}/share/doc/nix/manual"
                  ${pkgs.python3}/bin/python -m http.server
                '' ];
      service.ports = [
        "8000:8000" # host:container
      ];
#      service.environment.WEB_ROOT = "${pkgs.nix.doc}/share/doc/nix/manual";
      service.stop_signal = "SIGINT";
    };
  };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant