get nixed

This commit is contained in:
Peder Bergebakken Sundt 2023-08-17 21:45:27 +02:00
parent 63de4be667
commit 42274851d4
6 changed files with 799 additions and 482 deletions

15
.envrc
View File

@ -2,7 +2,20 @@
# This file is loaded with `direnv`.
# It enters you into the poetry venv, removing the need for `poetry run`.
poetry run true # create venv if it doesn't exist
if command -v nix >/dev/null; then
use nix -p poetry
fi
# Instead of using the flake, we use poetry to manage a development venv
# We only use poetry2nix for deployment
# create venv if it doesn't exist
poetry run true
# enter venv
export VIRTUAL_ENV=$(poetry env info --path)
export POETRY_ACTIVE=1
PATH_add "$VIRTUAL_ENV/bin"
if ! command -v sanic >/dev/null; then
poetry install
fi

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
__pycache__/
*.pyc
result
result-*

48
flake.lock Normal file
View File

@ -0,0 +1,48 @@
{
"nodes": {
"grzegorz": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1692297562,
"narHash": "sha256-QdFaVJdLS7vj6quN4DkWQYv297fNJIHeYvoidzaxcUg=",
"owner": "Programvareverkstedet",
"repo": "grzegorz",
"rev": "59fffe853a6d3385c2967a65455c336fb6d7f92c",
"type": "github"
},
"original": {
"owner": "Programvareverkstedet",
"repo": "grzegorz",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1692174805,
"narHash": "sha256-xmNPFDi/AUMIxwgOH/IVom55Dks34u1g7sFKKebxUm0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "caac0eb6bdcad0b32cb2522e03e4002c8975c62e",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"grzegorz": "grzegorz",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

122
flake.nix Normal file
View File

@ -0,0 +1,122 @@
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = {
self,
nixpkgs,
...
} @ inputs:
let
flake = inputs: system: nixpkgs.lib.mapAttrs (name: flake: {
# TODO filter non-flake inputs
nixos = flake.nixosModules
or null;
pkgs = flake.packages.${system}
or flake.legacyPackages.${system}
or null;
lib = flake.lib.${system}
or flake.lib
or null;
}) inputs;
forSystems = systems: f: nixpkgs.lib.genAttrs systems (system: f rec {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.legacyPackages.${system}.lib;
flakes = flake inputs system;
});
forAllSystems = forSystems [
"x86_64-linux"
"aarch64-linux"
#"riscv64-linux"
];
in {
packages = forAllSystems ({ pkgs, flakes, ...}: {
remi = with pkgs.python3.pkgs; buildPythonPackage rec {
pname = "remi";
version = "1.0";
src = fetchPypi {
inherit pname version;
hash = "sha256-65qc+td/mk/RSUcRWbPGVbS9S0F1o1S9zIkJb0Ek2eQ=";
extension = "zip";
};
};
grzegorz-clients = with pkgs.python3.pkgs; buildPythonPackage {
pname = "grzegorz-clients";
version = (builtins.fromTOML (builtins.readFile ./pyproject.toml)).tool.poetry.version;
format = "pyproject";
src = ./.;
nativeBuildInputs = [ poetry-core ];
propagatedBuildInputs = [ setuptools youtube-dl flakes.self.pkgs.remi requests typer urllib3 ];
};
default = flakes.self.pkgs.grzegorz-clients;
});
apps = forAllSystems ({ system, ...}: rec {
grzegorz-webui.type = "app";
grzegorz-webui.program = "${self.packages.${system}.grzegorz-clients}/bin/grzegorz-webui";
default = grzegorz-webui;
});
nixosModules.grzegorz-webui = { config, pkgs, ... }: let
inherit (pkgs) lib;
cfg = config.services.grzegorz-webui;
in {
options.services.grzegorz-webui = {
enable = lib.mkEnableOption (lib.mdDoc "grzegorz");
package = lib.mkPackageOption self.packages.${config.nixpkgs.system} "grzegorz-clients" { };
listenAddr = lib.mkOption {
type = lib.types.str;
default = "::";
};
listenPort = lib.mkOption {
type = lib.types.port;
default = 8080;
};
/** /
listenWebsocketPort = lib.mkOption {
type = lib.types.port;
default = 0;
};
/**/
multipleInstance = lib.mkOption {
type = lib.types.bool;
default = false;
};
apiBase = lib.mkOption {
type = lib.types.str;
default = "https://brzeczyszczykiewicz.pvv.ntnu.no/api";
};
};
config = {
systemd.services.grzegorz-webui = lib.mkIf cfg.enable {
description = "grzegorz-webui";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = "grzegorz-webui";
Group = "grzegorz-webui";
DynamicUser = true;
#StateDirectory = "grzegorz-webui";
#CacheDirectory = "grzegorz-webui";
ExecStart = escapeShellArgs [
"${pkgs.gregorz-clients}/bin/gregorz-webui"
"--address" cfg.listenAddr
"--port" cfg.listenPort
"--api-base" cfg.apiBase
#"--websocket-port" cfg.listenWebsocketPort
"--multiple-instance" cfg.multipleInstance
];
Restart = "on-failure";
};
};
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.listenPort ];
};
};
};
};
}

1088
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,13 +8,13 @@ license = "MIT"
[tool.poetry.dependencies]
python = ">=3.7,<4.0"
youtube_dl = ">=2021.12.17"
remi = {url = "https://github.com/dddomodossola/remi/archive/v1.0.tar.gz"}
remi = "1.0"
requests = ">=2.27.1,<3"
typer = "^0.4.0"
typer = ">=0.4.0"
urllib3 = "^1.26.8"
[tool.poetry.dev-dependencies]
python-lsp-server = {extras = ["all"], version = "^1.3.3"}
python-lsp-server = {extras = ["all"], version = "^1.5.0"}
[tool.poetry.scripts]
grzegorz-webui = "grzegorz_clients.__main__:cli"