From c529e3f6e939d5ce878d9f2709fe99726a8a98ae Mon Sep 17 00:00:00 2001 From: dolphinau Date: Sun, 23 Nov 2025 21:35:33 +0100 Subject: [PATCH] Init --- .gitignore | 22 +------------- README.md | 27 ++++++++++++++++- default.nix | 49 ++++++++++++++++++++++++++++++ setup.py | 8 +++++ src/secret_santa/__init__.py | 0 src/secret_santa/main.py | 59 ++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 22 deletions(-) create mode 100644 default.nix create mode 100644 setup.py create mode 100644 src/secret_santa/__init__.py create mode 100644 src/secret_santa/main.py diff --git a/.gitignore b/.gitignore index ad67955..b2be92b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1 @@ -# Generated by Cargo -# will have compiled files and executables -debug -target - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb - -# Generated by cargo mutants -# Contains mutation testing data -**/mutants.out*/ - -# RustRover -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +result diff --git a/README.md b/README.md index a9a2cfb..77f159f 100644 --- a/README.md +++ b/README.md @@ -1 +1,26 @@ -# secret-santa \ No newline at end of file +# secret-santa + +## Add command to nixos + +```nix +{ pkgs ? import { } }: + +let + secret-santa = + let + defaultNix = builtins.fetchurl { + url = "https://raw.githubusercontent.com/dolphinau/secret-santa/refs/heads/main/default.nix"; + sha256 = "1sihdgsg84kprycsg102rj9qnwd97zwx17x2wn42q4rmn918wvvx"; + }; + in pkgs.callPackage defaultNix { + src = pkgs.fetchFromGitHub { + owner = "dolphinau"; + repo = "secret-santa"; + rev = "a9b1f880d2fa50dbdff03a51b582deacb0972d90"; + sha256 = "sha256-v/fvJAlnMxMjlP6Z1cgHyKfno79yRSpKwY7pF0irISA="; + }; + }; + in [ + secret-santa + ] +``` diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..861e41d --- /dev/null +++ b/default.nix @@ -0,0 +1,49 @@ +{ pkgs ? import { }, src ? ./., subdir ? "" }: + +let + theSource = src; + pythonPackage = pkgs.python313Packages.buildPythonPackage { + pname = "secret-santa"; + version = "1.0.0"; + src = "${theSource}/${subdir}"; + buildInputs = [ + pkgs.python313Packages.setuptools + pkgs.python313Packages.wheel + ]; + propagatedBuildInputs = [ pkgs.python313Packages.flask ]; + + pyproject = true; + build-system = [ + pkgs.python313Packages.setuptools + pkgs.python313Packages.wheel + ]; + + meta = { + description = "Secret santa flask package"; + license = pkgs.lib.licenses.mit; + }; + }; + pythonEnv = pkgs.python313.buildEnv.override { + extraLibs = [ pkgs.python313Packages.flask pythonPackage ]; + ignoreCollisions = true; + }; +in +pkgs.stdenv.mkDerivation rec { + name = "secret-santa"; + propagatedBuildInputs = [ pythonEnv ]; + src = "${theSource}/${subdir}/src"; + + installPhase = '' + mkdir -p $out/bin + cat > $out/bin/${name} < ") + exit(1) + + try: + players = json.loads(open(out_path).read()) + except FileNotFoundError: + players = init(out_path) + + @app.route("/") + def get(name): + if name == "raphael": + return f"

Hello {name}!
Your secret santa target is {players[name]}
Eva's secret santa target is {players['eva']}

" + if name in players: + return ( + f"

Hello {name}!
Your secret santa target is {players[name]}

" + ) + else: + return f"

Error: Player {name} not found" + + app.run(debug=True)