]> Git — Sourcephile - literate-phylomemy-example1.git/blob - flake.nix
init
[literate-phylomemy-example1.git] / flake.nix
1 # SPDX-FileCopyrightText: 2024 Jane Doe <jane@example.org>
2 # SPDX-License-Identifier: CC0-1.0
3 {
4 description = "A phylomemy script example";
5 inputs = {
6 # Update with:
7 # nix flake lock --override-input nixpkgs github:NixOS/nixpkgs
8 nixpkgs.url = "flake:nixpkgs";
9 literate-phylomemy.url = "git+https://seed.radicle.garden/z2364hmzZUAGy1nKdSFa1gLSoUE2M.git";
10 };
11 outputs =
12 inputs:
13 let
14 lib = inputs.nixpkgs.lib;
15 # Helper to build for each system in `lib.systems.flakeExposed`.
16 perSystem =
17 f:
18 lib.genAttrs lib.systems.flakeExposed (
19 system:
20 f rec {
21 inherit system;
22 pkgs = import inputs.nixpkgs { inherit system; };
23 haskellPackages = pkgs.haskellPackages;
24 }
25 );
26 in
27 {
28 # `nix -L build`
29 packages = perSystem (
30 { pkgs, system, haskellPackages, ... }:
31 {
32 # The Glasgow Haskell Compiler (GHC)
33 # Here made available as `.#ghc` for script.hs's shebang
34 ghc = haskellPackages.ghcWithPackages (
35 haskellPackages: [
36 # Extra Haskell packages available
37 inputs.literate-phylomemy.packages.${system}.default
38 haskellPackages.bytestring
39 haskellPackages.turtle
40 haskellPackages.pretty-show
41 ]
42 );
43 ghcid = pkgs.ghcid;
44 xdot = pkgs.xdot;
45 # A compiled version of `script.hs`
46 # (instead of an interpreted one when run as `./script.hs`)
47 # To avoid writing a `.cabal` file, `ghc --make` is called directly here,
48 # but should the script become a full fledge executable,
49 # a `.cabal` file should be written instead.
50 default = pkgs.stdenv.mkDerivation {
51 name = "script";
52 src = ./.;
53 buildInputs = [
54 inputs.self.packages.${system}.ghc
55 ];
56 buildPhase = ''
57 mkdir -p $out/bin
58 ghc -o "$out/bin/script" -O2 --make ./script.hs
59 '';
60 };
61 }
62 );
63 # `nix develop` or `direnv allow`
64 devShells = perSystem (
65 { pkgs, system, ... }:
66 {
67 default = pkgs.mkShell {
68 nativeBuildInputs = [
69 inputs.self.packages.${system}.ghc
70 pkgs.haskellPackages.haskell-language-server
71 pkgs.haskellPackages.hlint
72 pkgs.reuse
73 pkgs.xdot
74 ];
75 };
76 }
77 );
78 };
79 }