]> Git — Sourcephile - literate-phylomemy-example1.git/blob - flake.nix
maintenance(deps): update `nixpkgs`, `literate-phylomemy` and `logic`
[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 literate-phylomemy.inputs.nixpkgs.follows = "nixpkgs";
11 # When working on a local clone:
12 #literate-phylomemy.url = "git+file:///home/julm/work/sourcephile/haskell/literate-phylomemy";
13 logic.url = "git+https://radicle-mermet.sourcephile.fr/z3795BqJN8hSMGkyAUr8hHviEEi2H.git";
14 logic.inputs.nixpkgs.follows = "nixpkgs";
15 };
16 outputs =
17 inputs:
18 let
19 lib = inputs.nixpkgs.lib;
20 # Helper to build for each system in `lib.systems.flakeExposed`.
21 perSystem =
22 f:
23 lib.genAttrs lib.systems.flakeExposed (
24 system:
25 f rec {
26 inherit system;
27 pkgs = import inputs.nixpkgs { inherit system; };
28 haskellPackages = pkgs.haskellPackages;
29 }
30 );
31 in
32 {
33 # `nix -L build`
34 packages = perSystem (
35 { pkgs, system, haskellPackages, ... }:
36 {
37 # The Glasgow Haskell Compiler (GHC)
38 # Here made available as `.#ghc` for script.hs's shebang
39 ghc = haskellPackages.ghcWithPackages (
40 haskellPackages: [
41 # Extra Haskell packages available
42 inputs.literate-phylomemy.packages.${system}.default
43 inputs.logic.packages.${system}.default
44 haskellPackages.bytestring
45 haskellPackages.turtle
46 haskellPackages.pretty-show
47 ]
48 );
49 ghcid = pkgs.ghcid;
50 xdot = pkgs.xdot;
51 # A compiled version of `script.hs`
52 # (instead of an interpreted one when run as `./script.hs`)
53 # To avoid writing a `.cabal` file, `ghc --make` is called directly here,
54 # but should the script become a full fledge executable,
55 # a `.cabal` file should be written instead.
56 default = pkgs.stdenv.mkDerivation {
57 name = "script";
58 src = ./.;
59 buildInputs = [
60 inputs.self.packages.${system}.ghc
61 ];
62 buildPhase = ''
63 mkdir -p $out/bin
64 ghc -o "$out/bin/script" -O2 --make ./script.hs
65 '';
66 };
67 }
68 );
69 # `nix develop` or `direnv allow`
70 devShells = perSystem (
71 { pkgs, system, ... }:
72 {
73 default = pkgs.mkShell {
74 nativeBuildInputs = [
75 inputs.self.packages.${system}.ghc
76 pkgs.haskellPackages.haskell-language-server
77 pkgs.haskellPackages.hlint
78 pkgs.reuse
79 pkgs.xdot
80 ];
81 };
82 }
83 );
84 };
85 }