flake: format it

This commit is contained in:
silver 2024-05-12 16:24:48 +01:00
parent 982b9defd4
commit ed4c46e81d

View file

@ -17,22 +17,27 @@
extra-trusted-public-keys = "skynet-cache:OdfA4Or0JcHiHf05fsiIR4nZT2z2yDEtkoLqhntGAz4="; extra-trusted-public-keys = "skynet-cache:OdfA4Or0JcHiHf05fsiIR4nZT2z2yDEtkoLqhntGAz4=";
}; };
outputs = { self, nixpkgs, utils, naersk }: utils.lib.eachDefaultSystem (system: outputs = {
let self,
nixpkgs,
utils,
naersk,
}:
utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages."${system}"; pkgs = nixpkgs.legacyPackages."${system}";
naersk-lib = naersk.lib."${system}"; naersk-lib = naersk.lib."${system}";
package_name = "skynet_discord_bot"; package_name = "skynet_discord_bot";
desc = "Skynet Discord Bot"; desc = "Skynet Discord Bot";
in rec { in rec {
# `nix build` # `nix build`
packages."${package_name}" = naersk-lib.buildPackage { packages."${package_name}" = naersk-lib.buildPackage {
pname = "${package_name}"; pname = "${package_name}";
root = ./.; root = ./.;
buildInputs = [ buildInputs = with pkgs; [
pkgs.openssl openssl
pkgs.pkg-config pkg-config
]; ];
}; };
@ -50,9 +55,13 @@
nativeBuildInputs = with pkgs; [rustc cargo pkg-config openssl]; nativeBuildInputs = with pkgs; [rustc cargo pkg-config openssl];
}; };
nixosModule = { lib, pkgs, config, ... }: nixosModule = {
with lib; lib,
let pkgs,
config,
...
}:
with lib; let
cfg = config.services."${package_name}"; cfg = config.services."${package_name}";
# secret options are in the env file(s) loaded separately # secret options are in the env file(s) loaded separately
environment_config = { environment_config = {
@ -62,10 +71,11 @@
DATABASE = "database.db"; 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 # 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}"; description = "Service for ${desc} ${script}";
wantedBy = []; wantedBy = [];
after = ["network-online.target"]; after = ["network-online.target"];
@ -86,7 +96,8 @@
}); });
# each timer will run the above service # 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}"; description = "Timer for ${desc} ${script}";
wantedBy = ["timers.target"]; wantedBy = ["timers.target"];
@ -107,7 +118,6 @@
# minecraft stuff is updated at 5am # minecraft stuff is updated at 5am
"update_minecraft" = "5:10:00"; "update_minecraft" = "5:10:00";
}; };
in { in {
options.services."${package_name}" = { options.services."${package_name}" = {
enable = mkEnableOption "enable ${package_name}"; enable = mkEnableOption "enable ${package_name}";
@ -165,7 +175,6 @@
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
users.groups."${cfg.user}" = {}; users.groups."${cfg.user}" = {};
users.users."${cfg.user}" = { users.users."${cfg.user}" = {
@ -175,7 +184,8 @@
group = "${cfg.user}"; group = "${cfg.user}";
}; };
systemd.services = { systemd.services =
{
# main service # main service
"${package_name}" = { "${package_name}" = {
description = desc; description = desc;
@ -204,11 +214,11 @@
"${cfg.env.wolves}" "${cfg.env.wolves}"
]; ];
}; };
} // serviceGenerator scripts; }
// serviceGenerator scripts;
# timers to run the above services # timers to run the above services
systemd.timers = timerGenerator scripts; systemd.timers = timerGenerator scripts;
}; };
}; };
} }