diff --git a/flake.lock b/flake.lock index d4fef1c7..4607a8b4 100644 --- a/flake.lock +++ b/flake.lock @@ -15,6 +15,26 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1635165013, + "narHash": "sha256-o/BdVjNwcB6jOmzZjOH703BesSkkS5O7ej3xhyO8hAY=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "5b9e0ff9d3b551234b4f3eb3983744fa354b17f1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1639927577, @@ -41,15 +61,16 @@ ] }, "locked": { - "lastModified": 1639592782, - "narHash": "sha256-QXAT8+oBW1ccWWHfxEagdLwA8GM7cNVVTV12DJKuddc=", - "owner": "nix-community", + "lastModified": 1639948094, + "narHash": "sha256-GAYmCV3tbvEm5TWdBB5WzCEODvG8dLKINnkvvnZoRe4=", + "owner": "cpcloud", "repo": "poetry2nix", - "rev": "2ab5f606d30b042228241f400314067aa9a609af", + "rev": "38d2b9bf45f1a5a7ed0f8521bdccca2c5ff34461", "type": "github" }, "original": { - "owner": "nix-community", + "owner": "cpcloud", + "ref": "remove-bootstrap-poetry", "repo": "poetry2nix", "type": "github" } @@ -80,6 +101,7 @@ "root": { "inputs": { "flake-utils": "flake-utils", + "gitignore": "gitignore", "nixpkgs": "nixpkgs", "poetry2nix": "poetry2nix", "pre-commit-hooks": "pre-commit-hooks" diff --git a/flake.nix b/flake.nix index 80158ed7..2907b57d 100644 --- a/flake.nix +++ b/flake.nix @@ -13,97 +13,83 @@ }; poetry2nix = { - url = "github:nix-community/poetry2nix"; + url = "github:cpcloud/poetry2nix/remove-bootstrap-poetry"; inputs.nixpkgs.follows = "nixpkgs"; inputs.flake-utils.follows = "flake-utils"; }; + + gitignore = { + url = "github:hercules-ci/gitignore.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { self , nixpkgs , flake-utils + , gitignore , pre-commit-hooks , poetry2nix }: - { - overlay = nixpkgs.lib.composeManyExtensions [ - poetry2nix.overlay - (pkgs: super: { - prettierTOML = pkgs.writeShellScriptBin "prettier" '' - ${pkgs.nodePackages.prettier}/bin/prettier \ - --plugin-search-dir "${pkgs.nodePackages.prettier-plugin-toml}/lib" \ - "$@" - ''; - } // (super.lib.listToAttrs ( - super.lib.concatMap - (py: - let - noDotPy = super.lib.replaceStrings [ "." ] [ "" ] py; - overrides = pkgs.poetry2nix.overrides.withDefaults ( - import ./poetry-overrides.nix { - inherit pkgs; - inherit (pkgs) lib stdenv; - } - ); - in - [ - { - name = "protoletariat${noDotPy}"; - value = pkgs.poetry2nix.mkPoetryApplication { - python = pkgs."python${noDotPy}"; - - pyproject = ./pyproject.toml; - poetrylock = ./poetry.lock; - src = pkgs.lib.cleanSource ./.; - - buildInputs = [ pkgs.sqlite ]; - - inherit overrides; - - checkInputs = with pkgs; [ buf grpc protobuf ]; - - preCheck = '' - export HOME - HOME="$(mktemp -d)" - ''; - - checkPhase = '' - runHook preCheck - pytest - runHook postCheck - ''; - - pythonImportsCheck = [ "protoletariat" ]; - }; - } - { - name = "protoletariatDevEnv${noDotPy}"; - value = pkgs.poetry2nix.mkPoetryEnv { - python = pkgs."python${noDotPy}"; - projectDir = ./.; - inherit overrides; - editablePackageSources = { - protoletariat = ./protoletariat; - }; - }; - } - ]) - [ "3.7" "3.8" "3.9" "3.10" ] - ))) - ]; - } // (flake-utils.lib.eachDefaultSystem (system: + (flake-utils.lib.eachDefaultSystem (localSystem: let + crossSystem = nixpkgs.lib.systems.examples.musl64 // { useLLVM = true; }; + getOverrides = pkgs: pkgs.poetry2nix.overrides.withDefaults ( + import ./poetry-overrides.nix { } + ); pkgs = import nixpkgs { - inherit system; - overlays = [ self.overlay ]; + inherit localSystem crossSystem; + overlays = [ + (nixpkgs.lib.composeManyExtensions [ + poetry2nix.overlay + gitignore.overlay + (final: _: { + prettierTOML = final.pkgsBuildBuild.writeShellScriptBin "prettier" '' + ${final.pkgsBuildBuild.nodePackages.prettier}/bin/prettier \ + --plugin-search-dir "${final.pkgsBuildBuild.nodePackages.prettier-plugin-toml}/lib" \ + "$@" + ''; + + protoletariatDevEnv310 = final.pkgsBuildBuild.poetry2nix.mkPoetryEnv { + python = final.pkgsBuildBuild.python310; + projectDir = ./.; + overrides = getOverrides final.pkgsBuildBuild; + editablePackageSources = { + protoletariat = ./protoletariat; + }; + }; + + protoletariat310 = final.poetry2nix.mkPoetryApplication { + python = final.python310; + + projectDir = ./.; + src = final.gitignoreSource ./.; + + overrides = getOverrides final; + + checkInputs = with final; [ buf grpc protobuf ]; + + preCheck = '' + export HOME + HOME="$(mktemp -d)" + ''; + + checkPhase = '' + runHook preCheck + pytest + runHook postCheck + ''; + + pythonImportsCheck = [ "protoletariat" ]; + }; + }) + ]) + ]; }; inherit (pkgs) lib; in rec { - packages.protoletariat37 = pkgs.protoletariat37; - packages.protoletariat38 = pkgs.protoletariat38; - packages.protoletariat39 = pkgs.protoletariat39; packages.protoletariat310 = pkgs.protoletariat310; packages.protoletariat = pkgs.protoletariat310; @@ -115,31 +101,31 @@ }; defaultApp = apps.protoletariat; - packages.protoletariat-image = pkgs.dockerTools.buildLayeredImage { + packages.protoletariat-image = pkgs.pkgsBuildBuild.dockerTools.buildLayeredImage { name = "protoletariat"; config = { - Entrypoint = [ "${defaultPackage}/bin/protol" ]; - Command = [ "${defaultPackage}/bin/protol" ]; + Entrypoint = [ defaultApp.program ]; + Command = [ defaultApp.program ]; }; }; checks = { - pre-commit-check = pre-commit-hooks.lib.${system}.run { + pre-commit-check = pre-commit-hooks.lib.${localSystem}.run { src = ./.; hooks = { nix-linter = { enable = true; - entry = lib.mkForce "${pkgs.nix-linter}/bin/nix-linter"; + entry = lib.mkForce "${pkgs.pkgsBuildBuild.nix-linter}/bin/nix-linter"; }; nixpkgs-fmt = { enable = true; - entry = lib.mkForce "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check"; + entry = lib.mkForce "${pkgs.pkgsBuildBuild.nixpkgs-fmt}/bin/nixpkgs-fmt --check"; }; prettier = { enable = true; - entry = lib.mkForce "${pkgs.prettierTOML}/bin/prettier --check"; + entry = lib.mkForce "${pkgs.pkgsBuildBuild.prettierTOML}/bin/prettier --check"; types_or = [ "json" "markdown" "toml" "yaml" ]; }; @@ -179,7 +165,7 @@ }; devShell = pkgs.mkShell { - nativeBuildInputs = with pkgs; [ + nativeBuildInputs = with pkgs.pkgsBuildBuild; [ buf commitizen grpc @@ -189,7 +175,7 @@ protoletariatDevEnv310 ]; - inherit (self.checks.${system}.pre-commit-check) shellHook; + inherit (self.checks.${localSystem}.pre-commit-check) shellHook; }; })); }