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";
|
target = "nix.machines";
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.systemd.units."nix-daemon.socket" =
|
boot.systemd.sockets."nix-daemon" =
|
||||||
{ wantedBy = [ "sockets.target" ];
|
{ description = "Nix Daemon Socket";
|
||||||
text =
|
wantedBy = [ "sockets.target" ];
|
||||||
''
|
before = [ "multi-user.target" ];
|
||||||
[Unit]
|
socketConfig.ListenStream = "/nix/var/nix/daemon-socket/socket";
|
||||||
Description=Nix Daemon Socket
|
|
||||||
Before=multi-user.target
|
|
||||||
|
|
||||||
[Socket]
|
|
||||||
ListenStream=/nix/var/nix/daemon-socket/socket
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.systemd.services."nix-daemon" =
|
boot.systemd.services."nix-daemon" =
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
|
|
||||||
{
|
rec {
|
||||||
|
|
||||||
serviceOptions = {
|
unitOptions = {
|
||||||
|
|
||||||
description = mkOption {
|
description = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
@ -62,6 +62,22 @@ with pkgs.lib;
|
|||||||
description = "Units that want (i.e. depend on) this unit.";
|
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 {
|
environment = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
type = types.attrs;
|
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 {
|
serviceConfig = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
example =
|
example =
|
||||||
|
@ -202,9 +202,17 @@ let
|
|||||||
(if isList value then value else [value]))
|
(if isList value then value else [value]))
|
||||||
as));
|
as));
|
||||||
|
|
||||||
|
targetToUnit = name: def:
|
||||||
|
{ inherit (def) wantedBy;
|
||||||
|
text =
|
||||||
|
''
|
||||||
|
[Unit]
|
||||||
|
${attrsToSection def.unitConfig}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
serviceToUnit = name: def:
|
serviceToUnit = name: def:
|
||||||
{ inherit (def) wantedBy;
|
{ inherit (def) wantedBy;
|
||||||
|
|
||||||
text =
|
text =
|
||||||
''
|
''
|
||||||
[Unit]
|
[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;
|
nixosUnits = mapAttrsToList makeUnit cfg.units;
|
||||||
|
|
||||||
units = pkgs.runCommand "units" { preferLocalBuild = true; }
|
units = pkgs.runCommand "units" { preferLocalBuild = true; }
|
||||||
@ -319,11 +339,37 @@ in
|
|||||||
description = "Packages providing systemd units.";
|
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 {
|
boot.systemd.services = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
type = types.attrsOf types.optionSet;
|
type = types.attrsOf types.optionSet;
|
||||||
options = [ serviceOptions serviceConfig ];
|
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 {
|
boot.systemd.defaultUnit = mkOption {
|
||||||
@ -385,7 +431,9 @@ in
|
|||||||
boot.systemd.units =
|
boot.systemd.units =
|
||||||
{ "rescue.service".text = rescueService; }
|
{ "rescue.service".text = rescueService; }
|
||||||
// { "fs.target" = { text = fsTarget; wantedBy = [ "multi-user.target" ]; }; }
|
// { "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…
x
Reference in New Issue
Block a user