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=";
};
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
];
};
@ -50,9 +55,13 @@
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,10 +71,11 @@
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"];
@ -86,7 +96,8 @@
});
# 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"];
@ -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,7 +175,6 @@
};
config = mkIf cfg.enable {
users.groups."${cfg.user}" = {};
users.users."${cfg.user}" = {
@ -175,7 +184,8 @@
group = "${cfg.user}";
};
systemd.services = {
systemd.services =
{
# main service
"${package_name}" = {
description = desc;
@ -204,11 +214,11 @@
"${cfg.env.wolves}"
];
};
} // serviceGenerator scripts;
}
// serviceGenerator scripts;
# timers to run the above services
systemd.timers = timerGenerator scripts;
};
};
}