nicks_nextcloud_integrations/flake.nix
2023-08-25 18:20:36 -07:00

111 lines
3.5 KiB
Nix

/*
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 ];
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" ];
})
openssl
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-GpAWrgFBzOTBCfZy/Ehy7IszuSgSOc/4N
2gbeed0jqI=";
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.
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 3001;
description = lib.mdDoc ''
The port at which to run.
'';
};
};
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;
after = [ "network.target" ];
wantedBy = [ "network.target" ];
serviceConfig = {
ExecStart = ''
${cfg.package}/bin/status_cloud --port ${builtins.toString cfg.port}
'';
Restart = "always";
DynamicUser = true;
};
};
};
};
}