nicks_nextcloud_integrations/flake.nix

118 lines
3.8 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" ];
})
2023-08-20 18:49:58 -07:00
openssl
2023-08-20 18:07:42 -07:00
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-08-26 08:33:16 -07:00
cargoHash = "sha256-mMxHI/rU1Gd5UR+hZ+5+FnBrff8uF+SrEvGJT7wh5tI=";
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
};
});
};
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-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-08-25 23:03:12 -07:00
${cfg.package}/bin/status_cloud --hddtemp-executable ${pkgs.hddtemp}/bin/hddtemp --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" ];
timerConfig.OnCalendar = [ "*:0/15" ];
};
2023-08-20 18:07:42 -07:00
};
};
}