From 71629c7966005a32e90f69d9cbdc672cd00e1fdb Mon Sep 17 00:00:00 2001
From: dadada <dadada@dadada.li>
Date: Mon, 1 Jan 2024 17:20:58 +0100
Subject: [PATCH] overlays: add recipemd

Remove unused overlays
---
 flake.lock               | 78 +++-------------------------------------
 flake.nix                | 22 +-----------
 home/pkgs.nix            |  1 +
 nixos/configurations.nix | 10 ++----
 outputs.nix              |  1 -
 overlays.nix             | 11 ++++++
 pkgs/recipemd.nix        | 58 ++++++++++++++++++++++++++++++
 7 files changed, 77 insertions(+), 104 deletions(-)
 create mode 100644 pkgs/recipemd.nix

diff --git a/flake.lock b/flake.lock
index 2839e8d..5ff9084 100644
--- a/flake.lock
+++ b/flake.lock
@@ -9,16 +9,16 @@
         ]
       },
       "locked": {
-        "lastModified": 1694733633,
-        "narHash": "sha256-/o/OubAsPMbxqru59tLlWzUI7LBNDaoW4rFwQ2Smxcg=",
+        "lastModified": 1703089996,
+        "narHash": "sha256-ipqShkBmHKC9ft1ZAsA6aeKps32k7+XZSPwfxeHLsAU=",
         "owner": "ryantm",
         "repo": "agenix",
-        "rev": "54693c91d923fecb4cf04c4535e3d84f8dec7919",
+        "rev": "564595d0ad4be7277e07fa63b5a991b3c645655d",
         "type": "github"
       },
       "original": {
         "owner": "ryantm",
-        "ref": "0.14.0",
+        "ref": "0.15.0",
         "repo": "agenix",
         "type": "github"
       }
@@ -162,26 +162,6 @@
         "type": "github"
       }
     },
-    "naersk": {
-      "inputs": {
-        "nixpkgs": [
-          "nixpkgs"
-        ]
-      },
-      "locked": {
-        "lastModified": 1698420672,
-        "narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=",
-        "owner": "nix-community",
-        "repo": "naersk",
-        "rev": "aeb58d5e8faead8980a807c840232697982d47b9",
-        "type": "github"
-      },
-      "original": {
-        "owner": "nix-community",
-        "repo": "naersk",
-        "type": "github"
-      }
-    },
     "nixlib": {
       "locked": {
         "lastModified": 1693701915,
@@ -250,30 +230,6 @@
         "type": "github"
       }
     },
-    "recipemd": {
-      "inputs": {
-        "flake-utils": [
-          "flake-utils"
-        ],
-        "nixpkgs": [
-          "nixpkgs"
-        ]
-      },
-      "locked": {
-        "lastModified": 1647022391,
-        "narHash": "sha256-TZih8S/GGmmONaEZchFw0sFS6U9pa+BjaGzNUf1ahi4=",
-        "owner": "dadada",
-        "repo": "recipemd",
-        "rev": "ef3ce521ce4fdc4e2cedb92102433c8a0a9d0335",
-        "type": "github"
-      },
-      "original": {
-        "owner": "dadada",
-        "ref": "nix-flake",
-        "repo": "recipemd",
-        "type": "github"
-      }
-    },
     "root": {
       "inputs": {
         "agenix": "agenix",
@@ -282,39 +238,13 @@
         "flake-utils": "flake-utils",
         "home-manager": "home-manager_2",
         "homePage": "homePage",
-        "naersk": "naersk",
         "nixos-generators": "nixos-generators",
         "nixos-hardware": "nixos-hardware",
         "nixpkgs": "nixpkgs",
-        "recipemd": "recipemd",
-        "rust-overlay": "rust-overlay",
         "systems": "systems",
         "treefmt-nix": "treefmt-nix"
       }
     },
-    "rust-overlay": {
-      "inputs": {
-        "flake-utils": [
-          "flake-utils"
-        ],
-        "nixpkgs": [
-          "nixpkgs"
-        ]
-      },
-      "locked": {
-        "lastModified": 1703384182,
-        "narHash": "sha256-g5K8bFBCIQ3x/j/MFTpkZo4It5SGWPwhBp/lASiy+pA=",
-        "owner": "oxalica",
-        "repo": "rust-overlay",
-        "rev": "cb6395cb3c2f69ad028914c90bce833e51d339c9",
-        "type": "github"
-      },
-      "original": {
-        "owner": "oxalica",
-        "repo": "rust-overlay",
-        "type": "github"
-      }
-    },
     "systems": {
       "locked": {
         "lastModified": 1681028828,
diff --git a/flake.nix b/flake.nix
index d6800c3..45af302 100644
--- a/flake.nix
+++ b/flake.nix
@@ -16,13 +16,8 @@
       url = "github:dadada/dadada.li";
       flake = false;
     };
-    recipemd = {
-      url = "github:dadada/recipemd/nix-flake";
-      inputs.nixpkgs.follows = "nixpkgs";
-      inputs.flake-utils.follows = "flake-utils";
-    };
     agenix = {
-      url = "github:ryantm/agenix/0.14.0";
+      url = "github:ryantm/agenix/0.15.0";
       inputs.nixpkgs.follows = "nixpkgs";
     };
     devshell = {
@@ -38,15 +33,6 @@
       url = "github:NixOS/flake-registry";
       flake = false;
     };
-    rust-overlay = {
-      url = "github:oxalica/rust-overlay";
-      inputs.nixpkgs.follows = "nixpkgs";
-      inputs.flake-utils.follows = "flake-utils";
-    };
-    naersk = {
-      url = "github:nix-community/naersk";
-      inputs.nixpkgs.follows = "nixpkgs";
-    };
     systems.url = "github:nix-systems/default";
     treefmt-nix = {
       url = "github:numtide/treefmt-nix";
@@ -55,10 +41,4 @@
   };
 
   outputs = { ... } @ args: import ./outputs.nix args;
-
-  nixConfig = {
-    extra-trusted-public-keys = "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=";
-    extra-substituters = "https://nix-community.cachix.org/";
-    extra-trusted-substituters = "https://nix-community.cachix.org/";
-  };
 }
