Set the services to be included as an option in the module.
This commit is contained in:
parent
95bd335d8c
commit
504f413c02
2 changed files with 55 additions and 45 deletions
14
flake.nix
14
flake.nix
|
|
@ -6,26 +6,24 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils }: {
|
outputs = { self, nixpkgs, flake-utils }: {
|
||||||
serviceConfig = self.lib.makeServiceConfig
|
serviceConfig = self.lib.makeServiceConfig {
|
||||||
[
|
module = { imports = [ ./modules ]; };
|
||||||
"service-1"
|
};
|
||||||
"service-2"
|
|
||||||
];
|
|
||||||
|
|
||||||
lib = {
|
lib = {
|
||||||
makeServiceConfig = serviceNames:
|
makeServiceConfig = { module }:
|
||||||
let
|
let
|
||||||
system = flake-utils.lib.system.x86_64-linux;
|
system = flake-utils.lib.system.x86_64-linux;
|
||||||
lib = nixpkgs.lib;
|
lib = nixpkgs.lib;
|
||||||
nixosConfig = nixpkgs.lib.nixosSystem {
|
nixosConfig = nixpkgs.lib.nixosSystem {
|
||||||
inherit system;
|
inherit system;
|
||||||
specialArgs = { };
|
specialArgs = { };
|
||||||
modules = [ ./modules ];
|
modules = [ module ];
|
||||||
};
|
};
|
||||||
services = lib.flip lib.genAttrs
|
services = lib.flip lib.genAttrs
|
||||||
(serviceName:
|
(serviceName:
|
||||||
nixosConfig.config.systemd.units."${serviceName}.service".unit)
|
nixosConfig.config.systemd.units."${serviceName}.service".unit)
|
||||||
serviceNames;
|
nixosConfig.config.service-manager.services;
|
||||||
in
|
in
|
||||||
nixpkgs.legacyPackages.${system}.writeTextFile {
|
nixpkgs.legacyPackages.${system}.writeTextFile {
|
||||||
name = "services";
|
name = "services";
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,57 @@
|
||||||
{ pkgs, ... }: {
|
{ lib, pkgs, ... }:
|
||||||
systemd.services =
|
|
||||||
let
|
|
||||||
service-1 = "service-1";
|
|
||||||
service-2 = "service-2";
|
|
||||||
in
|
|
||||||
{
|
|
||||||
${service-1} = {
|
|
||||||
enable = true;
|
|
||||||
description = service-1;
|
|
||||||
wants = [ "network-online.target" ];
|
|
||||||
after = [
|
|
||||||
"network-online.target"
|
|
||||||
"avahi-daemon.service"
|
|
||||||
"chrony.service"
|
|
||||||
"nss-lookup.target"
|
|
||||||
"tinc.service"
|
|
||||||
"pulseaudio.service"
|
|
||||||
];
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "oneshot";
|
|
||||||
RemainAfterExit = true;
|
|
||||||
script = ''
|
|
||||||
true
|
|
||||||
'';
|
|
||||||
ExecReload = "true";
|
|
||||||
};
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
};
|
|
||||||
|
|
||||||
${service-2} = {
|
let
|
||||||
enable = true;
|
service-1 = "service-1";
|
||||||
description = service-2;
|
service-2 = "service-2";
|
||||||
serviceConfig = {
|
|
||||||
Type = "simple";
|
|
||||||
};
|
|
||||||
partOf = [ "${service-1}.service" ];
|
|
||||||
wantedBy = [ "${service-1}.service" ];
|
|
||||||
|
|
||||||
|
services = {
|
||||||
|
${service-1} = {
|
||||||
|
enable = true;
|
||||||
|
description = service-1;
|
||||||
|
wants = [ "network-online.target" ];
|
||||||
|
after = [
|
||||||
|
"network-online.target"
|
||||||
|
"avahi-daemon.service"
|
||||||
|
"chrony.service"
|
||||||
|
"nss-lookup.target"
|
||||||
|
"tinc.service"
|
||||||
|
"pulseaudio.service"
|
||||||
|
];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
script = ''
|
script = ''
|
||||||
true
|
true
|
||||||
'';
|
'';
|
||||||
|
ExecReload = "true";
|
||||||
};
|
};
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
${service-2} = {
|
||||||
|
enable = true;
|
||||||
|
description = service-2;
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "simple";
|
||||||
|
};
|
||||||
|
partOf = [ "${service-1}.service" ];
|
||||||
|
wantedBy = [ "${service-1}.service" ];
|
||||||
|
|
||||||
|
script = ''
|
||||||
|
true
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
service-manager.services = lib.mkOption {
|
||||||
|
type = with lib.types; listOf str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
service-manager.services = lib.attrNames services;
|
||||||
|
systemd = { inherit services; };
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue