forked from Skynet/discord-bot
flake: format it
This commit is contained in:
parent
982b9defd4
commit
ed4c46e81d
1 changed files with 198 additions and 188 deletions
62
flake.nix
62
flake.nix
|
@ -17,22 +17,27 @@
|
|||
extra-trusted-public-keys = "skynet-cache:OdfA4Or0JcHiHf05fsiIR4nZT2z2yDEtkoLqhntGAz4=";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, utils, naersk }: utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
utils,
|
||||
naersk,
|
||||
}:
|
||||
utils.lib.eachDefaultSystem (
|
||||
system: let
|
||||
pkgs = nixpkgs.legacyPackages."${system}";
|
||||
naersk-lib = naersk.lib."${system}";
|
||||
package_name = "skynet_discord_bot";
|
||||
desc = "Skynet Discord Bot";
|
||||
in rec {
|
||||
|
||||
# `nix build`
|
||||
packages."${package_name}" = naersk-lib.buildPackage {
|
||||
pname = "${package_name}";
|
||||
root = ./.;
|
||||
|
||||
buildInputs = [
|
||||
pkgs.openssl
|
||||
pkgs.pkg-config
|
||||
buildInputs = with pkgs; [
|
||||
openssl
|
||||
pkg-config
|
||||
];
|
||||
};
|
||||
|
||||
|
@ -47,12 +52,16 @@
|
|||
|
||||
# `nix develop`
|
||||
devShell = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [ rustc cargo pkg-config openssl];
|
||||
nativeBuildInputs = with pkgs; [rustc cargo pkg-config openssl];
|
||||
};
|
||||
|
||||
nixosModule = { lib, pkgs, config, ... }:
|
||||
with lib;
|
||||
let
|
||||
nixosModule = {
|
||||
lib,
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.services."${package_name}";
|
||||
# secret options are in the env file(s) loaded separately
|
||||
environment_config = {
|
||||
|
@ -62,13 +71,14 @@
|
|||
DATABASE = "database.db";
|
||||
};
|
||||
|
||||
service_name = script: lib.strings.sanitizeDerivationName("${cfg.user}@${script}");
|
||||
service_name = script: lib.strings.sanitizeDerivationName "${cfg.user}@${script}";
|
||||
|
||||
# oneshot scripts to run
|
||||
serviceGenerator = mapAttrs' (script: time: nameValuePair (service_name script) {
|
||||
serviceGenerator = mapAttrs' (script: time:
|
||||
nameValuePair (service_name script) {
|
||||
description = "Service for ${desc} ${script}";
|
||||
wantedBy = [ ];
|
||||
after = [ "network-online.target" ];
|
||||
wantedBy = [];
|
||||
after = ["network-online.target"];
|
||||
environment = environment_config;
|
||||
|
||||
serviceConfig = {
|
||||
|
@ -86,11 +96,12 @@
|
|||
});
|
||||
|
||||
# each timer will run the above service
|
||||
timerGenerator = mapAttrs' (script: time: nameValuePair (service_name script) {
|
||||
timerGenerator = mapAttrs' (script: time:
|
||||
nameValuePair (service_name script) {
|
||||
description = "Timer for ${desc} ${script}";
|
||||
|
||||
wantedBy = [ "timers.target" ];
|
||||
partOf = [ "${service_name script}.service" ];
|
||||
wantedBy = ["timers.target"];
|
||||
partOf = ["${service_name script}.service"];
|
||||
timerConfig = {
|
||||
OnCalendar = time;
|
||||
Unit = "${service_name script}.service";
|
||||
|
@ -107,7 +118,6 @@
|
|||
# minecraft stuff is updated at 5am
|
||||
"update_minecraft" = "5:10:00";
|
||||
};
|
||||
|
||||
in {
|
||||
options.services."${package_name}" = {
|
||||
enable = mkEnableOption "enable ${package_name}";
|
||||
|
@ -165,8 +175,7 @@
|
|||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
users.groups."${cfg.user}" = { };
|
||||
users.groups."${cfg.user}" = {};
|
||||
|
||||
users.users."${cfg.user}" = {
|
||||
createHome = true;
|
||||
|
@ -175,13 +184,14 @@
|
|||
group = "${cfg.user}";
|
||||
};
|
||||
|
||||
systemd.services = {
|
||||
systemd.services =
|
||||
{
|
||||
# main service
|
||||
"${package_name}" = {
|
||||
description = desc;
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ ];
|
||||
wantedBy = ["multi-user.target"];
|
||||
after = ["network-online.target"];
|
||||
wants = [];
|
||||
environment = environment_config;
|
||||
|
||||
serviceConfig = {
|
||||
|
@ -204,11 +214,11 @@
|
|||
"${cfg.env.wolves}"
|
||||
];
|
||||
};
|
||||
} // serviceGenerator scripts;
|
||||
}
|
||||
// serviceGenerator scripts;
|
||||
|
||||
# timers to run the above services
|
||||
systemd.timers = timerGenerator scripts;
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue