diff --git a/.github/workflows/build-nix.yml b/.github/workflows/build-nix.yml index 4daf1bb2b..69c1af255 100644 --- a/.github/workflows/build-nix.yml +++ b/.github/workflows/build-nix.yml @@ -41,4 +41,4 @@ jobs: authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} extraPullNames: pyperscan - run: | - nix flake check -L --option system ${{ matrix.arch }} --extra-platforms ${{ matrix.arch }} + nix flake check -L --impure --option system ${{ matrix.arch }} --extra-platforms ${{ matrix.arch }} diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 000000000..93004f225 --- /dev/null +++ b/devenv.nix @@ -0,0 +1,24 @@ +{ pkgs, ... }: + +# https://devenv.sh/reference/options/ +{ + languages.python = { + enable = true; + libraries = with pkgs; [ + file # python-magic + ]; + poetry = { + enable = true; + activate.enable = true; + install.enable = true; + install = { + groups = [ "dev" ]; + installRootPackage = true; + }; + }; + }; + + packages = with pkgs; [ + nvfetcher + ] ++ unblob.runtimeDeps; +} diff --git a/flake.lock b/flake.lock index 856ce3c6d..75c2650ce 100644 --- a/flake.lock +++ b/flake.lock @@ -48,6 +48,29 @@ "type": "github" } }, + "cachix": { + "inputs": { + "devenv": [ + "devenv" + ], + "flake-compat": "flake-compat", + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1727697255, + "narHash": "sha256-zwo5qgUIKy1z4OJTOCoi5bWX1sHU6iIN3Slvg8v7G2Y=", + "owner": "cachix", + "repo": "cachix", + "rev": "a7abc17d7d8c2b678e0c66968d865274d6e1ac7d", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "cachix", + "type": "github" + } + }, "crane": { "inputs": { "nixpkgs": [ @@ -111,6 +134,43 @@ "type": "github" } }, + "devenv": { + "inputs": { + "cachix": "cachix", + "flake-compat": "flake-compat_2", + "nix": "nix", + "nixpkgs": [ + "nixpkgs" + ], + "pre-commit-hooks": "pre-commit-hooks_2" + }, + "locked": { + "lastModified": 1727693281, + "narHash": "sha256-Fy6dZ0IQ6ZnSeQB8ifwG+HN8AcDjGFQljnGyojwZ7CU=", + "owner": "vlaci", + "repo": "devenv", + "rev": "3e106c5c67231464aae9ef607810ed25ec3156e3", + "type": "github" + }, + "original": { + "owner": "vlaci", + "ref": "python-wrapper", + "repo": "devenv", + "type": "github" + } + }, + "devenv-root": { + "flake": false, + "locked": { + "narHash": "sha256-d6xi4mKdjkX2JFicDIv5niSzpyI0m/Hnm8GGAIU04kY=", + "type": "file", + "url": "file:///dev/null" + }, + "original": { + "type": "file", + "url": "file:///dev/null" + } + }, "fenix": { "inputs": { "nixpkgs": [ @@ -190,7 +250,76 @@ "type": "github" } }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_3": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "devenv", + "nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { "inputs": { "systems": "systems" }, @@ -208,7 +337,7 @@ "type": "github" } }, - "flake-utils_2": { + "flake-utils_3": { "inputs": { "systems": "systems_2" }, @@ -226,12 +355,102 @@ "type": "github" } }, + "git-hooks": { + "inputs": { + "flake-compat": [ + "devenv", + "cachix", + "flake-compat" + ], + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "cachix", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1727514110, + "narHash": "sha256-0YRcOxJG12VGDFH8iS8pJ0aYQQUAgo/r3ZAL+cSh9nk=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "85f7a7177c678de68224af3402ab8ee1bcee25c8", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "cachix", + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_2": { + "inputs": { + "nixpkgs": [ + "devenv", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "libgit2": { + "flake": false, + "locked": { + "lastModified": 1697646580, + "narHash": "sha256-oX4Z3S9WtJlwvj0uH9HlYcWv+x1hqp8mhXl7HsLu2f0=", + "owner": "libgit2", + "repo": "libgit2", + "rev": "45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5", + "type": "github" + }, + "original": { + "owner": "libgit2", + "repo": "libgit2", + "type": "github" + } + }, "lzallright": { "inputs": { "advisory-db": "advisory-db", "crane": "crane", "fenix": "fenix", - "flake-utils": "flake-utils", + "flake-utils": "flake-utils_2", "nixpkgs": [ "nixpkgs" ] @@ -250,6 +469,34 @@ "type": "github" } }, + "nix": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "flake-parts": "flake-parts", + "libgit2": "libgit2", + "nixpkgs": "nixpkgs_2", + "nixpkgs-23-11": "nixpkgs-23-11", + "nixpkgs-regression": "nixpkgs-regression", + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1727438425, + "narHash": "sha256-X8ES7I1cfNhR9oKp06F6ir4Np70WGZU5sfCOuNBEwMg=", + "owner": "domenkozar", + "repo": "nix", + "rev": "f6c5ae4c1b2e411e6b1e6a8181cc84363d6a7546", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "devenv-2.24", + "repo": "nix", + "type": "github" + } + }, "nix-filter": { "locked": { "lastModified": 1710156097, @@ -266,6 +513,102 @@ } }, "nixpkgs": { + "locked": { + "lastModified": 1727348695, + "narHash": "sha256-J+PeFKSDV+pHL7ukkfpVzCOO7mBSrrpJ3svwBFABbhI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1925c603f17fc89f4c8f6bf6f631a802ad85d784", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-23-11": { + "locked": { + "lastModified": 1717159533, + "narHash": "sha256-oamiKNfr2MS6yH64rUn99mIZjc45nGJlj9eGth/3Xuw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a62e6edd6d5e1fa0329b8653c801147986f8d446", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a62e6edd6d5e1fa0329b8653c801147986f8d446", + "type": "github" + } + }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable_2": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1717432640, + "narHash": "sha256-+f9c4/ZX5MWDOuB1rKoWj+lBNm0z0rs4CK47HBLxy1o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "88269ab3044128b7c2f4c7d68448b2fb50456870", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1726871744, "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", @@ -281,6 +624,69 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": [ + "devenv", + "nix" + ], + "flake-utils": "flake-utils", + "gitignore": [ + "devenv", + "nix" + ], + "nixpkgs": [ + "devenv", + "nix", + "nixpkgs" + ], + "nixpkgs-stable": [ + "devenv", + "nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712897695, + "narHash": "sha256-nMirxrGteNAl9sWiOhoN5tIHyjBbVi5e2tgZUgZlK3Y=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "40e6053ecb65fcbf12863338a6dcefb3f55f1bf8", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "pre-commit-hooks_2": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "gitignore": "gitignore_2", + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable_2" + }, + "locked": { + "lastModified": 1726745158, + "narHash": "sha256-D5AegvGoEjt4rkKedmxlSEmC+nNLMBPWFxvmYnVLhjk=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "4e743a6920eab45e8ba0fbe49dc459f1423a4b74", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "pyperscan": { "inputs": { "advisory-db": "advisory-db_2", @@ -306,10 +712,12 @@ }, "root": { "inputs": { + "devenv": "devenv", + "devenv-root": "devenv-root", "filter": "filter", - "flake-compat": "flake-compat", + "flake-compat": "flake-compat_3", "lzallright": "lzallright", - "nixpkgs": "nixpkgs", + "nixpkgs": "nixpkgs_3", "pyperscan": "pyperscan", "sasquatch": "sasquatch", "unblob-native": "unblob-native" @@ -369,7 +777,7 @@ "inputs": { "advisory-db": "advisory-db_3", "crane": "crane_3", - "flake-utils": "flake-utils_2", + "flake-utils": "flake-utils_3", "nix-filter": "nix-filter", "nixpkgs": [ "nixpkgs" diff --git a/flake.nix b/flake.nix index 10f9ba68a..92e655170 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,14 @@ url = "github:edolstra/flake-compat"; flake = false; }; + inputs.devenv = { + url = "github:vlaci/devenv/python-wrapper"; + inputs.nixpkgs.follows = "nixpkgs"; + # devenv and cachix depends on each-other force devenv's cachix to + # not pull-in another version of devenv, which would pull in + # another version of cachix... + inputs.cachix.inputs.devenv.follows = "devenv"; + }; nixConfig = { extra-substituters = [ "https://unblob.cachix.org" ]; @@ -31,7 +39,7 @@ ]; }; - outputs = { self, nixpkgs, filter, unblob-native, lzallright, pyperscan, sasquatch, ... }: + outputs = { self, nixpkgs, devenv, filter, unblob-native, lzallright, pyperscan, sasquatch, ... }@inputs: let # System types to support. supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; @@ -64,46 +72,15 @@ checks = forAllSystems (system: nixpkgsFor.${system}.unblob.tests); devShells = forAllSystems - (system: - with nixpkgsFor.${system}; { - default = mkShell { - venvDir = "./.venv"; - buildInputs = [ - # A Python interpreter including the 'venv' module is required to bootstrap - # the environment. - python3Packages.python - - # This executes some shell code to initialize a venv in $venvDir before - # dropping into the shell - python3Packages.venvShellHook - - # This hook is used to patch downloaded binaries in venv to use libraries - # from the nix store. - autoPatchelfHook - - unblob.runtimeDeps - pyright - python3Packages.pytest - python3Packages.pytest-cov - poetry - - nvfetcher - ]; - - postVenvCreation = - let - apply_patches = lib.concatMapStringsSep - "\n" - (patch: "patch -f -p1 -d $VIRTUAL_ENV/lib/python3*/site-packages < ${patch}") - pkgs.python3Packages.python-magic.patches; - in - '' - poetry install --all-extras --sync --with dev - autoPatchelf "$VIRTUAL_ENV/" - ${apply_patches} - ''; - }; - }); + (system: { + default = devenv.lib.mkShell { + inherit inputs; + pkgs = nixpkgsFor.${system}; + modules = [ + ./devenv.nix + ]; + }; + }); legacyPackages = forAllSystems (system: nixpkgsFor.${system}); }; diff --git a/shell.nix b/shell.nix index d933ce93f..08990ca70 100644 --- a/shell.nix +++ b/shell.nix @@ -5,6 +5,8 @@ let ./flake.nix ./overlay.nix ./nix + ./devenv.nix + ".devenv" ]; lock = builtins.fromJSON (builtins.readFile ./flake.lock);