scanbuddy/flake.nix

98 lines
2.4 KiB
Nix
Raw Normal View History

2025-09-25 17:42:36 +02:00
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2025-09-27 15:51:47 +02:00
pyproject-nix = {
url = "github:nix-community/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
2025-09-25 17:42:36 +02:00
};
outputs = {
self,
nixpkgs,
2025-09-27 15:51:47 +02:00
...
2025-09-25 17:42:36 +02:00
} @ inputs: let
system = "x86_64-linux";
2025-09-26 00:26:43 +02:00
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
2025-09-27 15:51:47 +02:00
python = pkgs.python3;
serverProject = inputs.pyproject-nix.lib.project.loadPyproject {
projectRoot = ./.;
2025-09-26 00:26:43 +02:00
};
2025-09-27 18:54:24 +02:00
# Packages
script = pkgs.writeShellApplication {
name = "scanbuddy";
runtimeInputs = with pkgs; [sane-backends brscan5 ghostscript];
2025-09-27 22:26:10 +02:00
text = builtins.readFile ./scanbuddy.sh;
2025-09-27 18:54:24 +02:00
};
# Returns an attribute set that can be passed to `buildPythonPackage`.
attrs = serverProject.renderers.buildPythonPackage {inherit python;};
server = python.pkgs.buildPythonPackage (attrs
// {
env.CUSTOM_ENVVAR = "foobar";
});
scanbuddy-pkg = pkgs.symlinkJoin {
name = "scanbuddy";
paths = [script server];
};
2025-09-27 15:51:47 +02:00
in {
# devShells.${system}.default = pkgs.mkShell {
# packages = with pkgs; [
# python313
# python313Packages.flask
# python313Packages.waitress
# ];
#
# shellHook = ''
# python --version
# exec zsh
# '';
# };
2025-09-27 18:54:24 +02:00
packages.${system} = {
default = scanbuddy-pkg;
inherit script;
inherit server;
};
2025-09-26 00:26:43 +02:00
2025-09-27 18:54:24 +02:00
nixosModules.default = {
config,
pkgs,
lib,
...
}: {
2025-09-27 22:26:10 +02:00
options = let
inherit (lib) mkOption mkEnableOption types;
in {
services.scanbuddy = {
enable = mkEnableOption "Enable the scanbuddy server";
environment = mkOption {
type = types.attrsOf (types.nullOr (types.oneOf [types.str types.path types.package]));
default = {};
};
};
2025-09-26 00:26:43 +02:00
};
2025-09-27 22:26:10 +02:00
config = let
cfg = config.services.scanbuddy;
in {
2025-09-27 18:54:24 +02:00
systemd.services.scanbuddy = lib.mkIf config.service.scanbuddy {
description = "The scanbuddy webservice";
wantedBy = ["multi-user.target"];
serviceConfig = {
ExecStart = "${scanbuddy-pkg}/bin/scanbuddy-server";
Path = ["${scanbuddy-pkg}/bin"];
WorkingDirectory = "/var/lib/scanbuddy";
2025-09-27 22:27:56 +02:00
Type = "simple";
2025-09-27 18:54:24 +02:00
};
2025-09-27 22:26:10 +02:00
environment = cfg.environment;
2025-09-27 18:54:24 +02:00
};
2025-09-26 00:26:43 +02:00
};
2025-09-25 17:42:36 +02:00
};
};
}