diff --git a/nixos/modules/services/web-servers/vinyl-cache/default.nix b/nixos/modules/services/web-servers/vinyl-cache/default.nix index 5efc681247e2..f77b5e4aafd7 100644 --- a/nixos/modules/services/web-servers/vinyl-cache/default.nix +++ b/nixos/modules/services/web-servers/vinyl-cache/default.nix @@ -18,12 +18,9 @@ let cfg = config.services.vinyl-cache; # Vinyl Cache has very strong opinions and very complicated code around handling - # the stateDir. After a lot of back and forth, we decided that we a) - # do not want a configurable option here, as most of the handling depends - # on the version and the compile time options. Putting everything into - # /var/run (RAM backed) is absolutely recommended by Vinyl Cache anyways. - # We do need to pay attention to the version-dependend variations, though! - stateDir = "/var/run/vinyld"; + # the stateDir. After a lot of back and forth, we decided to set the stateDir + # at compile time and let the package expose the particular path as passthru. + stateDir = cfg.package.stateDir; # from --help: # -a [=]address[:port][,proto] # HTTP listen address and port @@ -183,13 +180,13 @@ in after = [ "network.target" ]; serviceConfig = { Type = "simple"; - ExecStart = "${cfg.package}/bin/vinyld ${commandLineAddresses} -n ${stateDir} -F ${cfg.extraCommandLine} ${commandLine}"; + ExecStart = "${cfg.package}/bin/vinyld ${commandLineAddresses} -F ${cfg.extraCommandLine} ${commandLine}"; Restart = "always"; RestartSec = "5s"; User = "vinyl-cache"; Group = "vinyl-cache"; DynamicUser = true; - RuntimeDirectory = lib.removePrefix "/var/run/" stateDir; + RuntimeDirectory = lib.removePrefix "/run/" stateDir; AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]; NoNewPrivileges = true; LimitNOFILE = 131072; @@ -221,6 +218,10 @@ in assertion = cfg.package.pname == "vinyl-cache"; message = "services.vinyl-cache only supports Vinyl Cache. Please use services.varnish."; } + { + assertion = lib.strings.hasPrefix "/run/" stateDir; + message = "The vinyl-cache NixOS mosule only supports statedirs in /run/, but vinyl-cache package was compiled with ${stateDir}."; + } ]; }) (lib.mkIf (cfg.enable && cfg.enableFileLogging) { diff --git a/pkgs/servers/vinyl-cache/0001-Makefile-do-not-create-VINYL_STATE_DIR.patch b/pkgs/servers/vinyl-cache/0001-Makefile-do-not-create-VINYL_STATE_DIR.patch new file mode 100644 index 000000000000..60e2ce2de754 --- /dev/null +++ b/pkgs/servers/vinyl-cache/0001-Makefile-do-not-create-VINYL_STATE_DIR.patch @@ -0,0 +1,26 @@ +From 51ee9140e547eccfae99c6ee0846b8d1023d463e Mon Sep 17 00:00:00 2001 +From: Oliver Schmidt +Date: Tue, 19 May 2026 23:31:18 +0200 +Subject: [PATCH] Makefile: do not create VINYL_STATE_DIR + +In the nix expression, we continue to hardcode /var/run +as a statedirectory. But trying to create that top-level +directory from within the build sandbox fails (and is +a wrong move anyways). + +An upstream solution would need to be more nuanced though. + +diff --git a/Makefile.in b/Makefile.in +--- a/Makefile.in ++++ b/Makefile.in +@@ -44,7 +44,6 @@ AM_DISTCHECK_CONFIGURE_FLAGS += --with-unwind + endif + + install-data-local: +- $(install_sh) -d -m 0755 "${VINYL_STATE_DIR}" + + distclean-local: + -find . '(' -name '*.gcda' -o -name '*.gcda' ')' -exec rm '{}' ';' +-- +2.51.2 + diff --git a/pkgs/servers/vinyl-cache/default.nix b/pkgs/servers/vinyl-cache/default.nix index 529bba0d7e27..32e2099aa3c3 100644 --- a/pkgs/servers/vinyl-cache/default.nix +++ b/pkgs/servers/vinyl-cache/default.nix @@ -19,6 +19,21 @@ }: let + # Vinyl Cache has very strong opinions and very complicated code around handling + # the stateDir. After a lot of back and forth, we decided that we + # a) do not want a configurable option here, as most of the handling depends + # on the version and the compile time options. + # b) Vinyl Cache prefers RAM backed stateDirs due to shared memory usage. + # /var/run (RAM backed) is a very good fit as long as it is *not* mounted as + # `noexec`, which is currently not the case in NixOS but in other distros. + # https://code.vinyl-cache.org/vinyl-cache/vinyl-cache/issues/4477 + # c) need to explicitly specify this at compile-time as upstream even changed + # defaults in a patch release. + # To handle potential version-dependent differences, the path is exposed to a + # module using the package via passthru. + stateDirPrefix = "/run"; + # the actual subdirectory is created by vinyld itself within the prefix at runtime + stateDir = "${stateDirPrefix}/vinyld"; generic = { version, @@ -60,10 +75,12 @@ let "ac_cv_have_tcp_fastopen=yes" "ac_cv_have_tcp_keep=yes" "ac_cv_have_working_close_range=yes" + "PYTHON=${buildPackages.python3.interpreter}" + "--with-statedir=${stateDirPrefix}" ]; - buildFlags = [ "localstatedir=/var/run" ]; + patches = [ ./0001-Makefile-do-not-create-VINYL_STATE_DIR.patch ]; postPatch = '' substituteInPlace bin/vinyltest/vtest2/src/vtc_main.c --replace-fail /bin/rm "${coreutils}/bin/rm" @@ -109,6 +126,8 @@ let passthru = { python = python3; tests = nixosTests."vinyl-cache_${lib.versions.major version}"; + # pass-thru compile-time value for usage in module + inherit stateDir; }; meta = {