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
]; ];
}; };
@ -47,12 +52,16 @@
# `nix develop` # `nix develop`
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
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,13 +71,14 @@
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"];
environment = environment_config; environment = environment_config;
serviceConfig = { serviceConfig = {
@ -86,11 +96,12 @@
}); });
# 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"];
partOf = [ "${service_name script}.service" ]; partOf = ["${service_name script}.service"];
timerConfig = { timerConfig = {
OnCalendar = time; OnCalendar = time;
Unit = "${service_name script}.service"; Unit = "${service_name script}.service";
@ -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,8 +175,7 @@
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
users.groups."${cfg.user}" = {};
users.groups."${cfg.user}" = { };
users.users."${cfg.user}" = { users.users."${cfg.user}" = {
createHome = true; createHome = true;
@ -175,13 +184,14 @@
group = "${cfg.user}"; group = "${cfg.user}";
}; };
systemd.services = { systemd.services =
{
# main service # main service
"${package_name}" = { "${package_name}" = {
description = desc; description = desc;
wantedBy = [ "multi-user.target" ]; wantedBy = ["multi-user.target"];
after = [ "network-online.target" ]; after = ["network-online.target"];
wants = [ ]; wants = [];
environment = environment_config; environment = environment_config;
serviceConfig = { serviceConfig = {
@ -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;
}; };
}; };
} }