/* 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 ` - `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 ]; # move makeWrapper to nativeBuildInputs buildInputs = [ openssl hddtemp msmtp makeWrapper ]; 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-mXcD/92WJLgN2efX/8EiV3rOqUiNOKGC4puS8DvGFOc="; postFixup = '' wrapProgram $out/bin/status_cloud \ --prefix PATH : "${nixpkgs.lib.makeBinPath [ pkgs.hddtemp ]}" ''; meta = meta // { description = "Server status saved to a nextcloud note service."; }; }); chrono_track = pkgs.rustPlatform.buildRustPackage (rustSettings // { pname = "chrono_track"; version = "0.1.0"; buildAndTestSubdir = "chrono_track"; cargoHash = "sha256-51j5eG2ZBJg2TjbvYSEvvmOM4hhPyNohN+LUmvck88k="; meta = meta // { description = "Using nextcloud notes to track time usage."; }; postFixup = '' wrapProgram $out/bin/chrono_track \ --prefix PATH : "${nixpkgs.lib.makeBinPath [ pkgs.msmtp ]}" ''; }); }; 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}" ]; }; # Time Tracker options.services.chrono_track = { enable = lib.mkEnableOption (lib.mdDoc "chrono track, time tracking service"); package = lib.mkOption { type = lib.types.package; default = self.packages.${system}.chrono_track; defaultText = "pkgs.chrono_track"; description = lib.mdDoc '' The chrono_track package that should be used ''; }; config_path = lib.mkOption { type = lib.types.path; description = lib.mkDoc '' The file path to the toml that contains user information secrets ''; }; from_address = lib.mkOption { type = lib.types.str; description = lib.mdDoc '' The from address for the emails. E.g. noreply@example.com ''; }; frequency = lib.mkOption { type = lib.types.int; description = lib.mdDoc '' The number of minutes to wait between updates ''; }; }; config.systemd.services.chrono_track = let cfg = config.services.chrono_track; pkg = self.packages.${system}.chrono_track; in lib.mkIf cfg.enable { description = "Chrono Track"; serviceConfig = { Type = "oneshot"; ExecStart = '' ${cfg.package}/bin/chrono_track --config-file ${builtins.toString cfg.config_path} --from-addr ${cfg.from_address} ''; }; }; config.systemd.timers.chrono_track = let cfg = config.services.chrono_track; pkg = self.packages.${system}.chrono_track; in lib.mkIf cfg.enable { wantedBy = [ "timers.target" ]; partOf = [ "chrono_track.service" ]; timerConfig.OnCalendar = [ "*:0/${builtins.toString cfg.frequency}" ]; }; }; }; }