Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated systemd service contains line that is too long #3403

Closed
Gohla opened this issue Jul 30, 2014 · 2 comments
Closed

Generated systemd service contains line that is too long #3403

Gohla opened this issue Jul 30, 2014 · 2 comments

Comments

@Gohla
Copy link

Gohla commented Jul 30, 2014

I'm setting up a Jenkins instance on a nixos server, which works with default settings. However, if I add more package dependencies to the configuration, the generated systemd service file contains a line that is too long, and systemd cannot parse it any more.

The configuration is:

services.jenkins = {
  enable = true;
  home = "/home/jenkins";
  packages = [ pkgs.stdenv pkgs.git pkgs.oraclejdk7 pkgs.openssh pkgs.nix pkgs.gnutar pkgs.gzip pkgs.bash pkgs.maven pkgs.wget pkgs.unzip pkgs.ant ];
};

This is the generated service file:

[Unit]
After=network.target
Description=Jenkins Continuous Integration Server

[Service]
Environment="JENKINS_HOME=/home/jenkins"
Environment="LOCALE_ARCHIVE=/nix/store/5jxnz56h6ya1wy0dvcll65vkkx9679g4-glibc-locales-2.19/lib/locale/locale-archive"
Environment="NIX_REMOTE=daemon"
Environment="PATH=/nix/store/rq16hrf7gy426a6lcnf6pa9746sxnbgc-stdenv/bin:/nix/store/fqh4k92hghc190lhkqxrgpz1gj3l1zqi-git-1.9.4/bin:/nix/store/6r4ndcffxq5bc8lddycakvbp80l4sxij-jdk-1.7.0_55/bin:/nix/store/2wc50fcn54axkg2kk71jm2r5h0w5rbh6-openssh-6.6p1/bin:/nix/store/9f0n3pzmvv76p33m6rjck4gvifvl87ba-nix-1.7/bin:/nix/store/0x21z9gqd3rdhxffhxdaf1ccilaay4s4-gnutar-1.27.1/bin:/nix/store/asnkw21m4y0ihphnxi8wvw9f45f0d83k-gzip-1.6/bin:/nix/store/p0vd3ydvxplbpjffkpblwj5dahcmp9ri-bash-4.2-p45/bin:/nix/store/amwc7axnc8hi4dpbbsyrn36zq458yhxy-apache-maven-3.0.4/bin:/nix/store/rkhsvhrf6jhc5gl2638j55ap9lqrkfli-wget-1.15/bin:/nix/store/bhkglf9hbr8pbnqbbpszc65r5sh64f06-unzip-6.0/bin:/nix/store/jg2h4bhq4k0mm0wzk69bj9y5bq6xyjb8-ant-1.9.3/bin:/nix/store/xdswdgz11w9lm9n9bzb6spl7dj45s2x2-coreutils-8.21/bin:/nix/store/sls52f6fkpqfs0kj4w0k525v57zrsz9x-findutils-4.4.2/bin:/nix/store/937i66g191shz0hwzll61vmi0zvy3gwy-gnugrep-2.14/bin:/nix/store/93wabgii15q4d74fqgcpfka1qy42igr4-gnused-4.2.2/bin:/nix/store/x0knwlax0d250bqm97lwi7yaqq1lkypf-systemd-212/bin:/nix/store/rq16hrf7gy426a6lcnf6pa9746sxnbgc-stdenv/sbin:/nix/store/fqh4k92hghc190lhkqxrgpz1gj3l1zqi-git-1.9.4/sbin:/nix/store/6r4ndcffxq5bc8lddycakvbp80l4sxij-jdk-1.7.0_55/sbin:/nix/store/2wc50fcn54axkg2kk71jm2r5h0w5rbh6-openssh-6.6p1/sbin:/nix/store/9f0n3pzmvv76p33m6rjck4gvifvl87ba-nix-1.7/sbin:/nix/store/0x21z9gqd3rdhxffhxdaf1ccilaay4s4-gnutar-1.27.1/sbin:/nix/store/asnkw21m4y0ihphnxi8wvw9f45f0d83k-gzip-1.6/sbin:/nix/store/p0vd3ydvxplbpjffkpblwj5dahcmp9ri-bash-4.2-p45/sbin:/nix/store/amwc7axnc8hi4dpbbsyrn36zq458yhxy-apache-maven-3.0.4/sbin:/nix/store/rkhsvhrf6jhc5gl2638j55ap9lqrkfli-wget-1.15/sbin:/nix/store/bhkglf9hbr8pbnqbbpszc65r5sh64f06-unzip-6.0/sbin:/nix/store/jg2h4bhq4k0mm0wzk69bj9y5bq6xyjb8-ant-1.9.3/sbin:/nix/store/xdswdgz11w9lm9n9bzb6spl7dj45s2x2-coreutils-8.21/sbin:/nix/store/sls52f6fkpqfs0kj4w0k525v57zrsz9x-findutils-4.4.2/sbin:/nix/store/937i66g191shz0hwzll61vmi0zvy3gwy-gnugrep-2.14/sbin:/nix/store/93wabgii15q4d74fqgcpfka1qy42igr4-gnused-4.2.2/sbin:/nix/store/x0knwlax0d250bqm97lwi7yaqq1lkypf-systemd-212/sbin"



