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

nixos/systemd: Allow to override serviceConfig #41446

Merged
merged 1 commit into from Jun 5, 2018

Conversation

aszlig
Copy link
Member

@aszlig aszlig commented Jun 4, 2018

This has been reported by @qknight in his Stack Overflow question:

https://stackoverflow.com/q/50678639

The correct way to override a single value would be to use something like this:

{ systemd.services.nagios.serviceConfig.Restart = lib.mkForce "no"; }

However, this doesn't work because the check is applied for the attrsOf type and thus the attribute values might still contain the attribute set created by mkOverride.

The unitOption type however did already account for this, but at this stage it's already too late.

So now the actual value is unpacked while checking the values of the attribute set, which should allow us to override values in serviceConfig.

Cc: @edolstra, @qknight

This has been reported by @qknight in his Stack Overflow question:

https://stackoverflow.com/q/50678639

The correct way to override a single value would be to use something
like this:

systemd.services.nagios.serviceConfig.Restart = lib.mkForce "no";

However, this doesn't work because the check is applied for the attrsOf
type and thus the attribute values might still contain the attribute set
created by mkOverride.

The unitOption type however did already account for this, but at this
stage it's already too late.

So now the actual value is unpacked while checking the values of the
attribute set, which should allow us to override values in
serviceConfig.

Signed-off-by: aszlig <aszlig@nix.build>
Cc: @edolstra, @qknight
@4levels
Copy link

4levels commented Sep 16, 2019

Hi all,

is there currently a possible workaround while we wait for this fix to be released?

@aszlig
Copy link
Member Author

aszlig commented Sep 16, 2019

@4levels: This has been merged more than a year ago already.

@4levels
Copy link

4levels commented Sep 16, 2019

Hi @aszlig, this surprises me as I'm still running in exactly the same issue as described in the SO question here: https://stackoverflow.com/questions/50678639/how-to-change-the-serviceconfig-of-a-service-defined-in-nixpkgs-from-configurati

If I try to set the ExecStart part of the serviceConfig for eg. systemd.services.kibana I always get the following error: attribute 'systemd.services.kibana.serviceConfig.ExecStart' already defined without me explicitly defining it. If I adjust this to merge the existing kibana config, I get the infinite recursion error

I'm using the 19.03 channel..

I'm already setting a lot of systemd.services configurations myself, but not for kibana. I'll keep trying to find out if I can get it to work as expected. mkForce or mkOverride don't help either..

@jtojnar
Copy link
Contributor

jtojnar commented Sep 16, 2019

Did you try to override just the restart option, as suggested by OP?

{ systemd.services.nagios.serviceConfig.Restart = lib.mkForce "no"; }

@4levels
Copy link

4levels commented Sep 16, 2019

Ok, I managed to get around it, like so:

systemd.services = mapAttrs' systemdService cfg.platforms
      // runners cfg.platforms // timers cfg.platforms
      // {
        kibana.serviceConfig.ExecStart = lib.mkForce (kibanaExecStart cfg.platforms);
      }

where the systemdService, runners, timers are custom sets of systemd serviceconfigs and cfg.platforms holds my service-setup.

So if I do it in one go, this works. If I try however to set the kibana serviceconfig afterwards, I'm stuck.

systemd.services = mapAttrs' systemdService cfg.platforms
      // runners cfg.platforms // timers cfg.platforms;
systemd.services.kibana.serviceConfig.ExecStart = lib.mkForce (kibanaExecStart cfg.platforms);

@aszlig
Copy link
Member Author

aszlig commented Sep 16, 2019

@4levels: Mhm, as @jtojnar mentioned, mkForce should work, here is a smaller PoC with 19.03 as you mentioned:

(import "${fetchTarball channel:nixos-19.03}/nixos" {
  configuration = { lib, ... }: {
    systemd.services.kibana.serviceConfig.ExecStart = lib.mkForce "foo";
  };
}).config.system.build.units."kibana.service"

@4levels
Copy link

4levels commented Sep 16, 2019

Hi @aszlig, I guess it's because I'm already setting the systemd.services key to a set of my own serviceConfigs, which I seem to be able to do only once. If I omit the mkForce, I get the following error The unique option systemd.services.kibana.serviceConfig.ExecStart' is defined multiple times`. The whole setup I have here is obviously far more complex (nixops, overlays, legacy versions of packages, etc. etc.), but I'm very happy I still managed ;-)
Thanks for your quick responses!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants