Create home-manager module for hbs2-peer and hbs2-git-dashboard

This commit is contained in:
Andrei Borzenkov 2024-10-06 12:38:03 +04:00
parent 0b4c20d91b
commit 9640543924
No known key found for this signature in database
3 changed files with 115 additions and 0 deletions

View File

@ -142,6 +142,8 @@ Were using it for our non-public projects.
## How to install
### nix flakes
Assuming you know what the Nix and Nix flakes are ( See
[nixos.org](https://nixos.org) if you dont )
@ -158,6 +160,54 @@ Alternative option:
--substituters http://nix.hbs2.net:6000 \
--trusted-public-keys git.hbs2.net-1:HYIYU3xWetj0NasmHrxsWQTVzQUjawOE8ejZAW2xUS4=
### Home Manager module
The following snippet of code tries to show how to bring the HBS2 flake
from the flake input and use its packages with Home Manager.
Dont forget to replace exampleName with your username!
```nix
# flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
hbs2.url = "git+https://git.hbs2.net/BTThPdHKF8XnEq4m6wzbKHKA6geLFK4ydYhBXAqBdHSP";
};
outputs = {nixpkgs, home-manager, hbs2, ...}: {
homeConfigurations."exampleName" =
let system = "x86_64-linux"; # use your system here
in home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.${system};
modules = [
hbs2.homeManagerModules.${system}.default
{
services.hbs2 = {
enable = true;
git-dashboard.enable = true; # optional
};
}
# ...
];
};
};
}
```
Option `services.hbs2.enable` will add all hbs2 binaries into your environment and
create `hbs2-peer` user service to run it automatically at the background.
Option `services.hbs2.git-dashboard.enable` will create `hbs2-git-dashboard` user service.
## How to generate peers key?
hbs2 keyring-new > new-peer-key.key

View File

@ -116,6 +116,7 @@ outputs = { self, nixpkgs, flake-utils, ... }@inputs:
in {
legacyPackages = pkgs;
overlays.default = defaultOverlay;
homeManagerModules.default = import ./nix/hm-module.nix self;
packages =
packagesDynamic //

64
nix/hm-module.nix Normal file
View File

@ -0,0 +1,64 @@
self: {
config,
lib,
pkgs,
... }: let
inherit (pkgs.stdenv.hostPlatform) system;
package = self.packages.${system}.default;
cfg = config.services.hbs2;
hbs2 = cfg.package;
hbs2-peer = "${hbs2}/bin/hbs2-peer";
hbs2-git-dashboard = "${hbs2}/bin/hbs2-git-dashboard";
in {
options = {
services.hbs2 = {
enable = lib.mkEnableOption "hbs2-peer daemon";
package = lib.mkOption {
type = lib.types.package;
description = "Package with all HBS2 basic binaries";
default = package;
};
git-dashboard.enable = lib.mkEnableOption "hbs2-git-dashboard daemon";
};
};
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
systemd.user.services.hbs2-peer = {
Unit = {
Description = "HBS2 peer daemon";
After = [ "network.target" ];
};
Install = {
WantedBy = [ "default.target" ];
};
Service = {
ExecPreStart = "${hbs2-peer} init";
ExecStart = "${hbs2-peer} run";
Restart = "always";
RuntimeMaxSec = "1d";
};
};
systemd.user.services.hbs2-git-dashboard = lib.mkIf cfg.git-dashboard.enable {
Unit = {
Description = "HBS2 git dashboard daemon";
After = [ "hbs2-peer.service" "network.target" ];
BindsTo = [ "hbs2-peer.service" ];
};
Install = {
WantedBy = [ "default.target" ];
};
Service = {
ExecPreStart = "sleep 5";
ExecStart = "${hbs2-git-dashboard} web";
Environment = [ "PATH=${hbs2}/bin:${pkgs.git}/bin:$PATH" ]; # detectRPC require hbs2-peer to be in scope
Restart = "always";
RuntimeMaxSec = "1d";
};
};
};
}