Add options ‘boot.systemd.targets’ and ‘boot.systemd.sockets’
This commit is contained in:
parent
ca13a913d9
commit
2cf5e3cb66
@ -246,17 +246,11 @@ in
|
||||
target = "nix.machines";
|
||||
};
|
||||
|
||||
boot.systemd.units."nix-daemon.socket" =
|
||||
{ wantedBy = [ "sockets.target" ];
|
||||
text =
|
||||
''
|
||||
[Unit]
|
||||
Description=Nix Daemon Socket
|
||||
Before=multi-user.target
|
||||
|
||||
[Socket]
|
||||
ListenStream=/nix/var/nix/daemon-socket/socket
|
||||
'';
|
||||
boot.systemd.sockets."nix-daemon" =
|
||||
{ description = "Nix Daemon Socket";
|
||||
wantedBy = [ "sockets.target" ];
|
||||
before = [ "multi-user.target" ];
|
||||
socketConfig.ListenStream = "/nix/var/nix/daemon-socket/socket";
|
||||
};
|
||||
|
||||
boot.systemd.services."nix-daemon" =
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
with pkgs.lib;
|
||||
|
||||
{
|
||||
rec {
|
||||
|
||||
serviceOptions = {
|
||||
unitOptions = {
|
||||
|
||||
description = mkOption {
|
||||
default = "";
|
||||
@ -62,6 +62,22 @@ with pkgs.lib;
|
||||
description = "Units that want (i.e. depend on) this unit.";
|
||||
};
|
||||
|
||||
unitConfig = mkOption {
|
||||
default = {};
|
||||
example = { RequiresMountsFor = "/data"; };
|
||||
type = types.attrs;
|
||||
description = ''
|
||||
Each attribute in this set specifies an option in the
|
||||
<literal>[Unit]</literal> section of the unit. See
|
||||
<citerefentry><refentrytitle>systemd.unit</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
serviceOptions = unitOptions // {
|
||||
|
||||
environment = mkOption {
|
||||
default = {};
|
||||
type = types.attrs;
|
||||
@ -80,18 +96,6 @@ with pkgs.lib;
|
||||
'';
|
||||
};
|
||||
|
||||
unitConfig = mkOption {
|
||||
default = {};
|
||||
example = { RequiresMountsFor = "/data"; };
|
||||
type = types.attrs;
|
||||
description = ''
|
||||
Each attribute in this set specifies an option in the
|
||||
<literal>[Unit]</literal> section of the unit. See
|
||||
<citerefentry><refentrytitle>systemd.unit</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
|
||||
serviceConfig = mkOption {
|
||||
default = {};
|
||||
example =
|
||||
|
@ -202,9 +202,17 @@ let
|
||||
(if isList value then value else [value]))
|
||||
as));
|
||||
|
||||
targetToUnit = name: def:
|
||||
{ inherit (def) wantedBy;
|
||||
text =
|
||||
''
|
||||
[Unit]
|
||||
${attrsToSection def.unitConfig}
|
||||
'';
|
||||
};
|
||||
|
||||
serviceToUnit = name: def:
|
||||
{ inherit (def) wantedBy;
|
||||
|
||||
text =
|
||||
''
|
||||
[Unit]
|
||||
@ -240,6 +248,18 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
socketToUnit = name: def:
|
||||
{ inherit (def) wantedBy;
|
||||
text =
|
||||
''
|
||||
[Unit]
|
||||
${attrsToSection def.unitConfig}
|
||||
|
||||
[Socket]
|
||||
${attrsToSection def.socketConfig}
|
||||
'';
|
||||
};
|
||||
|
||||
nixosUnits = mapAttrsToList makeUnit cfg.units;
|
||||
|
||||
units = pkgs.runCommand "units" { preferLocalBuild = true; }
|
||||
@ -319,11 +339,37 @@ in
|
||||
description = "Packages providing systemd units.";
|
||||
};
|
||||
|
||||
boot.systemd.targets = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf types.optionSet;
|
||||
options = unitOptions;
|
||||
description = "Definition of systemd target units.";
|
||||
};
|
||||
|
||||
boot.systemd.services = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf types.optionSet;
|
||||
options = [ serviceOptions serviceConfig ];
|
||||
description = "Definition of systemd services.";
|
||||
description = "Definition of systemd service units.";
|
||||
};
|
||||
|
||||
boot.systemd.sockets = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf types.optionSet;
|
||||
options = unitOptions // {
|
||||
socketConfig = mkOption {
|
||||
default = {};
|
||||
example = { ListenStream = "/run/my-socket"; };
|
||||
type = types.attrs;
|
||||
description = ''
|
||||
Each attribute in this set specifies an option in the
|
||||
<literal>[Socket]</literal> section of the unit. See
|
||||
<citerefentry><refentrytitle>systemd.socket</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
};
|
||||
description = "Definition of systemd socket units.";
|
||||
};
|
||||
|
||||
boot.systemd.defaultUnit = mkOption {
|
||||
@ -385,7 +431,9 @@ in
|
||||
boot.systemd.units =
|
||||
{ "rescue.service".text = rescueService; }
|
||||
// { "fs.target" = { text = fsTarget; wantedBy = [ "multi-user.target" ]; }; }
|
||||
// mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.services;
|
||||
// mapAttrs' (n: v: nameValuePair "${n}.target" (targetToUnit n v)) cfg.targets
|
||||
// mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.services
|
||||
// mapAttrs' (n: v: nameValuePair "${n}.socket" (socketToUnit n v)) cfg.sockets;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user