Unverified Commit 56dd7544 authored by isabel's avatar isabel Committed by GitHub
Browse files

nixosTests.dashy: init (#443896)

parents 32886f1e a061c6c3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -430,6 +430,7 @@ in
  cyrus-imap = runTest ./cyrus-imap.nix;
  dae = runTest ./dae.nix;
  darling-dmg = runTest ./darling-dmg.nix;
  dashy = runTest ./web-apps/dashy.nix;
  davis = runTest ./davis.nix;
  db-rest = runTest ./db-rest.nix;
  dconf = runTest ./dconf.nix;
+75 −0
Original line number Diff line number Diff line
{ pkgs, lib, ... }:
let

  customSettings = {
    pageInfo = {
      title = "My Custom Dashy Title";
    };

    sections = [
      {
        name = "My Section";
        items = [
          {
            name = "NixOS";
            url = "https://nixos.org";
          }
        ];
      }
    ];
  };

  customSettingsYaml = (pkgs.formats.yaml_1_1 { }).generate "custom-conf.yaml" customSettings;
in
{
  name = "dashy";
  meta.maintainers = [ lib.maintainers.therealgramdalf ];

  defaults =
    { config, ... }:
    {
      services.dashy = {
        enable = true;
        virtualHost = {
          enableNginx = true;
          domain = "dashy.local";
        };
      };

      networking.extraHosts = "127.0.0.1 dashy.local";

      services.nginx.virtualHosts."${config.services.dashy.virtualHost.domain}".listen = [
        {
          addr = "127.0.0.1";
          port = 80;
        }
      ];
    };
  nodes = {
    machine = { };

    machine-custom = {
      services.dashy.settings = customSettings;
    };
  };

  testScript = ''
    start_all()
    machine.wait_for_unit("nginx.service")
    machine.wait_for_open_port(80)

    actual = machine.succeed("curl -v --stderr - http://dashy.local/", timeout=10)
    expected = "<title>Dashy</title>"
    assert expected in actual, \
      f"unexpected reply from Dashy, expected: '{expected}' got: '{actual}'"

    machine_custom.wait_for_unit("nginx.service")
    machine_custom.wait_for_open_port(80)

    actual_custom = machine_custom.succeed("curl -s --stderr - http://dashy.local/conf.yml", timeout=10).strip()
    expected_custom = machine_custom.succeed("cat ${customSettingsYaml}").strip()

    assert expected_custom == actual_custom, \
      f"unexpected reply from Dashy, expected: '{expected_custom}' got: '{actual_custom}'"
  '';
}
+11 −5
Original line number Diff line number Diff line
@@ -8,9 +8,10 @@
  yarn,
  fixup-yarn-lock,
  prefetch-yarn-deps,
  nixosTests,
  nodejs_20,
  nodejs-slim_20,
  yq-go,
  remarshal_0_17,
  settings ? { },
}:
stdenv.mkDerivation (finalAttrs: {
@@ -26,15 +27,20 @@ stdenv.mkDerivation (finalAttrs: {
    yarnLock = finalAttrs.src + "/yarn.lock";
    hash = "sha256-r36w3Cz/V7E/xPYYpvfQsdk2QXfCVDYE9OxiFNyKP2s=";
  };

  passthru.tests = {
    dashy = nixosTests.dashy;
  };

  # - If no settings are passed, use the default config provided by upstream
  # - Despite JSON being valid YAML (and the JSON passing the config validator),
  # there seem to be some issues with JSON in the final build - potentially due to
  # the way the client parses things
  # - Instead, we use `yq-go` to convert it to yaml
  # - Instead, we use `remarshal` to convert it to yaml
  # Config validation needs to happen after yarnConfigHook, since it's what sets the yarn offline cache
  preBuild = lib.optional (settings != { }) ''
    echo "Writing settings override..."
    yq --output-format yml '${builtins.toFile "conf.json" ''${builtins.toJSON settings}''}' > user-data/conf.yml
    json2yaml '${builtins.toFile "conf.json" (builtins.toJSON settings)}' user-data/conf.yml
    yarn validate-config --offline
  '';
  installPhase = ''
@@ -59,8 +65,8 @@ stdenv.mkDerivation (finalAttrs: {
    })
    yarnBuildHook
    nodejs_20
    # For yaml parsing
    yq-go
    # For yaml conversion
    remarshal_0_17
  ];
  doDist = false;
  meta = {