diff --git a/home/pkgs.nix b/home/pkgs.nix
index b09030f..3bd0007 100644
--- a/home/pkgs.nix
+++ b/home/pkgs.nix
@@ -108,6 +108,7 @@ with pkgs; [
   python38Packages.dateutil
   python38Packages.managesieve
   ranger
+  recipemd
   reptyr
   ripgrep
   ripgrep
diff --git a/nixos/configurations.nix b/nixos/configurations.nix
index 48d6a2e..0474384 100644
--- a/nixos/configurations.nix
+++ b/nixos/configurations.nix
@@ -8,19 +8,13 @@
 , ...
 }@inputs:
 let
-  more-packages = system: {
-    more-packages = final: prev: {
-      recipemd = inputs.recipemd.packages.${system}.recipemd;
-    };
-  };
-
   nixosSystem = { system ? "x86_64-linux", extraModules ? [ ] }: nixpkgs.lib.nixosSystem {
     inherit system;
 
     modules = [{
       # Add flakes to registry and nix path.
       dadada.inputs = inputs // { dadada = self; };
-      nixpkgs.overlays = nixpkgs.lib.attrValues (self.overlays // (more-packages system));
+      nixpkgs.overlays = nixpkgs.lib.attrValues self.overlays;
     }] ++ (nixpkgs.lib.attrValues self.nixosModules) ++ [ agenix.nixosModules.age ] ++ extraModules;
   };
 in
@@ -51,7 +45,7 @@ in
     ];
   };
 
-  surgat = nixosSystem rec {
+  surgat = nixosSystem {
     system = "x86_64-linux";
     extraModules = [
       {
diff --git a/outputs.nix b/outputs.nix
index 16715d2..8b6a45f 100644
--- a/outputs.nix
+++ b/outputs.nix
@@ -6,7 +6,6 @@
 , nixpkgs
 , home-manager
 , nixos-hardware
-, recipemd
 , agenix
 , devshell
 , ...
diff --git a/overlays.nix b/overlays.nix
index 225e23c..bf0588c 100644
--- a/overlays.nix
+++ b/overlays.nix
@@ -9,4 +9,15 @@
       };
     });
   };
+
+  recipemd = final: prev: {
+    pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [
+      (
+        python-final: python-prev: {
+          recipemd = python-final.callPackage ./pkgs/recipemd.nix { };
+        }
+      )
+    ];
+    recipemd = prev.python3Packages.toPythonApplication final.python3Packages.recipemd;
+  };
 }
diff --git a/pkgs/recipemd.nix b/pkgs/recipemd.nix
new file mode 100644
index 0000000..4879a9a
--- /dev/null
+++ b/pkgs/recipemd.nix
@@ -0,0 +1,58 @@
+{ lib
+, buildPythonPackage
+, fetchFromGitHub
+, pytestCheckHook
+, pythonPackages
+, installShellFiles
+, pythonOlder
+, pythonAtLeast
+}:
+buildPythonPackage rec {
+  pname = "recipemd";
+  version = "4.0.8";
+
+  disabled = pythonOlder "3.7" || pythonAtLeast "4";
+
+  src = fetchFromGitHub {
+    owner = "tstehr";
+    repo = "RecipeMD";
+    rev = "v${version}";
+    hash = "sha256-eumV2zm7TIJcTPRtWSckYz7jiyH3Ek4nIAVtuJs3sJc=";
+  };
+
+  propagatedBuildInputs = with pythonPackages; [
+    dataclasses-json
+    yarl
+    CommonMark
+    argcomplete
+    pyparsing
+  ];
+
+  nativeBuildInputs = [ installShellFiles ];
+
+  postInstall = ''
+    ${pythonPackages.argcomplete}/bin/register-python-argcomplete -s bash ${pname} > $out/completions.bash
+    installShellCompletion --bash --name recipemd.bash $out/completions.bash
+
+    ${pythonPackages.argcomplete}/bin/register-python-argcomplete -s fish ${pname} > $out/completions.fish
+    installShellCompletion --fish --name recipemd.fish $out/completions.fish
+
+    # The version of argcomplete in nixpkgs-stable does not have support for zsh
+    #${pythonPackages.argcomplete}/bin/register-python-argcomplete -s zsh ${pname} > $out/completions.zsh
+    #installShellCompletion --zsh --name _recipemd $out/completions.zsh
+  '';
+
+  checkInputs = [
+    pytestCheckHook
+    pythonPackages.pytestcov
+  ];
+
+  doCheck = true;
+
+  meta = with lib; {
+    description = "Markdown recipe manager, reference implementation of RecipeMD";
+    homepage = "https://recipemd.org";
+    license = [ licenses.lgpl3Only ];
+    maintainers = [ maintainers.dadada ];
+  };
+}