From 2eba30a88454a09950ccfeeeedeaad2ce407f5cb 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 | 225 ++++++++++++++++++++++++++++++++++++++ flake.nix | 75 +++++++++++++ nix/batou_ext.nix | 15 +++ 4 files changed, 335 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..f2f99b9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,225 @@ +{ + "nodes": { + "batou": { + "inputs": { + "flake-parts": "flake-parts", + "nix-filter": "nix-filter", + "nixpkgs": [ + "nixpkgs" + ], + "treefmt-nix": "treefmt-nix" + }, + "locked": { + "lastModified": 1686924448, + "narHash": "sha256-xfKVaBP/qOAtrF/iRwj9m79gOKJiMrGA6ygFWB6Pr4Y=", + "owner": "flyingcircusio", + "repo": "batou", + "rev": "615713579b64bb1b1276cfaf4b4f6d29eef47cfe", + "type": "github" + }, + "original": { + "owner": "flyingcircusio", + "ref": "phil/flakify-batou", + "repo": "batou", + "type": "github" + } + }, + "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" + } + }, + "flake-parts_2": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib_2" + }, + "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" + } + }, + "nix-filter_2": { + "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": 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" + } + }, + "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-lib_2": { + "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": 1686776226, + "narHash": "sha256-o6WbKvENj98QJz9Mco6T6SZGrjPewMDAFyKg0Lp8avU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0d2cf7fe5fa05d5271a15a8933414ee0a1570648", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "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": { + "batou": "batou", + "flake-parts": "flake-parts_2", + "nix-filter": "nix-filter_2", + "nixpkgs": "nixpkgs_2", + "treefmt-nix": "treefmt-nix_2" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1685519364, + "narHash": "sha256-rE9c9jWDSc5Nj0OjNzBENaJ6j4YBphcqSPia2IwCMLA=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "6521a278bcba66b440554cc1350403594367b4ac", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, + "treefmt-nix_2": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "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..f6f7161 --- /dev/null +++ b/flake.nix @@ -0,0 +1,75 @@ +{ + 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"; + + batou.url = "github:flyingcircusio/batou/phil/flakify-batou"; + batou.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = inputs @ {flake-parts, ...}: + flake-parts.lib.mkFlake {inherit inputs;} { + imports = [ + inputs.treefmt-nix.flakeModule + ]; + + systems = [ + "x86_64-linux" + "aarch64-darwin" + ]; + + perSystem = { + config, + pkgs, + inputs', + ... + }: 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; + inherit (inputs'.batou.packages) batou; + }; + 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..5d93c14 --- /dev/null +++ b/nix/batou_ext.nix @@ -0,0 +1,15 @@ +{ + buildPythonPackage, + pyyaml, + pyaml, + six, + src, + inquirerpy, + batou, +}: +buildPythonPackage { + pname = "batou_ext"; + version = "latest"; + propagatedBuildInputs = [pyyaml pyaml six batou inquirerpy]; + inherit src; +}