Skip to content

Commit

Permalink
build: build a musl image
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Dec 19, 2021
1 parent b4c9663 commit 679b897
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 90 deletions.
38 changes: 30 additions & 8 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

150 changes: 68 additions & 82 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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" ];
};

Expand Down Expand Up @@ -179,7 +165,7 @@
};

devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
nativeBuildInputs = with pkgs.pkgsBuildBuild; [
buf
commitizen
grpc
Expand All @@ -189,7 +175,7 @@
protoletariatDevEnv310
];

inherit (self.checks.${system}.pre-commit-check) shellHook;
inherit (self.checks.${localSystem}.pre-commit-check) shellHook;
};
}));
}

0 comments on commit 679b897

Please sign in to comment.