Skip to content

Commit c558fc0

Browse files
authored
homepage-dashboard: 0.10.9 -> 1.0.4 (NixOS#391235)
2 parents 6a95107 + 60ec94a commit c558fc0

File tree

7 files changed

+251
-163
lines changed

7 files changed

+251
-163
lines changed

nixos/modules/services/misc/homepage-dashboard.nix

Lines changed: 41 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -192,82 +192,52 @@ in
192192
};
193193
};
194194

195-
config =
196-
let
197-
# If homepage-dashboard is enabled, but none of the configuration values have been updated,
198-
# then default to "unmanaged" configuration which is manually updated in
199-
# var/lib/homepage-dashboard. This is to maintain backwards compatibility, and should be
200-
# deprecated in a future release.
201-
managedConfig =
202-
!(
203-
cfg.bookmarks == [ ]
204-
&& cfg.customCSS == ""
205-
&& cfg.customJS == ""
206-
&& cfg.docker == { }
207-
&& cfg.kubernetes == { }
208-
&& cfg.services == [ ]
209-
&& cfg.settings == { }
210-
&& cfg.widgets == [ ]
211-
);
212-
213-
configDir = if managedConfig then "/etc/homepage-dashboard" else "/var/lib/homepage-dashboard";
214-
215-
msg =
216-
"using unmanaged configuration for homepage-dashboard is deprecated and will be removed"
217-
+ " in 24.05. please see the NixOS documentation for `services.homepage-dashboard' and add"
218-
+ " your bookmarks, services, widgets, and other configuration using the options provided.";
219-
in
220-
lib.mkIf cfg.enable {
221-
warnings = lib.optional (!managedConfig) msg;
195+
config = lib.mkIf cfg.enable {
196+
environment.etc = {
197+
"homepage-dashboard/custom.css".text = cfg.customCSS;
198+
"homepage-dashboard/custom.js".text = cfg.customJS;
199+
"homepage-dashboard/bookmarks.yaml".source = settingsFormat.generate "bookmarks.yaml" cfg.bookmarks;
200+
"homepage-dashboard/docker.yaml".source = settingsFormat.generate "docker.yaml" cfg.docker;
201+
"homepage-dashboard/kubernetes.yaml".source =
202+
settingsFormat.generate "kubernetes.yaml" cfg.kubernetes;
203+
"homepage-dashboard/services.yaml".source = settingsFormat.generate "services.yaml" cfg.services;
204+
"homepage-dashboard/settings.yaml".source = settingsFormat.generate "settings.yaml" cfg.settings;
205+
"homepage-dashboard/widgets.yaml".source = settingsFormat.generate "widgets.yaml" cfg.widgets;
206+
};
222207

223-
environment.etc = lib.mkIf managedConfig {
224-
"homepage-dashboard/custom.css".text = cfg.customCSS;
225-
"homepage-dashboard/custom.js".text = cfg.customJS;
208+
systemd.services.homepage-dashboard = {
209+
description = "Homepage Dashboard";
210+
after = [ "network.target" ];
211+
wantedBy = [ "multi-user.target" ];
226212

227-
"homepage-dashboard/bookmarks.yaml".source = settingsFormat.generate "bookmarks.yaml" cfg.bookmarks;
228-
"homepage-dashboard/docker.yaml".source = settingsFormat.generate "docker.yaml" cfg.docker;
229-
"homepage-dashboard/kubernetes.yaml".source =
230-
settingsFormat.generate "kubernetes.yaml" cfg.kubernetes;
231-
"homepage-dashboard/services.yaml".source = settingsFormat.generate "services.yaml" cfg.services;
232-
"homepage-dashboard/settings.yaml".source = settingsFormat.generate "settings.yaml" cfg.settings;
233-
"homepage-dashboard/widgets.yaml".source = settingsFormat.generate "widgets.yaml" cfg.widgets;
213+
environment = {
214+
HOMEPAGE_CONFIG_DIR = "/etc/homepage-dashboard";
215+
NIXPKGS_HOMEPAGE_CACHE_DIR = "/var/cache/homepage-dashboard";
216+
PORT = toString cfg.listenPort;
217+
LOG_TARGETS = "stdout";
234218
};
235219

236-
systemd.services.homepage-dashboard = {
237-
description = "Homepage Dashboard";
238-
after = [ "network.target" ];
239-
wantedBy = [ "multi-user.target" ];
240-
241-
environment = {
242-
HOMEPAGE_CONFIG_DIR = configDir;
243-
NIXPKGS_HOMEPAGE_CACHE_DIR = "/var/cache/homepage-dashboard";
244-
PORT = toString cfg.listenPort;
245-
LOG_TARGETS = lib.mkIf managedConfig "stdout";
246-
};
247-
248-
serviceConfig = {
249-
Type = "simple";
250-
DynamicUser = true;
251-
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
252-
StateDirectory = lib.mkIf (!managedConfig) "homepage-dashboard";
253-
CacheDirectory = "homepage-dashboard";
254-
ExecStart = lib.getExe cfg.package;
255-
Restart = "on-failure";
256-
};
257-
258-
enableStrictShellChecks = true;
259-
260-
preStart = ''
261-
# Related:
262-
# * https://github.com/NixOS/nixpkgs/issues/346016 ("homepage-dashboard: cache dir is not cleared upon version upgrade")
263-
# * https://github.com/gethomepage/homepage/discussions/4560 ("homepage NixOS package does not clear cache on upgrade leaving broken state")
264-
# * https://github.com/vercel/next.js/discussions/58864 ("Feature Request: Allow configuration of cache dir")
265-
rm -rf "''${NIXPKGS_HOMEPAGE_CACHE_DIR:?}"/*
266-
'';
220+
serviceConfig = {
221+
Type = "simple";
222+
DynamicUser = true;
223+
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
224+
StateDirectory = "homepage-dashboard";
225+
CacheDirectory = "homepage-dashboard";
226+
ExecStart = lib.getExe cfg.package;
227+
Restart = "on-failure";
267228
};
268229

269-
networking.firewall = lib.mkIf cfg.openFirewall {
270-
allowedTCPPorts = [ cfg.listenPort ];
271-
};
230+
# Related:
231+
# * https://github.com/NixOS/nixpkgs/issues/346016 ("homepage-dashboard: cache dir is not cleared upon version upgrade")
232+
# * https://github.com/gethomepage/homepage/discussions/4560 ("homepage NixOS package does not clear cache on upgrade leaving broken state")
233+
# * https://github.com/vercel/next.js/discussions/58864 ("Feature Request: Allow configuration of cache dir")
234+
preStart = ''
235+
rm -rf "$NIXPKGS_HOMEPAGE_CACHE_DIR"/*
236+
'';
272237
};
238+
239+
networking.firewall = lib.mkIf cfg.openFirewall {
240+
allowedTCPPorts = [ cfg.listenPort ];
241+
};
242+
};
273243
}

nixos/tests/homepage-dashboard.nix

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,25 @@ import ./make-test-python.nix (
44
name = "homepage-dashboard";
55
meta.maintainers = with lib.maintainers; [ jnsgruk ];
66

7-
nodes.unmanaged_conf =
8-
{ pkgs, ... }:
9-
{
10-
services.homepage-dashboard.enable = true;
11-
};
12-
13-
nodes.managed_conf =
14-
{ pkgs, ... }:
15-
{
16-
services.homepage-dashboard = {
17-
enable = true;
18-
settings.title = "test title rodUsEagid"; # something random/unique
19-
};
7+
nodes.machine = _: {
8+
services.homepage-dashboard = {
9+
enable = true;
10+
settings.title = "test title rodUsEagid"; # something random/unique
2011
};
12+
};
2113

2214
testScript = ''
23-
# Ensure the services are started on unmanaged machine
24-
unmanaged_conf.wait_for_unit("homepage-dashboard.service")
25-
unmanaged_conf.wait_for_open_port(8082)
26-
unmanaged_conf.succeed("curl --fail http://localhost:8082/")
27-
28-
# Ensure that /etc/homepage-dashboard doesn't exist, and boilerplate
29-
# configs are copied into place.
30-
unmanaged_conf.fail("test -d /etc/homepage-dashboard")
31-
unmanaged_conf.succeed("test -f /var/lib/private/homepage-dashboard/settings.yaml")
32-
3315
# Ensure the services are started on managed machine
34-
managed_conf.wait_for_unit("homepage-dashboard.service")
35-
managed_conf.wait_for_open_port(8082)
36-
managed_conf.succeed("curl --fail http://localhost:8082/")
16+
machine.wait_for_unit("homepage-dashboard.service")
17+
machine.wait_for_open_port(8082)
18+
machine.succeed("curl --fail http://localhost:8082/")
3719
38-
# Ensure /etc/homepage-dashboard is created and unmanaged conf location isn't.
39-
managed_conf.succeed("test -d /etc/homepage-dashboard")
40-
managed_conf.fail("test -f /var/lib/private/homepage-dashboard/settings.yaml")
20+
# Ensure /etc/homepage-dashboard is created.
21+
machine.succeed("test -d /etc/homepage-dashboard")
4122
4223
# Ensure that we see the custom title *only in the managed config*
43-
page = managed_conf.succeed("curl --fail http://localhost:8082/")
24+
page = machine.succeed("curl --fail http://localhost:8082/")
4425
assert "test title rodUsEagid" in page, "Custom title not found"
45-
page = unmanaged_conf.succeed("curl --fail http://localhost:8082/")
46-
assert "test title rodUsEagid" not in page, "Custom title found where it shouldn't be"
4726
'';
4827
}
4928
)
Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
2-
buildNpmPackage,
32
fetchFromGitHub,
43
nodePackages,
4+
makeBinaryWrapper,
5+
nodejs,
6+
pnpm_10,
57
python3,
68
stdenv,
79
cctools,
8-
IOKit,
10+
darwin,
911
lib,
1012
nixosTests,
1113
enableLocalIcons ? false,
12-
nix-update-script,
1314
}:
1415
let
1516
dashboardIcons = fetchFromGitHub {
@@ -26,63 +27,68 @@ let
2627
cp ${dashboardIcons}/LICENSE $out/share/homepage/public/icons/
2728
'';
2829
in
29-
buildNpmPackage rec {
30+
stdenv.mkDerivation (finalAttrs: {
3031
pname = "homepage-dashboard";
31-
version = "0.10.9";
32+
version = "1.0.4";
3233

3334
src = fetchFromGitHub {
3435
owner = "gethomepage";
3536
repo = "homepage";
36-
rev = "v${version}";
37-
hash = "sha256-q8+uoikHMQVuTrVSH8tPsoI5655ZStMc/7tmoAfoZIY=";
37+
tag = "v${finalAttrs.version}";
38+
hash = "sha256-SwzgmVy3TBzEH+FJ/kY+iCo+pZhud1IZkfCh2DiSTsk=";
3839
};
3940

40-
npmDepsHash = "sha256-N39gwct2U4UxlIL5ceDzzU7HpA6xh2WksrZNxGz04PU=";
41-
42-
preBuild = ''
43-
mkdir -p config
44-
'';
45-
46-
postBuild = ''
47-
# Add a shebang to the server js file, then patch the shebang.
48-
sed -i '1s|^|#!/usr/bin/env node\n|' .next/standalone/server.js
49-
patchShebangs .next/standalone/server.js
50-
'';
41+
# This patch ensures that the cache implementation respects the env
42+
# variable `NIXPKGS_HOMEPAGE_CACHE_DIR`, which is set by default in the
43+
# wrapper below.
44+
# The patch is automatically generated by the `update.sh` script.
45+
patches = [ ./prerender_cache_path.patch ];
46+
47+
pnpmDeps = pnpm_10.fetchDeps {
48+
inherit (finalAttrs)
49+
pname
50+
version
51+
src
52+
patches
53+
;
54+
hash = "sha256-GUDSfAbBK+6Bbih5jBrkjiMYLOJM7gMfurXFeez1bSw=";
55+
};
5156

52-
nativeBuildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ cctools ];
57+
nativeBuildInputs = [
58+
makeBinaryWrapper
59+
nodejs
60+
pnpm_10.configHook
61+
] ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ];
5362

5463
buildInputs = [
5564
nodePackages.node-gyp-build
56-
] ++ lib.optionals stdenv.hostPlatform.isDarwin [ IOKit ];
65+
] ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.IOKit ];
5766

5867
env.PYTHON = "${python3}/bin/python";
5968

69+
buildPhase = ''
70+
runHook preBuild
71+
mkdir -p config
72+
pnpm build
73+
runHook postBuild
74+
'';
75+
6076
installPhase = ''
6177
runHook preInstall
6278
63-
mkdir -p $out/{share,bin}
64-
79+
mkdir -p $out/{bin,share}
6580
cp -r .next/standalone $out/share/homepage/
6681
cp -r public $out/share/homepage/public
82+
chmod +x $out/share/homepage/server.js
6783
6884
mkdir -p $out/share/homepage/.next
6985
cp -r .next/static $out/share/homepage/.next/static
7086
71-
chmod +x $out/share/homepage/server.js
72-
73-
# This patch must be applied here, as it's patching the `dist` directory
74-
# of NextJS. Without this, homepage-dashboard errors when trying to
75-
# write its prerender cache.
76-
#
77-
# This patch ensures that the cache implementation respects the env
78-
# variable `NIXPKGS_HOMEPAGE_CACHE_DIR`, which is set by default in the
79-
# wrapper below.
80-
(cd "$out" && patch -p1 <${./prerender_cache_path.patch})
81-
82-
makeWrapper $out/share/homepage/server.js $out/bin/homepage \
87+
makeWrapper "${lib.getExe nodejs}" $out/bin/homepage \
8388
--set-default PORT 3000 \
8489
--set-default HOMEPAGE_CONFIG_DIR /var/lib/homepage-dashboard \
85-
--set-default NIXPKGS_HOMEPAGE_CACHE_DIR /var/cache/homepage-dashboard
90+
--set-default NIXPKGS_HOMEPAGE_CACHE_DIR /var/cache/homepage-dashboard \
91+
--add-flags "$out/share/homepage/server.js"
8692
8793
${if enableLocalIcons then installLocalIcons else ""}
8894
@@ -95,17 +101,17 @@ buildNpmPackage rec {
95101
tests = {
96102
inherit (nixosTests) homepage-dashboard;
97103
};
98-
updateScript = nix-update-script { };
104+
updateScript = ./update.sh;
99105
};
100106

101107
meta = {
102108
description = "Highly customisable dashboard with Docker and service API integrations";
103-
changelog = "https://github.com/gethomepage/homepage/releases/tag/v${version}";
109+
changelog = "https://github.com/gethomepage/homepage/releases/tag/v${finalAttrs.version}";
104110
mainProgram = "homepage";
105111
homepage = "https://gethomepage.dev";
106112
license = lib.licenses.gpl3;
107113
maintainers = with lib.maintainers; [ jnsgruk ];
108114
platforms = lib.platforms.all;
109115
broken = stdenv.hostPlatform.isDarwin;
110116
};
111-
}
117+
})

0 commit comments

Comments
 (0)