Initial commit

This commit is contained in:
Aleksandr 2025-10-07 01:16:35 +03:00
commit c826b8a819
15 changed files with 4417 additions and 0 deletions

115
nix/flake.lock generated Normal file
View file

@ -0,0 +1,115 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1758758545,
"narHash": "sha256-NU5WaEdfwF6i8faJ2Yh+jcK9vVFrofLcwlD/mP65JrI=",
"owner": "ipetkov",
"repo": "crane",
"rev": "95d528a5f54eaba0d12102249ce42f4d01f4e364",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1746858783,
"narHash": "sha256-oLrH70QIWB/KpaI+nztyP1hG4zAEEpMiNk6sA8QLQ/8=",
"owner": "nix-community",
"repo": "fenix",
"rev": "4e3cd098060cca21f2a213ce8c086948df946940",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1746663147,
"narHash": "sha256-Ua0drDHawlzNqJnclTJGf87dBmaO/tn7iZ+TCkTRpRc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "dda3dcd3fe03e991015e9a74b22d35950f264a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": {
"inputs": {
"crane": "crane",
"fenix": "fenix",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1746722075,
"narHash": "sha256-t4ZntWiW4C3lE621lV3XyK3KltC5/SW1V9G+CSz70rQ=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "8b624868e4ce2cb5b39559175f0978bee86bdeea",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

50
nix/flake.nix Normal file
View file

@ -0,0 +1,50 @@
{
inputs = {
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/nixos-unstable";
crane.url = "github:ipetkov/crane";
};
outputs = { flake-utils, fenix, nixpkgs, crane, ... }:
flake-utils.lib.eachDefaultSystem(system:
let
overlays = [ fenix.overlays.default ];
pkgs = import nixpkgs { inherit system overlays; };
rust = with pkgs.fenix; combine [
((fromToolchainName { name = "1.89"; sha256 = "sha256-+9FmLhAOezBZCOziO0Qct1NOrfpjNsXxc/8I0c7BdKE="; }).withComponents [
"cargo"
"rustc"
"rust-src"
"rust-analyzer"
"clippy"
"llvm-tools-preview"
])
default.rustfmt
];
llvm = pkgs.llvmPackages_20;
package = import ./package.nix { inherit crane rust pkgs; };
in
{
devShells.default = pkgs.mkShell.override {
stdenv = pkgs.llvmPackages_20.stdenv;
} {
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
packages = [ rust ] ++ (with pkgs; [
libclang.lib
]);
buildInputs = with pkgs; [
stdenv.cc.cc.lib
];
};
nixosModules.default = import ./module.nix { maid = package; };
packages.maid = package;
packages.default = package;
}
);
}

63
nix/module.nix Normal file
View file

@ -0,0 +1,63 @@
{ makise-next, }:
{ config, lib, pkgs, ... }:
let
types = lib.types;
cfg = config.services.makise-next;
toml = pkgs.formats.toml {};
configs = let generated = (if cfg.config != null then [(toml.generate "config.toml" cfg.config)] else []);
all = generated ++ cfg.configFiles;
in builtins.map (x: "--config ${x}") all;
configParameters = lib.strings.concatStringsSep " " configs;
in
{
options.services.viendesu-maid = {
autoStart = lib.mkOption {
description = "start Maid with the system";
type = types.bool;
default = false;
};
user = lib.mkOption {
description = "user under which Maid will run";
type = types.str;
};
enable = lib.mkEnableOption "viendesu-maid";
config = lib.mkOption {
description = "configuration for the Maid";
type = types.nullOr types.attrs;
default = null;
};
configFiles = lib.mkOption {
description = "list of configuration files for Maid";
type = types.listOf types.str;
default = [];
};
environment = lib.mkOption {
description = "list of environment variables";
type = types.attrs;
default = {};
};
environmentFiles = lib.mkOption {
description = "environment variables files";
type = types.listOf types.str;
default = [];
};
};
config = {
systemd.services.viendesu-maid = lib.mkIf cfg.enable {
wantedBy = lib.mkIf cfg.autoStart [ "multi-user.target" ];
after = [ "network.target" ];
description = "VienDesu! Maid bot";
serviceConfig = {
Type = "simple";
User = cfg.user;
ExecStart = "${makise-next} ${configParameters}";
EnvironmentFile = cfg.environmentFiles;
Environment = builtins.map ({ name, value }: "${name}=${value}")
(lib.attrsets.attrsToList cfg.environment);
};
};
};
}

15
nix/package.nix Normal file
View file

@ -0,0 +1,15 @@
{ pkgs, rust, crane }:
let
craneLib = (crane.mkLib pkgs).overrideToolchain (p: rust);
src = craneLib.cleanCargoSource ../.;
common = {
inherit src;
strictDeps = true;
};
cargoArtifacts = craneLib.buildDepsOnly common;
in
craneLib.buildPackage (common // {
inherit cargoArtifacts;
})