vroom vroom

This commit is contained in:
Peder Bergebakken Sundt 2023-08-17 20:39:22 +02:00
parent 1497e3e679
commit 59fffe853a
4 changed files with 73 additions and 121 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
__pycache__
config.py
*.socket
result
result-*

View File

@ -1,89 +1,24 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1661621241,
"narHash": "sha256-qUsCgbZNM9b8yOV2XWB//0/qUduDAnbB9WFXr8XzWB0=",
"lastModified": 1692174805,
"narHash": "sha256-xmNPFDi/AUMIxwgOH/IVom55Dks34u1g7sFKKebxUm0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f214afa5fb6452900e27776735db21f5092261b8",
"rev": "caac0eb6bdcad0b32cb2522e03e4002c8975c62e",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1661621241,
"narHash": "sha256-qUsCgbZNM9b8yOV2XWB//0/qUduDAnbB9WFXr8XzWB0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f214afa5fb6452900e27776735db21f5092261b8",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"poetry2nix": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1661298951,
"narHash": "sha256-R4zRiXIYic14aNJGuWvBZBblyt6I0GNzgBEQAXhchf4=",
"owner": "nix-community",
"repo": "poetry2nix",
"rev": "e1e95bbf61be2d150613f5e0560d70c4b316ba4a",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "poetry2nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"poetry2nix": "poetry2nix"
"nixpkgs": "nixpkgs"
}
}
},

111
flake.nix
View File

@ -1,55 +1,70 @@
{
description = "A REST API for managing a MPV instance over via a RPC socket";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
inputs.poetry2nix.url = "github:nix-community/poetry2nix";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs, flake-utils, poetry2nix }:
{
# Nixpkgs overlay providing the application
overlay = nixpkgs.lib.composeManyExtensions [
poetry2nix.overlay
(final: prev: {
# The application
grzegorz = prev.poetry2nix.mkPoetryApplication {
projectDir = ./.;
};
})
];
} // (flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
};
entrypoint = pkgs.writeShellApplication {
name = "grzegorz-run";
runtimeInputs = [
pkgs.grzegorz
pkgs.mpv
];
text = ''
SPIS_MEG=()
if test -z "$*"; then
>&2 echo "DEBUG: No args provided, running with defaults...."
SPIS_MEG=("--host" "::" "--port" "8080")
fi
(
set -x
sanic grzegorz.app "''${SPIS_MEG[@]}" "$@"
)
'';
};
in {
packages = {
inherit (pkgs) grzegorz;
grzegorz-run = entrypoint;
};
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 {
apps = {
default.type = "app";
default.program = "${entrypoint}/bin/grzegorz-run";
packages = forAllSystems ({ system, pkgs, ...}: rec {
sanic-openapi = with pkgs.python3.pkgs; buildPythonPackage rec {
pname = "sanic-openapi";
version = "21.12.0";
src = fetchPypi {
inherit pname version;
hash = "sha256-fNpiI00IyWX3OeqsawWejyRNhwYdlzNcVyh/1q4Wv1I=";
};
}));
propagatedBuildInputs = [ sanic pyyaml ];
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 ];
propagatedBuildInputs = [ sanic sanic-openapi youtube-dl mpv ];
doCheck = false;
};
grzegorz-run = pkgs.writeShellApplication {
name = "grzegorz-run";
runtimeInputs = [ grzegorz pkgs.mpv ];
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[@]}" "$@"
)
'';
};
});
apps = forAllSystems ({ system, pkgs, ...}: {
default.type = "app";
default.program = "${self.packages.${system}.grzegorz-run}/bin/grzegorz-run";
});
};
}

View File

@ -7,10 +7,10 @@ license = "MIT"
[tool.poetry.dependencies]
python = ">=3.7,<4.0"
mpv = "^0.1" # TODO: do we use this?
mpv = ">=0.1" # TODO: do we use this?
youtube_dl = "^2021.12.17"
sanic = "^21.12.2"
sanic-openapi = "^21.6.1"
sanic = ">=21.12.2"
sanic-openapi = ">=21.6.1"
[tool.poetry.dev-dependencies]
python-lsp-server = {extras = ["all"], version = "^1.3.3"}