From ce7518e9ee5e341dfc92216e157aa5d851661062 Mon Sep 17 00:00:00 2001 From: b12f Date: Mon, 25 Nov 2024 12:12:29 +0100 Subject: [PATCH] flake: improve devshell, add watson package, add github action --- .github/workflows/build.yml | 16 ++++++ .gitignore | 4 ++ flake.lock | 49 ++++++++--------- flake.nix | 102 ++++++++++++++++++++++-------------- 4 files changed, 106 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..cbcd6c0 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,16 @@ +name: Nix Flake Build + +on: + push: + branches: + - main + pull_request: + +jobs: + nix-flake-check: + runs-on: ubuntu-latest + steps: + - uses: nixbuild/nix-quick-install-action@v29 + - run: nix build '.#watson-td' + - name: watson + run: ./result/bin/watson diff --git a/.gitignore b/.gitignore index 7107bf5..79e29da 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,7 @@ pip-log.txt *.sublime-workspace *.swp *.sw[po] + +# nix related files + +/result diff --git a/flake.lock b/flake.lock index c3d7545..ed27139 100644 --- a/flake.lock +++ b/flake.lock @@ -1,22 +1,20 @@ { "nodes": { - "devshell": { + "flake-parts": { "inputs": { - "nixpkgs": [ - "nixpkgs" - ] + "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1722113426, - "narHash": "sha256-Yo/3loq572A8Su6aY5GP56knpuKYRvM2a1meP9oJZCw=", - "owner": "numtide", - "repo": "devshell", - "rev": "67cce7359e4cd3c45296fb4aaf6a19e2a9c757ae", + "lastModified": 1730504689, + "narHash": "sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS+b4tfNFCwE=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "506278e768c2a08bec68eb62932193e341f55c90", "type": "github" }, "original": { - "owner": "numtide", - "repo": "devshell", + "owner": "hercules-ci", + "repo": "flake-parts", "type": "github" } }, @@ -36,25 +34,22 @@ "type": "github" } }, - "root": { - "inputs": { - "devshell": "devshell", - "nixpkgs": "nixpkgs", - "systems": "systems" - } - }, - "systems": { + "nixpkgs-lib": { "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" + "lastModified": 1730504152, + "narHash": "sha256-lXvH/vOfb4aGYyvFmZK/HlsNsr/0CVWlwYvo2rxJk3s=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/cc2f28000298e1269cea6612cd06ec9979dd5d7f.tar.gz" }, "original": { - "id": "systems", - "type": "indirect" + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/cc2f28000298e1269cea6612cd06ec9979dd5d7f.tar.gz" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index 842176e..0cd25c1 100644 --- a/flake.nix +++ b/flake.nix @@ -1,51 +1,77 @@ { description = "Watson devenv"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - - inputs.devshell.url = "github:numtide/devshell"; - inputs.devshell.inputs.nixpkgs.follows = "nixpkgs"; - - outputs = {self, nixpkgs, systems, devshell }: - let - eachSystem = nixpkgs.lib.genAttrs (import systems); - # Nixpkgs instantiated for system types in nix-systems - nixpkgsFor = eachSystem (system: - import nixpkgs { - inherit system; - overlays = [ - devshell.overlays.default - ]; - } - ); - in - { - devShells = eachSystem (system: - let - pkgs = nixpkgsFor.${system}; - in - { - default = pkgs.devshell.mkShell { - # Add additional packages you'd like to be available in your devshell - # PATH here - devshell.packages = with pkgs; [ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + flake-parts.url = "github:hercules-ci/flake-parts"; + }; + + outputs = inputs@{ self, ... }: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + perSystem = + args@{ pkgs, config, system, ... }: { + packages = { + watson-td = pkgs.python3Packages.buildPythonPackage { + name = "watson-td"; + src = ./.; + propagatedBuildInputs = with pkgs.python3Packages; [ + # requirements + click + click-didyoumean + requests + arrow + + # requirements-dev + flake8 + py + pytest + pytest-datafiles + pytest-mock + pytest-runner + pytest-runner + ]; + }; + }; + + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ gnumake virtualenv - (pkgs.python3.withPackages (p: [ - # select Python packages here + yaml-language-server + (python3.withPackages (p: [ + # LSP support p.python-lsp-ruff p.python-lsp-server p.python-lsp-server.optional-dependencies + + # pip + p.pip + + # requirements + p.click + p.click-didyoumean + p.requests + p.arrow + + # requirements-dev + p.flake8 + p.py + p.pytest + p.pytest-datafiles + p.pytest-mock + p.pytest-runner + p.pytest-runner ])) ]; }; - }); - - packages = eachSystem (system: - let - pkgs = nixpkgsFor.${system}; - in - { - }); + }; }; }