Set the services to be included as an option in the module.

This commit is contained in:
R-VdP 2023-02-01 16:55:43 +00:00
parent 95bd335d8c
commit 504f413c02
No known key found for this signature in database
2 changed files with 55 additions and 45 deletions

View file

@ -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";

View file

@ -1,10 +1,10 @@
{ pkgs, ... }: { { lib, pkgs, ... }:
systemd.services =
let let
service-1 = "service-1"; service-1 = "service-1";
service-2 = "service-2"; service-2 = "service-2";
in
{ services = {
${service-1} = { ${service-1} = {
enable = true; enable = true;
description = service-1; description = service-1;
@ -42,4 +42,16 @@
''; '';
}; };
}; };
in
{
options = {
service-manager.services = lib.mkOption {
type = with lib.types; listOf str;
};
};
config = {
service-manager.services = lib.attrNames services;
systemd = { inherit services; };
};
} }