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,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; };
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue