{ lib, pkgs, ... }:

{
  services.glance.enable = true;

  nmt.script = lib.mkMerge [
    ''
      configFile=home-files/.config/glance/glance.yml
      assertFileContent $configFile ${./glance-default-config.yml}
    ''
    (lib.mkIf pkgs.stdenv.hostPlatform.isLinux ''
      serviceFile=home-files/.config/systemd/user/glance.service
      serviceFile=$(normalizeStorePaths $serviceFile)
      assertFileContent $serviceFile ${./glance.service}
    '')
    (lib.mkIf pkgs.stdenv.hostPlatform.isDarwin ''
      serviceFile=LaunchAgents/org.nix-community.home.glance.plist
      serviceFile=$(normalizeStorePaths $serviceFile)
      assertFileExists "$serviceFile"
      assertFileContent "$serviceFile" ${./glance.plist}

      domainFile=LaunchAgentDomains/org.nix-community.home.glance.domain
      assertFileContent "$domainFile" ${builtins.toFile "expected-domain" "user\n"}
      assertFileContains activate 'domain="user/$(id -u)"'
      assertFileContains activate 'launchctl kickstart -k "$domain/org.nix-community.home.glance"'
    '')
  ];
}
