Move nix code under nix/
This commit is contained in:
parent
fe6fb907f7
commit
929da3e3c3
3 changed files with 2 additions and 2 deletions
34
nix/lib.nix
Normal file
34
nix/lib.nix
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
{ nixpkgs }:
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
in
|
||||
{
|
||||
makeServiceConfig = { system, module }:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
nixosConfig = lib.nixosSystem {
|
||||
inherit system;
|
||||
specialArgs = { };
|
||||
modules = [ module ];
|
||||
};
|
||||
services = lib.flip lib.genAttrs
|
||||
(serviceName:
|
||||
nixosConfig.config.systemd.units."${serviceName}.service".unit)
|
||||
nixosConfig.config.service-manager.services;
|
||||
|
||||
servicesPath =
|
||||
pkgs.writeTextFile {
|
||||
name = "services";
|
||||
destination = "/services.json";
|
||||
text = lib.generators.toJSON { } services;
|
||||
};
|
||||
activationScript = pkgs.writeShellScript "activate" ''
|
||||
echo "${servicesPath}"
|
||||
'';
|
||||
in
|
||||
pkgs.linkFarmFromDrvs "service-manager" [
|
||||
servicesPath
|
||||
activationScript
|
||||
];
|
||||
}
|
||||
57
nix/modules/default.nix
Normal file
57
nix/modules/default.nix
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
{ lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
service-1 = "service-1";
|
||||
service-2 = "service-2";
|
||||
|
||||
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 = ''
|
||||
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