nix: add package & NixOS module
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I5bfbacb984356f912f1f40d6209f0a896a6a6964
This commit is contained in:
parent
6e772ffefb
commit
d8f0bf3b09
4 changed files with 99 additions and 2 deletions
|
|
@ -10,9 +10,14 @@
|
||||||
pkgsForEach = nixpkgs.legacyPackages;
|
pkgsForEach = nixpkgs.legacyPackages;
|
||||||
in {
|
in {
|
||||||
packages = forEachSystem (system: {
|
packages = forEachSystem (system: {
|
||||||
default = pkgsForEach.${system}.callPackage ./nix/package.nix {};
|
pscand = pkgsForEach.${system}.callPackage ./nix/package.nix {};
|
||||||
|
default = self.packages.${system}.pscand;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
nixosModules = {
|
||||||
|
pscand = import ./nix/modules/nixos.nix self;
|
||||||
|
};
|
||||||
|
|
||||||
devShells = forEachSystem (system: {
|
devShells = forEachSystem (system: {
|
||||||
default = pkgsForEach.${system}.callPackage ./nix/shell.nix {};
|
default = pkgsForEach.${system}.callPackage ./nix/shell.nix {};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
38
nix/modules/nixos.nix
Normal file
38
nix/modules/nixos.nix
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
self: {
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit (lib.modules) mkIf;
|
||||||
|
inherit (lib.options) mkOption mkEnableOption;
|
||||||
|
inherit (lib.types) package;
|
||||||
|
|
||||||
|
cfg = config.services.pscand;
|
||||||
|
in {
|
||||||
|
options.services.pscand = {
|
||||||
|
enable = mkEnableOption "Pluggable System Condition Monitoring Daemon";
|
||||||
|
package = mkOption {
|
||||||
|
type = package;
|
||||||
|
default = self.packages.${pkgs.hostPlatform.system.pscand};
|
||||||
|
defaultText = "self.packages.$${pkgs.hostPlatform.system}.pscand";
|
||||||
|
description = "The pscand package to use";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
systemd.packages = [cfg.package];
|
||||||
|
|
||||||
|
systemd.services.pscand = {
|
||||||
|
wantedBy = ["multi-user.target"];
|
||||||
|
after = ["network.target"];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "simple";
|
||||||
|
ExecStart = "${cfg.package}/bin/pscand";
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = "5s";
|
||||||
|
Environment = ["${cfg.package}/lib/pscand/scanners"]; # FIXME: make this configurable
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
54
nix/package.nix
Normal file
54
nix/package.nix
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
rustPlatform,
|
||||||
|
makeWrapper,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
pname = "pscand";
|
||||||
|
version = "0.1.0";
|
||||||
|
src = let
|
||||||
|
fs = lib.fileset;
|
||||||
|
s = ../.;
|
||||||
|
in
|
||||||
|
lib.cleanSourceWith {
|
||||||
|
src = fs.toSource {
|
||||||
|
root = s;
|
||||||
|
fileset = fs.unions [
|
||||||
|
(s + /crates)
|
||||||
|
(s + /scanners)
|
||||||
|
(s + /Cargo.lock)
|
||||||
|
(s + /Cargo.toml)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
rustPlatform.buildRustPackage {
|
||||||
|
inherit pname version src;
|
||||||
|
cargoLock.lockFile = ../Cargo.lock;
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
makeWrapper
|
||||||
|
];
|
||||||
|
|
||||||
|
postFixup = let
|
||||||
|
scannerDir = "${placeholder "out"}/lib/pscand/scanners";
|
||||||
|
in ''
|
||||||
|
mkdir -p ${scannerDir}
|
||||||
|
for scanner in scanners/**/target/release/*.so; do
|
||||||
|
if [ -f "$scanner" ]; then
|
||||||
|
install -Dm755 "$scanner" "${scannerDir}/$(basename "$scanner")"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
wrapProgram "$out/bin/pscand" \
|
||||||
|
--set PSCAND_SCANNER_DIRS "${scannerDir}"
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
description = "Pluggable System Condition Monitoring Daemon";
|
||||||
|
homepage = "https://github.com/notashelf/pscand";
|
||||||
|
license = lib.licenses.mpl20;
|
||||||
|
maintainers = with lib.maintainers; [NotAShelf];
|
||||||
|
platforms = lib.platforms.linux;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
}:
|
}:
|
||||||
mkShell {
|
mkShell {
|
||||||
name = "rust";
|
name = "pscand";
|
||||||
|
|
||||||
strictDeps = true;
|
strictDeps = true;
|
||||||
packages = [
|
packages = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue