nicks_nextcloud_integrations/flake.nix

184 lines
6.2 KiB
Nix
Raw Normal View History

2023-08-20 18:07:42 -07:00
/*
TODO
5. (optional) set your project homepage, license, and maintainers list on lines 48-51
6. (optional) uncomment the NixOS module and update it for your needs
7. Delete this comment block
*/
/*
Some utility commands:
- `nix flake update --commit-lock-file`
- `nix flake lock update-input <input>`
2023-08-25 18:20:36 -07:00
- `nix build .#nicks_nextcloud_integrations` or `nix build .`
- `nix run .#nicks_nextcloud_integrations` or `nix run .`
2023-08-20 18:07:42 -07:00
Updating `cargoHash`:
- Set `cargoHash` to an empty string
2023-08-25 18:20:36 -07:00
- run `nix run .#nicks_nextcloud_integrations`
2023-08-20 18:07:42 -07:00
- Update `cargoHash` with correct hash from output
rust-project TODO: write shell script for automatically updating `cargoHash`
*/
{
2023-08-25 18:20:36 -07:00
description = "A group of utilities Nick created to manage his server through nextcloud notes";
2023-08-20 18:07:42 -07:00
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, rust-overlay }:
let
overlays = [ (import rust-overlay) ];
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system overlays;
};
rustSettings = with pkgs; {
src = ./.;
2023-08-20 18:49:58 -07:00
nativeBuildInputs = [ pkg-config ];
2023-08-25 22:32:28 -07:00
buildInputs = [ openssl hddtemp ];
2023-08-20 18:07:42 -07:00
cargoHash = nixpkgs.lib.fakeHash;
};
meta = with nixpkgs.lib; {
#homepage = "https://example.com";
#license = [ licenses.gpl3 ];
platforms = [ system ];
#maintainers = with maintainers; [ ];
};
in {
devShells.${system}.default = with pkgs; mkShell {
packages = [
(pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
})
bacon
];
2023-08-25 18:20:36 -07:00
inputsFrom = with self.packages.${system}; [ status_cloud ];
2023-08-20 18:07:42 -07:00
};
packages.${system} = {
2023-08-25 18:20:36 -07:00
status_cloud = pkgs.rustPlatform.buildRustPackage (rustSettings // {
pname = "status_cloud";
2023-08-20 18:07:42 -07:00
version = "0.1.0";
2023-08-25 18:20:36 -07:00
buildAndTestSubdir = "status_cloud";
2023-09-09 18:44:05 -07:00
cargoHash = "sha256-JIiUtHqppZkOa77NRmu+e47JXwZZUluk3jPoJsAusas=";
2023-08-26 12:30:06 -07:00
preBuild = ''
2023-08-26 12:50:01 -07:00
sed -i 's/Command::new("hddtemp")/Command::new("${nixpkgs.lib.escape [ "/" ] "${pkgs.hddtemp}"}")/g' status_cloud/src/main.rs
2023-08-26 12:30:06 -07:00
'';
2023-08-20 18:07:42 -07:00
meta = meta // {
2023-08-25 18:20:36 -07:00
description = "Server status saved to a nextcloud note service.";
2023-08-20 18:07:42 -07:00
};
});
2023-09-09 18:12:39 -07:00
time_tracker = pkgs.rustPlatform.buildRustPackage (rustSettings // {
pname = "time_tracker";
version = "0.1.0";
buildAndTestSubdir = "time_tracker";
2023-09-09 18:44:05 -07:00
cargoHash = "sha256-b8qbOh7ATsQnswgFkbeES8VHGhs1OCYCcuyJ4m0bGMs=";
2023-09-09 18:12:39 -07:00
meta = meta // {
description = "Using nextcloud notes to track time usage.";
};
});
2023-08-20 18:07:42 -07:00
};
nixosModules.default = { config, ... }: let
lib = nixpkgs.lib;
in {
2023-08-25 18:20:36 -07:00
# status_cloud
options.services.status_cloud = {
enable = lib.mkEnableOption (lib.mdDoc "status_cloud service");
2023-08-20 18:07:42 -07:00
package = lib.mkOption {
type = lib.types.package;
2023-08-25 18:20:36 -07:00
default = self.packages.${system}.status_cloud;
defaultText = "pkgs.status_cloud";
2023-08-20 18:07:42 -07:00
description = lib.mdDoc ''
2023-08-25 18:20:36 -07:00
The status_cloud package that should be used.
2023-08-20 18:07:42 -07:00
'';
};
2023-08-25 20:11:27 -07:00
config_path = lib.mkOption {
type = lib.types.path;
2023-08-20 18:07:42 -07:00
description = lib.mdDoc ''
2023-08-25 20:11:27 -07:00
The file path to the toml that contains user information secrets
2023-08-20 18:07:42 -07:00
'';
};
2023-08-26 08:50:36 -07:00
frequency = lib.mkOption {
2023-08-26 08:52:26 -07:00
type = lib.types.int;
2023-08-26 08:50:36 -07:00
description = lib.mdDoc ''
The number of minutes to wait between updates
'';
};
2023-08-20 18:07:42 -07:00
};
2023-09-09 18:12:39 -07:00
2023-08-25 18:20:36 -07:00
config.systemd.services.status_cloud = let
cfg = config.services.status_cloud;
pkg = self.packages.${system}.status_cloud;
2023-08-20 18:07:42 -07:00
in lib.mkIf cfg.enable {
2023-08-25 21:34:34 -07:00
#description = pkg.meta.description;
description = "Status Cloud";
2023-08-20 18:07:42 -07:00
serviceConfig = {
2023-08-25 20:11:27 -07:00
Type = "oneshot";
2023-08-20 18:07:42 -07:00
ExecStart = ''
2023-09-09 18:12:39 -07:00
${cfg.package}/bin/status_cloud --config-file ${builtins.toString cfg.config_path}
2023-08-20 18:07:42 -07:00
'';
};
};
2023-08-25 20:11:27 -07:00
config.systemd.timers.status_cloud = let
cfg = config.services.status_cloud;
pkg = self.packages.${system}.status_cloud;
in lib.mkIf cfg.enable {
wantedBy = [ "timers.target" ];
partOf = [ "status_cloud.service" ];
2023-08-26 08:51:40 -07:00
timerConfig.OnCalendar = [ "*:0/${builtins.toString cfg.frequency}" ];
2023-08-25 20:11:27 -07:00
};
2023-09-09 18:12:39 -07:00
# Time Tracker
options.services.time_tracker = {
enable = lib.mkEnableOption (lib.mdDoc "time tracker service");
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${system}.time_tracker;
defaultText = "pkgs.time_tracker";
description = lib.mdDoc ''
The time_tracker package that should be used
'';
};
config_path = lib.mkOption {
type = lib.types.path;
2023-09-09 18:17:38 -07:00
description = lib.mkDoc ''
2023-09-09 18:12:39 -07:00
The file path to the toml that contains user information secrets
'';
};
frequency = lib.mkOption {
type = lib.types.int;
description = lib.mdDoc ''
The number of minutes to wait between updates
'';
};
};
config.systemd.services.time_tracker = let
cfg = config.services.time_tracker;
pkg = self.packages.${system}.time_tracker;
2023-09-09 19:15:15 -07:00
in lib.mkIf cfg.enable {
2023-09-09 18:12:39 -07:00
description = "Nextcloud Time Tracker";
serviceConfig = {
Type = "oneshot";
ExecStart = ''
${cfg.package}/bin/time_tracker --config-file ${builtins.toString cfg.config_path}
'';
};
};
2023-09-09 18:21:41 -07:00
config.systemd.timers.time_tracker = let
2023-09-09 18:12:39 -07:00
cfg = config.services.time_tracker;
pkg = self.packages.${system}.time_tracker;
in lib.mkIf cfg.enable {
wantedBy = [ "timers.target" ];
partOf = [ "time_tracker.service" ];
timerConfig.OnCalendar = [ "*:0/${builtins.toString cfg.frequency}" ];
};
2023-08-20 18:07:42 -07:00
};
};
}