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 }: {
|
||||
serviceConfig = self.lib.makeServiceConfig
|
||||
[
|
||||
"service-1"
|
||||
"service-2"
|
||||
];
|
||||
serviceConfig = self.lib.makeServiceConfig {
|
||||
module = { imports = [ ./modules ]; };
|
||||
};
|
||||
|
||||
lib = {
|
||||
makeServiceConfig = serviceNames:
|
||||
makeServiceConfig = { module }:
|
||||
let
|
||||
system = flake-utils.lib.system.x86_64-linux;
|
||||
lib = nixpkgs.lib;
|
||||
nixosConfig = nixpkgs.lib.nixosSystem {
|
||||
inherit system;
|
||||
specialArgs = { };
|
||||
modules = [ ./modules ];
|
||||
modules = [ module ];
|
||||
};
|
||||
services = lib.flip lib.genAttrs
|
||||
(serviceName:
|
||||
nixosConfig.config.systemd.units."${serviceName}.service".unit)
|
||||
serviceNames;
|
||||
nixosConfig.config.service-manager.services;
|
||||
in
|
||||
nixpkgs.legacyPackages.${system}.writeTextFile {
|
||||
name = "services";
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{ pkgs, ... }: {
|
||||
systemd.services =
|
||||
{ lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
service-1 = "service-1";
|
||||
service-2 = "service-2";
|
||||
in
|
||||
{
|
||||
|
||||
services = {
|
||||
${service-1} = {
|
||||
enable = true;
|
||||
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; };
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue