wrapperManagerLib.systemd

A fork of the NixOS systemd library from nixpkgs suited for wrapper-manager’s needs. The major reason it is forked instead of using it directly is because a lot of the functions is centered around NixOS' need (unsurprisingly) and it would require a LOT of adjusting otherwise so why not just fork it directly.

Unlike NixOS' version, wrapper-manager only cares about generating them unit files so it won’t have additional options such as restartTriggers and the like. Thus, we have dropped several module options such as systemd.units.<name>.enable and systemd.units.<name>.overrideStrategy. Furthermore, we have added support for generating drop-in unit files by "$UNITNAME/$OVERRIDE_NAME" where it should map to $out/etc/systemd/$TYPEDIR/$UNITNAME.$UNITTYPE.d/$OVERRIDE_NAME.conf.

It is meant to be composed alongside other packages of other environments (e.g., systemd.packages from NixOS) after all and several environment implementation are already taking care of installing them properly such as NixOS and home-manager.

wrapperManagerLib.systemd.intoUnit

Convert the given non-generic unit options into the generic units version. For example, it converts programs.systemd.system.services.hello suitable for programs.systemd.system.units.hello where it will be included in the derivation.

For third-party module authors, it is recommended to set programs.systemd.{system,user}.units with this function.

Arguments

It’s an attrset that is expected to have shared module options with programs.systemd.system.units.

Type

intoUnit :: attr -> attr

wrapperManagerLib.systemd.generateUnits

Builder function for generating a set of systemd units expected to be from programs.systemd.$VARIANT.units.

Arguments

It’s a sole attrset with the following expected attributes:

units

A set of units associated with a systemd installation. Typically, this is used from programs.systemd.user.units and programs.systemd.system.units respectively to build the systemd installation directory.

Type

generateUnits :: Attr -> Derivation

Example

For the following example, assume it is invoked inside of a wrapper-manager configuration.

{ config, lib, pkgs, wrapperManagerLib, ... }:

{
  files."lib/my-custom-apps/examples/systemd".source =
    wrapperManagerLib.systemd.generateUnits { inherit (config.programs.systemd.system) units; };
}

wrapperManagerLib.systemd.shellEscape

Given a Nix string, return a shell string value.

Arguments

s

The Nix string value.

Type

shellEscape :: String -> String

Examples

shellEscape "\\$"
=> "\\\\$"

wrapperManagerLib.systemd.mkPathSafeName

Given a Nix string, return a path-safe name typically used as part of a filename itself.

Arguments

s

The string value.

Type

mkPathSafeName :: String -> String

Examples

mkPathSafeName "foo@sample.service"
=> "foo-sample.service"

wrapperManagerLib.systemd.unitNameType

Module type for matching with the systemd unit filenames.

wrapperManagerLib.systemd.splitUnitFilename

Given a string, split the unit name into the unit name and its drop-in, if there’s one.

Arguments

s

The string value.

Type

splitUnitFilename :: str -> str

Example

splitUnitFilename "hello-there.service"
=> [ "hello-there.service" ]

splitUnitFilename "hello-there.service.d/10-overrides.conf"
=> [ "hello-there.service.d" "10-overrides.conf" ]

wrapperManagerLib.systemd.getUnitName

Naively get the unit name of the given string.

Type

getUnitName :: str -> str

Examples

getUnitName "hello.service.d/10-override.conf"
=> hello.service.d

wrapperManagerLib.systemd.mkUnitFileName

Given a name and an extension, create the unit filename. Typically used for properly setting the filename option from programs.systemd.units and the like.

Arguments

unitType

The unit type associated (e.g., service, slice).

s

String value.

Type

mkUnitFileName :: str -> str -> str

Example

mkUnitFileName "service" "hello-there"1
=> "hello-there.service"

mkUnitFileName "service" "hello-there/10-override"
=> "hello-there.service.d/10-override.conf"