Want to contribute? Fork me on Codeberg.org!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.1 KiB

/*
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>`
- `nix build .#nicks_nextcloud_integrations` or `nix build .`
- `nix run .#nicks_nextcloud_integrations` or `nix run .`
Updating `cargoHash`:
- Set `cargoHash` to an empty string
- run `nix run .#nicks_nextcloud_integrations`
- Update `cargoHash` with correct hash from output
rust-project TODO: write shell script for automatically updating `cargoHash`
*/
{
description = "A group of utilities Nick created to manage his server through nextcloud notes";
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 = ./.;
nativeBuildInputs = [ pkg-config ];
buildInputs = [ openssl hddtemp ];
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
];
inputsFrom = with self.packages.${system}; [ status_cloud ];
};
packages.${system} = {
status_cloud = pkgs.rustPlatform.buildRustPackage (rustSettings // {
pname = "status_cloud";
version = "0.1.0";
buildAndTestSubdir = "status_cloud";
cargoHash = "sha256-mMxHI/rU1Gd5UR+hZ+5+FnBrff8uF+SrEvGJT7wh5tI=";
preBuild = ''
sed -i 's/Command::new("hddtemp")/Command::new("${nixpkgs.lib.escape [ "/" ] "${pkgs.hddtemp}"}")/g' status_cloud/src/main.rs
'';
meta = meta // {
description = "Server status saved to a nextcloud note service.";
};
});
};
nixosModules.default = { config, ... }: let
lib = nixpkgs.lib;
in {
# status_cloud
options.services.status_cloud = {
enable = lib.mkEnableOption (lib.mdDoc "status_cloud service");
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${system}.status_cloud;
defaultText = "pkgs.status_cloud";
description = lib.mdDoc ''
The status_cloud package that should be used.
'';
};
config_path = lib.mkOption {
type = lib.types.path;
description = lib.mdDoc ''
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.status_cloud = let
cfg = config.services.status_cloud;
pkg = self.packages.${system}.status_cloud;
in lib.mkIf cfg.enable {
#description = pkg.meta.description;
description = "Status Cloud";
serviceConfig = {
Type = "oneshot";
ExecStart = ''
${cfg.package}/bin/status_cloud --config-file ${builtins.toString cfg.config_path}
'';
};
};
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" ];
timerConfig.OnCalendar = [ "*:0/${builtins.toString cfg.frequency}" ];
};
};
};
}