ExecStart=/nix/store/n2disw6k70h64pyzdhx8bcqbq96yajjp-unit-script/bin/jenkins-start
ExecStartPost=/nix/store/hgjsm80npdmkvx737y0bxcm5kdzd0liz-unit-script/bin/jenkins-post-start
User=jenkins

If I try to start this service, I get the error:

Failed to start jenkins.service: Unit jenkins.service failed to load: Bad message. See system logs and 'systemctl status jenkins.service' for details.

The logs contain:

systemd[1]: [/nix/store/ha60ypzklhj6anrrz8aqrjlgfhrvhrwf-unit/jenkins.service:10] Missing '='.

The line with the PATH environment is 2080 characters. According to someone from the #systemd IRC channel, the systemd parser only handles lines up to LINE_MAX which POSIX sets to 2048 by default. It is possible to break up the line by using the regular '', but since the service file is generated and cannot be changed, the generator needs to break up lines.

On a side note, the path also contains each entry twice, taking up even more space.

@Gohla
Copy link
Author

Gohla commented Jul 30, 2014

cstrahan on the #nixos IRC channel showed me a workaround, create an environment with all the required packages and use that instead:

services.jenkins.packages =
  let env = pkgs.buildEnv {
    name = "jenkins-env";
    pathsToLink = [ "/bin" ];
    paths = [
      # defaults
      pkgs.stdenv pkgs.git pkgs.jdk pkgs.openssh pkgs.nix
      # put your packages here:
      # ...
    ];
  };
  in [ env ];

edolstra added a commit that referenced this issue Jul 30, 2014
Issue #3403. For the case of $PATH being too long, we could call
buildEnv automatically.
edolstra added a commit that referenced this issue Jul 30, 2014
Issue #3403. For the case of $PATH being too long, we could call
buildEnv automatically.

(cherry picked from commit 9956b97)
@domenkozar
Copy link
Member

@Gohla in 9956b97 we check for length now, that's pretty much what can be done.

olorin added a commit to olorin/nixpkgs that referenced this issue Feb 10, 2019
The length check was introduced[0] to match systemd's max line
length. This limit has been increased[1][2] to 1MiB, starting with
systemd v235.

[0] NixOS#3403
[1] systemd/systemd@e6dde45
    (relevant systemd commit)
[2] systemd/systemd#3302
    (more context on systemd change)
adrianpk added a commit to adrianpk/nixpkgs that referenced this issue May 31, 2024
Issue NixOS#3403. For the case of $PATH being too long, we could call
buildEnv automatically.

(cherry picked from commit 9956b97)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants