Skip to content

Commit

Permalink
perf: build docker image with musl
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Dec 29, 2021
1 parent c1ca5ed commit 6d3f5b8
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
inputs.nixpkgs.follows = "nixpkgs";
};

gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};

nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";

pre-commit-hooks = {
Expand All @@ -21,7 +26,7 @@
};

poetry2nix = {
url = "github:nix-community/poetry2nix";
url = "github:cpcloud/poetry2nix/remove-bootstrap-poetry";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
Expand Down Expand Up @@ -85,9 +90,9 @@
gitignore.overlay
poetry2nix.overlay
(pkgs: super: {
prettierTOML = pkgs.writeShellScriptBin "prettier" ''
${pkgs.nodePackages.prettier}/bin/prettier \
--plugin-search-dir "${pkgs.nodePackages.prettier-plugin-toml}/lib" \
prettierTOML = pkgs.pkgsBuildBuild.writeShellScriptBin "prettier" ''
${pkgs.pkgsBuildBuild.nodePackages.prettier}/bin/prettier \
--plugin-search-dir "${pkgs.pkgsBuildBuild.nodePackages.prettier-plugin-toml}/lib" \
"$@"
'';
protoletariatDevEnv = pkgs.protoletariatDevEnv310;
Expand Down Expand Up @@ -154,12 +159,16 @@
[ "37" "38" "39" "310" ]
)))
];
} // (flake-utils.lib.eachDefaultSystem (system:
} // (flake-utils.lib.eachDefaultSystem (localSystem:
let
pkgs = import nixpkgs {
inherit system;
legacyPkgs = nixpkgs.legacyPackages.${localSystem};
attrs = {
inherit localSystem;
overlays = [ self.overlay ];
} // legacyPkgs.lib.optionalAttrs (!legacyPkgs.stdenv.isDarwin) {
crossSystem = nixpkgs.lib.systems.examples.musl64 // { useLLVM = true; };
};
pkgs = import nixpkgs attrs;
inherit (pkgs) lib;
in
rec {
Expand All @@ -177,7 +186,7 @@
};
defaultApp = apps.protoletariat;

packages.protoletariat-image = pkgs.dockerTools.buildLayeredImage {
packages.protoletariat-image = pkgs.pkgsBuildBuild.dockerTools.buildLayeredImage {
name = "protoletariat";
config = {
Entrypoint = [ defaultApp.program ];
Expand All @@ -186,22 +195,22 @@
};

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 @@ -238,18 +247,19 @@
};
};

devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
devShell = pkgs.pkgsBuildBuild.mkShell {
nativeBuildInputs = with pkgs.pkgsBuildBuild; [
buf
commitizen
dive
grpc
poetry
prettierTOML
protobuf
protoletariatDevEnv
];

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

0 comments on commit 6d3f5b8

Please sign in to comment.