Unverified Commit eb324777 authored by Jon Seager's avatar Jon Seager
Browse files

nixos/homepage-dashboard: remove unmanaged config support

This has been deprecated since before 24.05 was released
and displaying a warning.

This change means that only "managed", i.e.
Nix-native configurations are supported.
parent 6b178a41
Loading
Loading
Loading
Loading
+41 −71
Original line number Diff line number Diff line
@@ -192,38 +192,10 @@ in
    };
  };

  config =
    let
      # If homepage-dashboard is enabled, but none of the configuration values have been updated,
      # then default to "unmanaged" configuration which is manually updated in
      # var/lib/homepage-dashboard. This is to maintain backwards compatibility, and should be
      # deprecated in a future release.
      managedConfig =
        !(
          cfg.bookmarks == [ ]
          && cfg.customCSS == ""
          && cfg.customJS == ""
          && cfg.docker == { }
          && cfg.kubernetes == { }
          && cfg.services == [ ]
          && cfg.settings == { }
          && cfg.widgets == [ ]
        );

      configDir = if managedConfig then "/etc/homepage-dashboard" else "/var/lib/homepage-dashboard";

      msg =
        "using unmanaged configuration for homepage-dashboard is deprecated and will be removed"
        + " in 24.05. please see the NixOS documentation for `services.homepage-dashboard' and add"
        + " your bookmarks, services, widgets, and other configuration using the options provided.";
    in
    lib.mkIf cfg.enable {
      warnings = lib.optional (!managedConfig) msg;

      environment.etc = lib.mkIf managedConfig {
  config = lib.mkIf cfg.enable {
    environment.etc = {
      "homepage-dashboard/custom.css".text = cfg.customCSS;
      "homepage-dashboard/custom.js".text = cfg.customJS;

      "homepage-dashboard/bookmarks.yaml".source = settingsFormat.generate "bookmarks.yaml" cfg.bookmarks;
      "homepage-dashboard/docker.yaml".source = settingsFormat.generate "docker.yaml" cfg.docker;
      "homepage-dashboard/kubernetes.yaml".source =
@@ -239,30 +211,28 @@ in
      wantedBy = [ "multi-user.target" ];

      environment = {
          HOMEPAGE_CONFIG_DIR = configDir;
        HOMEPAGE_CONFIG_DIR = "/etc/homepage-dashboard";
        NIXPKGS_HOMEPAGE_CACHE_DIR = "/var/cache/homepage-dashboard";
        PORT = toString cfg.listenPort;
          LOG_TARGETS = lib.mkIf managedConfig "stdout";
        LOG_TARGETS = "stdout";
      };

      serviceConfig = {
        Type = "simple";
        DynamicUser = true;
        EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
          StateDirectory = lib.mkIf (!managedConfig) "homepage-dashboard";
        StateDirectory = "homepage-dashboard";
        CacheDirectory = "homepage-dashboard";
        ExecStart = lib.getExe cfg.package;
        Restart = "on-failure";
      };

        enableStrictShellChecks = true;

      preStart = ''
        # Related:
        # * https://github.com/NixOS/nixpkgs/issues/346016 ("homepage-dashboard: cache dir is not cleared upon version upgrade")
        # * https://github.com/gethomepage/homepage/discussions/4560 ("homepage NixOS package does not clear cache on upgrade leaving broken state")
        # * https://github.com/vercel/next.js/discussions/58864 ("Feature Request: Allow configuration of cache dir")
          rm -rf "''${NIXPKGS_HOMEPAGE_CACHE_DIR:?}"/*
        rm -rf "$NIXPKGS_HOMEPAGE_CACHE_DIR"/*
      '';
    };