grzegorz/flake.nix

112 lines
3.2 KiB
Nix
Raw Normal View History

2022-08-27 22:27:55 +02:00
{
description = "A REST API for managing a MPV instance over via a RPC socket";
2023-08-17 20:39:22 +02:00
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2022-08-27 22:27:55 +02:00
2023-08-17 20:39:22 +02:00
outputs = {
self,
nixpkgs,
...
} @ inputs:
let
forSystems = systems: f: nixpkgs.lib.genAttrs systems (system: f rec {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.legacyPackages.${system}.lib;
});
forAllSystems = forSystems [
"x86_64-linux"
"aarch64-linux"
#"riscv64-linux"
];
in {
2022-08-27 22:27:55 +02:00
2023-08-17 20:39:22 +02:00
packages = forAllSystems ({ system, pkgs, ...}: rec {
2023-08-27 00:51:10 +02:00
sanic-ext = with pkgs.python3.pkgs; buildPythonPackage rec {
pname = "sanic-ext";
version = "23.6.0";
2023-08-17 20:39:22 +02:00
src = fetchPypi {
inherit pname version;
2023-08-27 00:51:10 +02:00
hash = "sha256-gd0Ta2t7ef2otP7CRE2YIjlFVXecKYqJFVxnKHoYSQI=";
2022-08-27 22:27:55 +02:00
};
2023-08-27 00:51:10 +02:00
propagatedBuildInputs = [ pyyaml ];
2023-08-17 20:39:22 +02:00
doCheck = false;
};
grzegorz = with pkgs.python3.pkgs; buildPythonPackage {
pname = "grzegorz";
version = (builtins.fromTOML (builtins.readFile ./pyproject.toml)).tool.poetry.version;
format = "pyproject";
src = ./.;
postInstall = ''
'';
nativeBuildInputs = [ poetry-core ];
2023-09-05 00:04:36 +02:00
propagatedBuildInputs = [ setuptools sanic sanic-ext yt-dlp mpv ];
2023-08-17 20:39:22 +02:00
doCheck = false;
};
grzegorz-run = pkgs.writeShellApplication {
name = "grzegorz-run";
2023-08-27 00:51:10 +02:00
runtimeInputs = [ (pkgs.python3.withPackages (ps: [ grzegorz ])) pkgs.mpv ];
2023-08-17 20:39:22 +02:00
text = ''
TOOMANYARGS=()
if test -z "$*"; then
>&2 echo "DEBUG: No args provided, running with defaults...."
TOOMANYARGS=("--host" "::" "--port" "8080")
fi
(
set -x
sanic grzegorz.app "''${TOOMANYARGS[@]}" "$@"
)
'';
};
2023-09-05 00:04:36 +02:00
default = grzegorz;
2023-08-17 20:39:22 +02:00
});
apps = forAllSystems ({ system, pkgs, ...}: {
default.type = "app";
default.program = "${self.packages.${system}.grzegorz-run}/bin/grzegorz-run";
});
2023-08-17 21:44:26 +02:00
nixosModules.grzegorz-kiosk = { config, pkgs, ... }: let
inherit (pkgs) lib;
cfg = config.services.grzegorz;
in {
options.services.grzegorz = {
enable = lib.mkEnableOption (lib.mdDoc "grzegorz");
package = lib.mkPackageOption self.packages.${config.nixpkgs.system} "grzegorz-run" { };
listenAddr = lib.mkOption {
type = lib.types.str;
default = "::";
};
listenPort = lib.mkOption {
type = lib.types.port;
default = 9090;
};
};
config = {
2023-08-27 01:05:41 +02:00
services.cage.enable = true;
services.cage.program = pkgs.writeShellScript "grzegorz-kiosk" ''
cd $(mktemp -d)
${(lib.escapeShellArgs [
"${cfg.package}/bin/grzegorz-run"
"--host" cfg.listenAddr
"--port" cfg.listenPort
])}
'';
services.cage.user = "grzegorz";
users.users."grzegorz".isNormalUser = true;
system.activationScripts = {
base-dirs = {
text = ''
mkdir -p /nix/var/nix/profiles/per-user/grzegorz
'';
deps = [];
2023-08-17 21:44:26 +02:00
};
};
};
};
2023-08-17 20:39:22 +02:00
};
2022-08-27 22:27:55 +02:00
}