Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 7 additions & 113 deletions flake.lock

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

153 changes: 78 additions & 75 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,98 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs-crunchy = { url = "github:crunchydata/nixpkgs"; inputs.nixpkgs.follows = "nixpkgs"; };
nix-filter.url = "github:numtide/nix-filter";
};

outputs = { self, nixpkgs, nixpkgs-crunchy, flake-utils, nix-filter }:
outputs = { nixpkgs, nix-filter, ... }:
let
systems = builtins.map (a: a.system) (builtins.catAttrs "crystal" (builtins.attrValues nixpkgs-crunchy.outputs.packages));
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
filterSrc = files: (nix-filter.lib { root = ./.; include = [ "src" "spec" ] ++ files; });
in
flake-utils.lib.eachSystem systems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
crunchy = nixpkgs-crunchy.packages.${system};

crystal = crunchy.crystal.override { extraBuildInputs = [ pkgs.libssh2 ]; };
crystalStatic = crunchy.crystalStatic.override { extraBuildInputs = [ pkgs.pkgsStatic.libssh2 ]; };

check = pkgs.writeScriptBin "check" "nix build .#check --keep-going --print-build-logs";
shardFiles = [ "shard.lock" "shards.nix" "shard.yml" ];
src = filterSrc (shardFiles ++ [ "Readme" "Changelog" ]);
specSrc = filterSrc shardFiles;
lintSrc = filterSrc [ ".ameba.yml" ];
perSystemOutputs = system:
let
pkgs = nixpkgs.legacyPackages.${system};

darwinBuildInputs = [
pkgs.darwin.apple_sdk.frameworks.Foundation
pkgs.darwin.apple_sdk.frameworks.Security
];
crystal = pkgs.crystal;

mkPkgArgs = { inherit self src; doCheck = false; };

# NOTE: currently (2023-11-29) `nix flake check` fails on x86 macs due to
# error: don't yet have a `targetPackages.darwin.LibsystemCross for x86_64-apple-darwin`
# so only have a static package on the other platforms for now.
# some maybe relevant issues:
# https://github.com/NixOS/nixpkgs/pull/256590
# https://github.com/NixOS/nixpkgs/issues/180771
# https://github.com/NixOS/nixpkgs/issues/270375
static = if system == "x86_64-darwin" then null else "static";
in
rec {
packages = {
default = crystal.mkPkg mkPkgArgs;
${static} = crystalStatic.mkPkg mkPkgArgs;
check = pkgs.linkFarmFromDrvs "cb-all-checks" (builtins.attrValues checks);
};
check = pkgs.writeScriptBin "check" "nix build .#check --keep-going --print-build-logs";
shardFiles = [ "shard.lock" "shards.nix" "shard.yml" ];
src = filterSrc (shardFiles ++ [ "Readme" "Changelog" ]);
specSrc = filterSrc shardFiles;
lintSrc = filterSrc [ ".ameba.yml" ];

devShells.default = pkgs.mkShell {
buildInputs = with crunchy; [ crystal2nix ameba ]
++ [ crystal check ]
++ [ pkgs.pcre2 pkgs.pcre pkgs.libyaml ]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin darwinBuildInputs;
};
# returns a function that can read a value for a key in shard.yml
shardValue = src: key:
let
file = src + "/shard.yml";
contents = builtins.readFile file;
match = builtins.split (key + ": ([-a-zA-Z0-9\.]+).*\n") contents;
in
if builtins.length match == 3 then
builtins.head (builtins.head (builtins.tail match))
else
builtins.traceVerbose "file ${file} doesn't have top-level key '${key}'" null;

checks = {
format = pkgs.stdenvNoCC.mkDerivation {
name = "format";
src = specSrc;
installPhase = "mkdir $out && crystal tool format --check";
nativeBuildInputs = [ crystal ];
dontPatch = true;
dontConfigure = true;
dontBuild = true;
dontFixup = true;
version = shardValue src "version";
in
rec {
packages = {
default = crystal.buildCrystalPackage {
inherit src version;
pname = "cb";
format = "shards";
shardsFile = ./shards.nix;
buildInputs = [ pkgs.libssh2 ];
doCheck = false;
};
check = pkgs.linkFarmFromDrvs "cb-all-checks" (builtins.attrValues checks);
};

ameba = pkgs.stdenvNoCC.mkDerivation {
name = "ameba";
src = lintSrc;
installPhase = "mkdir $out && ameba";
nativeBuildInputs = [ crunchy.ameba ];
dontPatch = true;
dontConfigure = true;
dontBuild = true;
dontFixup = true;
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [ crystal2nix ameba shards libssh2 ]
++ [ crystal check ];
};

specs = crystal.buildCrystalPackage {
name = "specs";
src = specSrc;
HOME = "/tmp"; # needed just for cb, not in general
installPhase = "mkdir $out && crystal spec --progress";
shardsFile = specSrc + "/shards.nix";
doCheck = false;
dontPatch = true;
dontBuild = true;
dontFixup = true;
checks = {
format = pkgs.stdenvNoCC.mkDerivation {
name = "format";
src = specSrc;
installPhase = "mkdir $out && crystal tool format --check";
nativeBuildInputs = [ crystal ];
dontPatch = true;
dontConfigure = true;
dontBuild = true;
dontFixup = true;
};

ameba = pkgs.stdenvNoCC.mkDerivation {
name = "ameba";
src = lintSrc;
installPhase = "mkdir $out && ameba";
nativeBuildInputs = [ pkgs.ameba ];
dontPatch = true;
dontConfigure = true;
dontBuild = true;
dontFixup = true;
};

specs = crystal.buildCrystalPackage {
name = "specs";
src = specSrc;
buildInputs = [ pkgs.libssh2 ];
installPhase = "mkdir $out && HOME=$TMP crystal spec --progress";
shardsFile = specSrc + "/shards.nix";
doCheck = false;
dontPatch = true;
dontBuild = true;
dontFixup = true;
};
};
};
}
);
in
{
packages = forAllSystems (system: (perSystemOutputs system).packages);
devShells = forAllSystems (system: (perSystemOutputs system).devShells);
checks = forAllSystems (system: (perSystemOutputs system).checks);
};
}
14 changes: 7 additions & 7 deletions shard.lock

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

Loading