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

1 year ago
/*
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 .`
1 year ago
Updating `cargoHash`:
- Set `cargoHash` to an empty string
- run `nix run .#nicks_nextcloud_integrations`
1 year ago
- 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";
1 year ago
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 ];
1 year ago
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 ];
1 year ago
};
packages.${system} = {
status_cloud = pkgs.rustPlatform.buildRustPackage (rustSettings // {
pname = "status_cloud";
1 year ago
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
'';
1 year ago
meta = meta // {
description = "Server status saved to a nextcloud note service.";
1 year ago
};
});
};
nixosModules.default = { config, ... }: let
lib = nixpkgs.lib;
in {
# status_cloud
options.services.status_cloud = {
enable = lib.mkEnableOption (lib.mdDoc "status_cloud service");
1 year ago
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${system}.status_cloud;
defaultText = "pkgs.status_cloud";
1 year ago
description = lib.mdDoc ''
The status_cloud package that should be used.
1 year ago
'';
};
config_path = lib.mkOption {
type = lib.types.path;
1 year ago
description = lib.mdDoc ''
The file path to the toml that contains user information secrets
1 year ago
'';
};
frequency = lib.mkOption {
1 year ago
type = lib.types.int;
description = lib.mdDoc ''
The number of minutes to wait between updates
'';
};
1 year ago
};
config.systemd.services.status_cloud = let
cfg = config.services.status_cloud;
pkg = self.packages.${system}.status_cloud;
1 year ago
in lib.mkIf cfg.enable {
#description = pkg.meta.description;
description = "Status Cloud";
1 year ago
serviceConfig = {
Type = "oneshot";
1 year ago
ExecStart = ''
${cfg.package}/bin/status_cloud --config-file ${builtins.toString cfg.config_path}
1 year ago
'';
};
};
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" ];
1 year ago
timerConfig.OnCalendar = [ "*:0/${builtins.toString cfg.frequency}" ];
};
1 year ago
};
};
}