|
3 | 3 |
|
4 | 4 | inputs = { |
5 | 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; |
6 | | - flake-utils.url = "github:numtide/flake-utils"; |
7 | | - nixpkgs-crunchy = { url = "github:crunchydata/nixpkgs"; inputs.nixpkgs.follows = "nixpkgs"; }; |
8 | 6 | nix-filter.url = "github:numtide/nix-filter"; |
9 | 7 | }; |
10 | 8 |
|
11 | | - outputs = { self, nixpkgs, nixpkgs-crunchy, flake-utils, nix-filter }: |
| 9 | + outputs = { nixpkgs, nix-filter, ... }: |
12 | 10 | let |
13 | | - systems = builtins.map (a: a.system) (builtins.catAttrs "crystal" (builtins.attrValues nixpkgs-crunchy.outputs.packages)); |
| 11 | + forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed; |
14 | 12 | filterSrc = files: (nix-filter.lib { root = ./.; include = [ "src" "spec" ] ++ files; }); |
15 | | - in |
16 | | - flake-utils.lib.eachSystem systems (system: |
17 | | - let |
18 | | - pkgs = nixpkgs.legacyPackages.${system}; |
19 | | - crunchy = nixpkgs-crunchy.packages.${system}; |
20 | | - |
21 | | - crystal = crunchy.crystal.override { extraBuildInputs = [ pkgs.libssh2 ]; }; |
22 | | - crystalStatic = crunchy.crystalStatic.override { extraBuildInputs = [ pkgs.pkgsStatic.libssh2 ]; }; |
23 | 13 |
|
24 | | - check = pkgs.writeScriptBin "check" "nix build .#check --keep-going --print-build-logs"; |
25 | | - shardFiles = [ "shard.lock" "shards.nix" "shard.yml" ]; |
26 | | - src = filterSrc (shardFiles ++ [ "Readme" "Changelog" ]); |
27 | | - specSrc = filterSrc shardFiles; |
28 | | - lintSrc = filterSrc [ ".ameba.yml" ]; |
| 14 | + perSystemOutputs = system: |
| 15 | + let |
| 16 | + pkgs = nixpkgs.legacyPackages.${system}; |
29 | 17 |
|
30 | | - darwinBuildInputs = [ |
31 | | - pkgs.darwin.apple_sdk.frameworks.Foundation |
32 | | - pkgs.darwin.apple_sdk.frameworks.Security |
33 | | - ]; |
| 18 | + crystal = pkgs.crystal; |
34 | 19 |
|
35 | | - mkPkgArgs = { inherit self src; doCheck = false; }; |
36 | | - |
37 | | - # NOTE: currently (2023-11-29) `nix flake check` fails on x86 macs due to |
38 | | - # error: don't yet have a `targetPackages.darwin.LibsystemCross for x86_64-apple-darwin` |
39 | | - # so only have a static package on the other platforms for now. |
40 | | - # some maybe relevant issues: |
41 | | - # https://github.com/NixOS/nixpkgs/pull/256590 |
42 | | - # https://github.com/NixOS/nixpkgs/issues/180771 |
43 | | - # https://github.com/NixOS/nixpkgs/issues/270375 |
44 | | - static = if system == "x86_64-darwin" then null else "static"; |
45 | | - in |
46 | | - rec { |
47 | | - packages = { |
48 | | - default = crystal.mkPkg mkPkgArgs; |
49 | | - ${static} = crystalStatic.mkPkg mkPkgArgs; |
50 | | - check = pkgs.linkFarmFromDrvs "cb-all-checks" (builtins.attrValues checks); |
51 | | - }; |
| 20 | + check = pkgs.writeScriptBin "check" "nix build .#check --keep-going --print-build-logs"; |
| 21 | + shardFiles = [ "shard.lock" "shards.nix" "shard.yml" ]; |
| 22 | + src = filterSrc (shardFiles ++ [ "Readme" "Changelog" ]); |
| 23 | + specSrc = filterSrc shardFiles; |
| 24 | + lintSrc = filterSrc [ ".ameba.yml" ]; |
52 | 25 |
|
53 | | - devShells.default = pkgs.mkShell { |
54 | | - buildInputs = with crunchy; [ crystal2nix ameba ] |
55 | | - ++ [ crystal check ] |
56 | | - ++ [ pkgs.pcre2 pkgs.pcre pkgs.libyaml ] |
57 | | - ++ pkgs.lib.optionals pkgs.stdenv.isDarwin darwinBuildInputs; |
58 | | - }; |
| 26 | + # returns a function that can read a value for a key in shard.yml |
| 27 | + shardValue = src: key: |
| 28 | + let |
| 29 | + file = src + "/shard.yml"; |
| 30 | + contents = builtins.readFile file; |
| 31 | + match = builtins.split (key + ": ([-a-zA-Z0-9\.]+).*\n") contents; |
| 32 | + in |
| 33 | + if builtins.length match == 3 then |
| 34 | + builtins.head (builtins.head (builtins.tail match)) |
| 35 | + else |
| 36 | + builtins.traceVerbose "file ${file} doesn't have top-level key '${key}'" null; |
59 | 37 |
|
60 | | - checks = { |
61 | | - format = pkgs.stdenvNoCC.mkDerivation { |
62 | | - name = "format"; |
63 | | - src = specSrc; |
64 | | - installPhase = "mkdir $out && crystal tool format --check"; |
65 | | - nativeBuildInputs = [ crystal ]; |
66 | | - dontPatch = true; |
67 | | - dontConfigure = true; |
68 | | - dontBuild = true; |
69 | | - dontFixup = true; |
| 38 | + version = shardValue src "version"; |
| 39 | + in |
| 40 | + rec { |
| 41 | + packages = { |
| 42 | + default = crystal.buildCrystalPackage { |
| 43 | + inherit src version; |
| 44 | + pname = "cb"; |
| 45 | + format = "shards"; |
| 46 | + shardsFile = ./shards.nix; |
| 47 | + buildInputs = [ pkgs.libssh2 ]; |
| 48 | + doCheck = false; |
| 49 | + }; |
| 50 | + check = pkgs.linkFarmFromDrvs "cb-all-checks" (builtins.attrValues checks); |
70 | 51 | }; |
71 | 52 |
|
72 | | - ameba = pkgs.stdenvNoCC.mkDerivation { |
73 | | - name = "ameba"; |
74 | | - src = lintSrc; |
75 | | - installPhase = "mkdir $out && ameba"; |
76 | | - nativeBuildInputs = [ crunchy.ameba ]; |
77 | | - dontPatch = true; |
78 | | - dontConfigure = true; |
79 | | - dontBuild = true; |
80 | | - dontFixup = true; |
| 53 | + devShells.default = pkgs.mkShell { |
| 54 | + buildInputs = with pkgs; [ crystal2nix ameba shards libssh2 ] |
| 55 | + ++ [ crystal check ]; |
81 | 56 | }; |
82 | 57 |
|
83 | | - specs = crystal.buildCrystalPackage { |
84 | | - name = "specs"; |
85 | | - src = specSrc; |
86 | | - HOME = "/tmp"; # needed just for cb, not in general |
87 | | - installPhase = "mkdir $out && crystal spec --progress"; |
88 | | - shardsFile = specSrc + "/shards.nix"; |
89 | | - doCheck = false; |
90 | | - dontPatch = true; |
91 | | - dontBuild = true; |
92 | | - dontFixup = true; |
| 58 | + checks = { |
| 59 | + format = pkgs.stdenvNoCC.mkDerivation { |
| 60 | + name = "format"; |
| 61 | + src = specSrc; |
| 62 | + installPhase = "mkdir $out && crystal tool format --check"; |
| 63 | + nativeBuildInputs = [ crystal ]; |
| 64 | + dontPatch = true; |
| 65 | + dontConfigure = true; |
| 66 | + dontBuild = true; |
| 67 | + dontFixup = true; |
| 68 | + }; |
| 69 | + |
| 70 | + ameba = pkgs.stdenvNoCC.mkDerivation { |
| 71 | + name = "ameba"; |
| 72 | + src = lintSrc; |
| 73 | + installPhase = "mkdir $out && ameba"; |
| 74 | + nativeBuildInputs = [ pkgs.ameba ]; |
| 75 | + dontPatch = true; |
| 76 | + dontConfigure = true; |
| 77 | + dontBuild = true; |
| 78 | + dontFixup = true; |
| 79 | + }; |
| 80 | + |
| 81 | + specs = crystal.buildCrystalPackage { |
| 82 | + name = "specs"; |
| 83 | + src = specSrc; |
| 84 | + buildInputs = [ pkgs.libssh2 ]; |
| 85 | + installPhase = "mkdir $out && HOME=$TMP crystal spec --progress"; |
| 86 | + shardsFile = specSrc + "/shards.nix"; |
| 87 | + doCheck = false; |
| 88 | + dontPatch = true; |
| 89 | + dontBuild = true; |
| 90 | + dontFixup = true; |
| 91 | + }; |
93 | 92 | }; |
94 | 93 | }; |
95 | | - } |
96 | | - ); |
| 94 | + in |
| 95 | + { |
| 96 | + packages = forAllSystems (system: (perSystemOutputs system).packages); |
| 97 | + devShells = forAllSystems (system: (perSystemOutputs system).devShells); |
| 98 | + checks = forAllSystems (system: (perSystemOutputs system).checks); |
| 99 | + }; |
97 | 100 | } |
0 commit comments