From 5679c01f8dc961ea75ff72955e67b4778b1e9708 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Sat, 18 Nov 2023 21:26:21 +0200 Subject: [PATCH] Add a nix Flake Signed-off-by: Wiktor Kwapisiewicz --- flake.lock | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 46 ++++++++++++++++++++++++++++++++++++++++ package.nix | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..81c99a3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1700051294, + "narHash": "sha256-tUtNWuvFxk+C2VfjOgNGIBYl3gy2wYwYxVjsxODRbyQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "11cdf7776dd99bf437056f21608f5f78da04e877", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6cdbf91 --- /dev/null +++ b/flake.nix @@ -0,0 +1,46 @@ +{ + # See https://github.com/mhwombat/nix-for-numbskulls/blob/main/flakes.md + # for a brief overview of what each section in a flake should or can contain. + + # TODO: Fix this to something better + description = "a very simple and friendly flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self + , nixpkgs + , flake-utils + }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in + { + devShells = { + default = pkgs.mkShell { + nativeBuildInputs = [ + pkgs.python3 + pkgs.python3.pkgs.virtualenv + pkgs.python3.pkgs.pip + ]; + }; + }; + packages = { + # Besides the `src` and `version` arguments, this package.nix could + # be copied as is to Nixpkgs' + # pkgs/development/python-modules/pysequoia/default.nix, and should be + # maintained in parallel to this local version of it. + pysequoia = pkgs.python3.pkgs.callPackage ./package.nix { + src = self; + # Get the version defined in pyproject.toml + version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version; + }; + }; + } + ); +} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..d6cba9e --- /dev/null +++ b/package.nix @@ -0,0 +1,59 @@ +{ lib +, buildPythonPackage +, src +, version +, pkg-config +, rustPlatform +, cargo +, rustc +, bzip2 +, nettle +, openssl +, pcsclite +, stdenv +, darwin +, libiconv +}: + +buildPythonPackage rec { + pname = "pysequoia"; + inherit src version; + pyproject = true; + + # This attribute is defined differently in Nixpkgs - using + # `rustPlatform.fetchCargoTarball`. Since we have a Cargo.lock file available + # here, we can use it instead. + cargoDeps = rustPlatform.importCargoLock { + lockFile = ./Cargo.lock; + }; + + nativeBuildInputs = [ + pkg-config + rustPlatform.bindgenHook + rustPlatform.cargoSetupHook + rustPlatform.maturinBuildHook + cargo + rustc + ]; + + buildInputs = [ + bzip2 + nettle + openssl + pcsclite + ] ++ lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.CoreFoundation + darwin.apple_sdk.frameworks.Security + libiconv + ]; + + pythonImportsCheck = [ "pysequoia" ]; + + meta = with lib; { + description = "This library provides OpenPGP facilities in Python through the Sequoia PGP library"; + downloadPage = "https://codeberg.org/wiktor/pysequoia"; + homepage = "https://sequoia-pgp.gitlab.io/pysequoia"; + license = licenses.asl20; + maintainers = with maintainers; [ doronbehar ]; + }; +}