]> Git — Sourcephile - tmp/julm/android.git/blob - flake.nix
appropriateness: enable `git-hooks`
[tmp/julm/android.git] / flake.nix
1 {
2 description = "Demo Haskell app using Miso";
3 # UsageNote: to run the app inside an Android emulator:
4 # nix -L run .#android-emulator-x86_64
5
6 nixConfig = {
7 extra-substituters = [
8 # ResourceWarning: this flake is not cached
9 "https://haskell-miso-cachix.cachix.org"
10 ];
11 extra-trusted-public-keys = [
12 "haskell-miso-cachix.cachix.org-1:m8hN1cvFMJtYib4tj+06xkKt5ABMSGfe8W7s40x1kQ0="
13 ];
14 #allow-import-from-derivation = "true";
15 };
16
17 inputs = {
18 ghcjs-base.flake = false;
19 ghcjs-base.url = "github:ghcjs/ghcjs-base";
20 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
21 git-hooks.url = "github:cachix/git-hooks.nix";
22 miso-lynx.flake = false;
23 miso-lynx.url = "github:dmjio/miso-lynx";
24 miso.inputs.nixpkgs.follows = "nixpkgs";
25 miso.url = "github:dmjio/miso";
26 nixpkgs.url = "flake:nixpkgs";
27 };
28
29 outputs =
30 inputs:
31 let
32 systems = [
33 "x86_64-linux"
34 "x86_64-darwin"
35 "aarch64-linux"
36 "aarch64-darwin"
37 ];
38 lib = inputs.nixpkgs.lib;
39 perSystem =
40 f:
41 lib.genAttrs lib.systems.flakeExposed (
42 system:
43 f rec {
44 inherit system;
45 pkgs = import inputs.nixpkgs {
46 inherit system;
47 config = {
48 android_sdk.accept_license = true;
49 allowUnfreePredicate = android.allowUnfreePredicate;
50 };
51 overlays = [
52 ];
53 };
54 pkg = "demo";
55 ghc = "ghc9122";
56 haskell = pkgs.callPackage haskell/default.nix {
57 inherit inputs ghc;
58 miso-lynx = inputs.miso-lynx;
59 };
60 ghcPackages = pkgs.haskell.packages.${ghc}.extend (
61 with pkgs.haskell.lib;
62 finalHaskellPkgs: previousHaskellPkgs: {
63 ${pkg} = buildFromSdist (finalHaskellPkgs.callCabal2nix pkg haskell.src { });
64 miso = finalHaskellPkgs.callCabal2nix "miso" inputs.miso { };
65 miso-lynx = finalHaskellPkgs.callCabal2nix "miso-lynx" inputs.miso-lynx { };
66 }
67 );
68 android = pkgs.callPackage android/default.nix {
69 inherit inputs system;
70 inherit (haskell) mainLynxBundle;
71 };
72 }
73 );
74 in
75 rec {
76 # nix -L build
77 packages = perSystem (
78 args: with args; {
79 default = android.packages.default;
80 android = android.packages.default;
81 android-emulator-x86_64 = android.packages.android-emulator-x86_64;
82 }
83 );
84
85 # nix -L develop
86 devShells = perSystem (
87 args: with args; {
88 default = ghcPackages.shellFor {
89 packages = haskellPackages: [ haskellPackages.${pkg} ];
90 nativeBuildInputs = android.devShells.default.nativeBuildInputs ++ [
91 # CompatibilityNote: pull haskell-language-server from ghcPackages
92 # to ensure its compatibility with the selected GHC.
93 ghcPackages.haskell-language-server
94 #pkgs.emscripten
95 pkgs.ghciwatch
96 pkgs.haskellPackages.cabal-install
97 pkgs.haskellPackages.ghcid
98 pkgs.haskellPackages.hlint
99 pkgs.http-server
100 pkgs.reuse
101 ];
102 withHoogle = false;
103 shellHook = ''
104 ${android.devShells.default.shellHook}
105 ${checks.${system}.git-hooks-check}
106 '';
107 };
108 }
109 );
110
111 # nix flake check
112 checks = perSystem (
113 args: with args; {
114 git-hooks-check = inputs.git-hooks.lib.${system}.run {
115 src = ./.;
116 hooks = {
117 cabal-fmt.enable = true;
118 fourmolu.enable = true;
119 hlint.enable = true;
120 nixfmt-rfc-style.enable = true;
121 ormolu.settings.cabalDefaultExtensions = true;
122 reuse = {
123 enable = true;
124 entry = "${pkgs.reuse}/bin/reuse lint";
125 pass_filenames = false;
126 };
127 };
128 };
129 }
130 );
131 };
132
133 }