{nixos/,}cockpit: add branding + small fixes (#413033)

Changed files
+85 -10
nixos
modules
services
monitoring
pkgs
by-name
+42 -8
nixos/modules/services/monitoring/cockpit.nix
···
'';
};
+
showBanner = mkOption {
+
description = "Whether to add the Cockpit banner to the issue and motd files.";
+
type = types.bool;
+
default = true;
+
example = false;
+
};
+
port = mkOption {
description = "Port where cockpit will listen.";
type = types.port;
···
};
};
};
-
config = mkIf cfg.enable {
+
config = mkIf cfg.enable {
# expose cockpit-bridge system-wide
environment.systemPackages = [ cfg.package ];
# allow cockpit to find its plugins
environment.pathsToLink = [ "/share/cockpit" ];
-
# generate cockpit settings
-
environment.etc."cockpit/cockpit.conf".source = settingsFormat.generate "cockpit.conf" cfg.settings;
+
environment.etc = {
+
# generate cockpit settings
+
"cockpit/cockpit.conf".source = settingsFormat.generate "cockpit.conf" cfg.settings;
+
+
# Add "Web console: ..." line to issue and MOTD
+
"issue.d/cockpit.issue" = {
+
enable = cfg.showBanner;
+
source = "/run/cockpit/issue";
+
};
+
"motd.d/cockpit" = {
+
enable = cfg.showBanner;
+
source = "/run/cockpit/issue";
+
};
+
};
security.pam.services.cockpit = {
startSession = true;
···
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
systemd.packages = [ cfg.package ];
-
systemd.sockets.cockpit.wantedBy = [ "multi-user.target" ];
-
systemd.sockets.cockpit.listenStreams = [
-
"" # workaround so it doesn't listen on both ports caused by the runtime merging
-
(toString cfg.port)
-
];
+
+
systemd.sockets.cockpit = {
+
wantedBy = [ "multi-user.target" ];
+
listenStreams = [
+
"" # workaround so it doesn't listen on both ports caused by the runtime merging
+
(toString cfg.port)
+
];
+
};
+
+
# Enable connecting to remote hosts from the login page
+
systemd.services = mkIf (cfg.settings ? LoginTo -> cfg.settings.LoginTo) {
+
"cockpit-wsinstance-http".path = [
+
config.programs.ssh.package
+
cfg.package
+
];
+
"cockpit-wsinstance-https@".path = [
+
config.programs.ssh.package
+
cfg.package
+
];
+
};
systemd.tmpfiles.rules = [
# From $out/lib/tmpfiles.d/cockpit-tmpfiles.conf
+11
pkgs/by-name/co/cockpit/branding.css
···
+
#badge {
+
inline-size: 225px;
+
block-size: 80px;
+
background-image: url("logo.png");
+
background-size: contain;
+
background-repeat: no-repeat;
+
}
+
+
#brand::before {
+
content: "${PRETTY_NAME}";
+
}
+32 -2
pkgs/by-name/co/cockpit/package.nix
···
systemd,
udev,
xmlto,
+
# Enables lightweight NixOS branding, replacing the default Cockpit icons
+
withBranding ? true,
+
nixos-icons,
}:
stdenv.mkDerivation (finalAttrs: {
···
# hardcode libexecdir, I am assuming that cockpit only use it to find it's binaries
printf 'def get_libexecdir() -> str:\n\treturn "%s"' "$out/libexec" >> src/cockpit/packages.py
+
+
# patch paths used as visibility conditions in apps
+
substituteInPlace pkg/*/manifest.json \
+
--replace-warn '"/usr/bin' '"/run/current-system/sw/bin' \
+
--replace-warn '"/usr/sbin' '"/run/current-system/sw/bin' \
+
--replace-warn '"/usr/share' '"/run/current-system/sw/share' \
+
--replace-warn '"/lib/systemd' '"/run/current-system/sw/lib/systemd'
+
+
# replace reference to system python interpreter, used for e.g. sosreport
+
substituteInPlace pkg/lib/python.ts \
+
--replace-fail /usr/libexec/platform-python ${python3Packages.python.interpreter}
'';
configureFlags = [
···
substituteInPlace $out/lib/systemd/*/* \
--replace-warn /bin /run/current-system/sw/bin
+
${lib.optionalString withBranding ''
+
mkdir -p "$out/share/cockpit/branding/nixos"
+
pushd "$out/share/cockpit/branding/nixos"
+
+
icons="${nixos-icons}/share/icons/hicolor"
+
ln -s "$icons/16x16/apps/nix-snowflake.png" favicon.ico
+
ln -s "$icons/256x256/apps/nix-snowflake.png" logo.png
+
ln -s "$icons/256x256/apps/nix-snowflake.png" apple-touch-icon.png
+
cp "${./branding.css}" branding.css
+
+
popd
+
''}
+
runHook postFixup
'';
···
export G_MESSAGES_DEBUG=cockpit-ws,cockpit-wrapper,cockpit-bridge
export PATH=$PATH:$(pwd)
-
make check -j$NIX_BUILD_CORES || true
+
make check -j$NIX_BUILD_CORES || true
npm run eslint
npm run stylelint
'';
···
homepage = "https://cockpit-project.org/";
changelog = "https://cockpit-project.org/blog/cockpit-${finalAttrs.version}.html";
license = lib.licenses.lgpl21;
-
maintainers = [ lib.maintainers.lucasew ];
+
maintainers = with lib.maintainers; [
+
lucasew
+
andre4ik3
+
];
};
})