]> Git — Sourcephile - tmp/julm/alpmestan-sounds.git/blob - flake.nix
repro(env): add a Nix flake
[tmp/julm/alpmestan-sounds.git] / flake.nix
1 {
2 description = "sounds";
3 inputs = {
4 nixpkgs.url = "flake:nixpkgs";
5 git-hooks.url = "github:cachix/git-hooks.nix";
6 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
7 proteaaudio = { url = "github:csabahruska/proteaaudio"; flake = false; };
8 };
9 outputs = inputs:
10 let
11 pkg = "sounds";
12 lib = inputs.nixpkgs.lib;
13 fileInputs = with lib.fileset; toSource {
14 root = ./.;
15 fileset = unions [
16 ./sounds.cabal
17 ./CHANGELOG.md
18 #./Readme.md
19 ./LICENSE
20 (fileFilter (file: lib.any file.hasExt [ "hs" ]) ./exe)
21 ];
22 };
23 perSystem = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
24 inherit system;
25 pkgs = inputs.nixpkgs.legacyPackages.${system};
26 haskellPackages = pkgs.haskellPackages.extend (with pkgs.haskell.lib.compose; finalHaskellPkgs: previousHaskellPkgs: {
27 ${pkg} = buildFromSdist (finalHaskellPkgs.callCabal2nix pkg fileInputs { });
28 lambdasound = (doJailbreak (unmarkBroken previousHaskellPkgs.lambdasound)).overrideAttrs (previousAttrs: {
29 # ExplanationNote: one of lambdasound's test tries to write in `$HOME`
30 # which defaults to the non-existent directory `/homeless-shelter`.
31 HOME = "/tmp";
32 });
33 plots = doJailbreak (unmarkBroken previousHaskellPkgs.plots);
34 proteaaudio = lib.pipe
35 (finalHaskellPkgs.callCabal2nix "proteaaudio" "${inputs.proteaaudio}/proteaaudio" {
36 libpulse = pkgs.libpulseaudio;
37 libpulse-simple = pkgs.libpulseaudio.dev;
38 }) [
39 (overrideCabal (previousDrv: {
40 # ExplanationNote: because
41 # `proteaaudio/proteaaudio/Sound/ProteaAudio.chs`
42 # symlinks to `../../chs/Binding.chs`
43 # the sibling directory ${inputs.proteaaudio}/cbits
44 # must be available too.
45 src = inputs.proteaaudio;
46 postUnpack = "sourceRoot=$sourceRoot/proteaaudio";
47 }))
48 ];
49 });
50 });
51 in
52 rec {
53 # nix -L build
54 packages = perSystem ({ haskellPackages, ... }: {
55 default = haskellPackages.${pkg};
56 });
57 # nix -L develop or direnv allow
58 devShells = perSystem ({ pkgs, haskellPackages, system, ... }: {
59 default =
60 haskellPackages.shellFor {
61 packages = ps: [
62 ps.${pkg}
63 ];
64 nativeBuildInputs = [
65 haskellPackages.cabal-install
66 haskellPackages.cabal2nix
67 haskellPackages.haskell-language-server
68 haskellPackages.hlint
69 pkgs.ghciwatch
70 pkgs.git-cliff
71 pkgs.reuse
72 ];
73 #withHoogle = true;
74 inherit (checks.${system}.git-hooks-check) shellHook;
75 };
76 });
77 # nix flake check
78 checks = perSystem (args: with args; {
79 git-hooks-check = inputs.git-hooks.lib.${system}.run {
80 src = ./.;
81 hooks = {
82 cabal-fmt.enable = true;
83 fourmolu.enable = true;
84 hlint.enable = true;
85 nixpkgs-fmt.enable = true;
86 ormolu.settings.cabalDefaultExtensions = true;
87 /*
88 reuse = {
89 enable = true;
90 entry = "${pkgs.reuse}/bin/reuse lint";
91 pass_filenames = false;
92 };
93 */
94 };
95 };
96 });
97 };
98 }