diff --git a/flake.nix b/flake.nix index f7779f1..4c5b01b 100644 --- a/flake.nix +++ b/flake.nix @@ -3,32 +3,36 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; }; - outputs = {nixpkgs, ...}: let - lib = nixpkgs.lib; + outputs = { nixpkgs, ... }: + let + lib = nixpkgs.lib; - # Stolen from https://github.com/divnix/digga/blob/main/src/importers.nix - rakeLeaves = dirPath: let - seive = file: type: - # Only rake `.nix` files or directories - (type == "regular" && lib.hasSuffix ".nix" file) || (type == "directory"); + # Stolen from https://github.com/divnix/digga/blob/main/src/importers.nix + rakeLeaves = dirPath: + let + seive = file: type: + # Only rake `.nix` files or directories + (type == "regular" && lib.hasSuffix ".nix" file) || (type == "directory"); - collect = file: type: { - name = lib.removeSuffix ".nix" file; - value = let - path = dirPath + "/${file}"; + collect = file: type: { + name = lib.removeSuffix ".nix" file; + value = + let + path = dirPath + "/${file}"; + in + if + (type == "regular") + || (type == "directory" && builtins.pathExists (path + "/default.nix")) + then path + # recurse on directories that don't contain a `default.nix` + else rakeLeaves path; + }; + + files = lib.filterAttrs seive (builtins.readDir dirPath); in - if - (type == "regular") - || (type == "directory" && builtins.pathExists (path + "/default.nix")) - then path - # recurse on directories that don't contain a `default.nix` - else rakeLeaves path; - }; - - files = lib.filterAttrs seive (builtins.readDir dirPath); + lib.filterAttrs (n: v: v != { }) (lib.mapAttrs' collect files); in - lib.filterAttrs (n: v: v != {}) (lib.mapAttrs' collect files); - in { - nixosModules = rakeLeaves ./modules; - }; + { + nixosModules = rakeLeaves ./modules; + }; } diff --git a/modules/nixos-upgrade.nix b/modules/nixos-upgrade.nix index 79c8a40..9f01a4a 100644 --- a/modules/nixos-upgrade.nix +++ b/modules/nixos-upgrade.nix @@ -1,15 +1,15 @@ -{ - config, - lib, - pkgs, - ... -}: let +{ config +, lib +, pkgs +, ... +}: +let cfg = config.system.autoUpgrade; updateScript = pkgs.writeShellApplication { name = "update"; - runtimeInputs = with pkgs; [git nix]; + runtimeInputs = with pkgs; [ git nix ]; text = '' cd ${cfg.flake} @@ -19,7 +19,8 @@ git push ''; }; -in { +in +{ options.system.autoUpgrade = { # TODO: make sure system.autoUpgrade.flake is a local folder updateFlake = lib.mkOption { @@ -51,10 +52,10 @@ in { config.systemd.services = lib.mkIf cfg.enable { nixos-upgrade.serviceConfig.ExecStartPre = lib.mkIf cfg.updateFlake - (lib.getExe updateScript); + (lib.getExe updateScript); nixos-upgrade-failure = lib.mkIf cfg.failureNotification.enable { - path = with pkgs; ["/run/wrappers" "/run/current-system/sw" curl]; + path = with pkgs; [ "/run/wrappers" "/run/current-system/sw" curl ]; script = '' journalctl _SYSTEMD_INVOCATION_ID=`systemctl show --value -p InvocationID nixos-upgrade.service` > /tmp/upgrade-failure.txt curl -T /tmp/upgrade-failure.txt -H "Filename: failure-logs.txt" -H "Title: Nixos auto upgrade failed for $(hostname)" $NTFY_URL @@ -67,6 +68,6 @@ in { }; }; - nixos-upgrade.onFailure = lib.mkIf cfg.failureNotification.enable ["nixos-upgrade-failure.service"]; + nixos-upgrade.onFailure = lib.mkIf cfg.failureNotification.enable [ "nixos-upgrade-failure.service" ]; }; } diff --git a/modules/qbittorrent-nox.nix b/modules/qbittorrent-nox.nix index 900cd3f..749c6d2 100644 --- a/modules/qbittorrent-nox.nix +++ b/modules/qbittorrent-nox.nix @@ -1,15 +1,16 @@ -{ - config, - pkgs, - lib, - ... -}: let +{ config +, pkgs +, lib +, ... +}: +let cfg = config.services.qbittorrent-nox; -in { +in +{ options.services.qbittorrent-nox = { enable = lib.mkEnableOption "qbittorrent, BitTorrent client."; - package = lib.mkPackageOption pkgs "qbittorrent-nox" {}; + package = lib.mkPackageOption pkgs "qbittorrent-nox" { }; openFirewall = lib.mkOption { default = false; @@ -42,13 +43,13 @@ in { systemd = { services.qbittorrent-nox = { description = "qbittorrent BitTorrent client"; - wants = ["network-online.target"]; + wants = [ "network-online.target" ]; after = [ "local-fs.target" "network-online.target" "nss-lookup.target" ]; - wantedBy = ["multi-user.target"]; + wantedBy = [ "multi-user.target" ]; # Needed for running cross-seed's hook # /bin/sh -c "curl -XPOST http://localhost:2468/api/webhook --data-urlencode 'name=%N'" @@ -87,7 +88,7 @@ in { MemoryDenyWriteExecute = true; SystemCallArchitectures = "native"; CapabilityBoundingSet = ""; - SystemCallFilter = ["@system-service"]; + SystemCallFilter = [ "@system-service" ]; }; }; }; diff --git a/modules/unpackerr.nix b/modules/unpackerr.nix index c228303..3129582 100644 --- a/modules/unpackerr.nix +++ b/modules/unpackerr.nix @@ -1,14 +1,15 @@ -{ - config, - lib, - pkgs, - ... -}: let +{ config +, lib +, pkgs +, ... +}: +let cfg = config.services.unpackerr; -in { +in +{ options.services.unpackerr = { enable = lib.mkEnableOption "unpackerr"; - package = lib.mkPackageOption pkgs "unpackerr" {}; + package = lib.mkPackageOption pkgs "unpackerr" { }; user = lib.mkOption { type = lib.types.str; @@ -23,7 +24,7 @@ in { }; settings = lib.mkOption { - default = {}; + default = { }; description = "unpackerr config file"; }; @@ -43,7 +44,7 @@ in { User = cfg.user; Group = cfg.group; ProtectHome = "yes"; - DeviceAllow = [""]; + DeviceAllow = [ "" ]; LockPersonality = true; MemoryDenyWriteExecute = true; PrivateDevices = true; @@ -63,7 +64,7 @@ in { EnvironmentFile = cfg.environmentFile; }; - wantedBy = ["default.target"]; + wantedBy = [ "default.target" ]; }; }; };