From 2cf5e3cb6640ae634c5d7060d0ff6fa3b647ce70 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 1 Oct 2012 18:58:11 -0400 Subject: [PATCH] =?UTF-8?q?Add=20options=20=E2=80=98boot.systemd.targets?= =?UTF-8?q?=E2=80=99=20and=20=E2=80=98boot.systemd.sockets=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/services/misc/nix-daemon.nix | 16 ++---- modules/system/boot/systemd-unit-options.nix | 32 +++++++----- modules/system/boot/systemd.nix | 54 ++++++++++++++++++-- 3 files changed, 74 insertions(+), 28 deletions(-) diff --git a/modules/services/misc/nix-daemon.nix b/modules/services/misc/nix-daemon.nix index 718566ee5b9..eeb26ee5e15 100644 --- a/modules/services/misc/nix-daemon.nix +++ b/modules/services/misc/nix-daemon.nix @@ -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" = diff --git a/modules/system/boot/systemd-unit-options.nix b/modules/system/boot/systemd-unit-options.nix index 95506712cac..276197d24d8 100644 --- a/modules/system/boot/systemd-unit-options.nix +++ b/modules/system/boot/systemd-unit-options.nix @@ -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 + [Unit] section of the unit. See + systemd.unit + 5 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 - [Unit] section of the unit. See - systemd.unit - 5 for details. - ''; - }; - serviceConfig = mkOption { default = {}; example = diff --git a/modules/system/boot/systemd.nix b/modules/system/boot/systemd.nix index bb2ea087c21..23751e2104a 100644 --- a/modules/system/boot/systemd.nix +++ b/modules/system/boot/systemd.nix @@ -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 + [Socket] section of the unit. See + systemd.socket + 5 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; };