From 92931d288388b594cdaca3a0bcf1671d513ab697 Mon Sep 17 00:00:00 2001 From: Philipp Herzog Date: Fri, 16 Jun 2023 15:40:48 +0200 Subject: [PATCH] [meta] flakify batou_ext add a nix flake to batou_ext to build the batou_ext python package as well as a devshell for development purposes --- .github/workflows/nix.yml | 20 +++++++ flake.lock | 115 ++++++++++++++++++++++++++++++++++++++ flake.nix | 68 ++++++++++++++++++++++ nix/batou_ext.nix | 56 +++++++++++++++++++ 4 files changed, 259 insertions(+) create mode 100644 .github/workflows/nix.yml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/batou_ext.nix diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 0000000..c360292 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,20 @@ +name: "Nix Test" + +# Controls when the workflow will run +on: + # Trigger the workflow on push or pull request events: + push: + branches: [ master ] + pull_request: + + # Allow to run this workflow manually from the Actions tab: + workflow_dispatch: + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v20 + - run: nix build + - run: nix flake check diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b9f5fde --- /dev/null +++ b/flake.lock @@ -0,0 +1,115 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1685662779, + "narHash": "sha256-cKDDciXGpMEjP1n6HlzKinN0H+oLmNpgeCTzYnsA2po=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "71fb97f0d875fd4de4994dfb849f2c75e17eb6c3", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nix-filter": { + "locked": { + "lastModified": 1681154353, + "narHash": "sha256-MCJ5FHOlbfQRFwN0brqPbCunLEVw05D/3sRVoNVt2tI=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "f529f42792ade8e32c4be274af6b6d60857fbee7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1686776226, + "narHash": "sha256-o6WbKvENj98QJz9Mco6T6SZGrjPewMDAFyKg0Lp8avU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0d2cf7fe5fa05d5271a15a8933414ee0a1570648", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1685564631, + "narHash": "sha256-8ywr3AkblY4++3lIVxmrWZFzac7+f32ZEhH/A8pNscI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4f53efe34b3a8877ac923b9350c874e3dcd5dc0a", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1680945546, + "narHash": "sha256-8FuaH5t/aVi/pR1XxnF0qi4WwMYC+YxlfdsA0V+TEuQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d9f759f2ea8d265d974a6e1259bd510ac5844c5d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nix-filter": "nix-filter", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1685519364, + "narHash": "sha256-rE9c9jWDSc5Nj0OjNzBENaJ6j4YBphcqSPia2IwCMLA=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "6521a278bcba66b440554cc1350403594367b4ac", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6773de3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,68 @@ +{ + description = "A flake for the flyingcircus batou_ext library"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + + treefmt-nix.url = "github:numtide/treefmt-nix"; + nix-filter.url = "github:numtide/nix-filter"; + }; + + outputs = inputs @ {flake-parts, ...}: + flake-parts.lib.mkFlake {inherit inputs;} { + imports = [ + inputs.treefmt-nix.flakeModule + ]; + + systems = [ + "x86_64-linux" + "aarch64-darwin" + ]; + + perSystem = { + config, + pkgs, + ... + }: let + src = inputs.nix-filter.lib { + root = inputs.self; + exclude = [ + (inputs.nix-filter.lib.matchExt "nix") + "flake.lock" + ]; + }; + batou_ext = pkgs.python3Packages.callPackage ./nix/batou_ext.nix {inherit src;}; + in { + treefmt = { + projectRootFile = "flake.nix"; + programs.alejandra.enable = true; + settings.formatter.alejandra.excludes = [ + "src/batou_ext/*" + ]; + flakeCheck = false; + }; + + formatter = config.treefmt.build.wrapper; + + packages = rec { + default = batou_ext; + inherit batou_ext; + }; + + checks = { + inherit batou_ext; + }; + + devShells.default = pkgs.mkShell { + packages = [ + (pkgs.python3.withPackages (ps: [batou_ext ps.tox])) + ]; + + shellHook = '' + export APPENV_BASEDIR=$PWD + ''; + }; + }; + }; +} diff --git a/nix/batou_ext.nix b/nix/batou_ext.nix new file mode 100644 index 0000000..ed0d9c8 --- /dev/null +++ b/nix/batou_ext.nix @@ -0,0 +1,56 @@ +{ + buildPythonPackage, + pyyaml, + pyaml, + six, + fetchPypi, + src, + markupsafe, + requests, + execnet, + importlib-metadata, + remote-pdb, + py, + configupdater, + mock, + pytest, + setuptools, + inquirerpy, +}: let + jinja2 = buildPythonPackage rec { + pname = "Jinja2"; + version = "3.0.1"; + propagatedBuildInputs = [markupsafe]; + src = fetchPypi { + inherit pname version; + sha256 = "sha256-cD9IS0emr1AudDyRIllcyBKwJx9mFyJAMRT3GnnQ9aQ="; + }; + }; + batou = buildPythonPackage rec { + pname = "batou"; + version = "2.3.1"; + propagatedBuildInputs = [ + requests + pyyaml + execnet + importlib-metadata + remote-pdb + py + configupdater + mock + pytest + setuptools + jinja2 + ]; + src = fetchPypi { + inherit pname version; + sha256 = "sha256-fPLYvmsNubKfsYWR039CoF7/767EDtXLFNAWhDAg9m4="; + }; + }; +in + buildPythonPackage { + pname = "batou_ext"; + version = "latest"; + propagatedBuildInputs = [pyyaml pyaml six batou inquirerpy]; + inherit src; + }