-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
136 lines (118 loc) · 3.88 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{
description = "Fathom related experiments";
# Flake dependency specification
#
# To update all flake inputs:
#
# $ nix flake update --commit-lockfile
#
# To update individual flake inputs:
#
# $ nix flake lock --update-input <input> ... --commit-lockfile
#
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
# Externally extensible flake systems. See <https://github.com/nix-systems/nix-systems>.
systems.url = "github:nix-systems/default";
# Follow the `systems` input in flakes that still use `flake-utils`.
flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};
# Main package repository for opam, the package manager of OCaml.
opam-repository = {
url = "github:ocaml/opam-repository";
flake = false;
};
# Create nix derivations from opam package definitions.
opam-nix = {
url = "github:tweag/opam-nix";
inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
inputs.opam-repository.follows = "opam-repository";
};
};
outputs = { systems, opam-nix, nixpkgs, ... }:
let
# Nixpkgs library functions.
lib = nixpkgs.lib;
# Iterate over each system, configured via the `systems` input.
eachSystem = lib.genAttrs (import systems);
# Local packages, detected from the package definition files in `./opam/`.
localPackagesQuery = eachSystem (system:
let
opam-lib = opam-nix.lib.${system};
in
lib.mapAttrs (_: lib.last)
(opam-lib.listRepo (opam-lib.makeOpamRepo ./.)));
# Development package versions.
devPackagesQuery = {
ocaml-lsp-server = "*";
ocamlformat = "*";
utop = "*";
};
# Development package versions, along with the base compiler tools, used
# when building the opam project with `opam-nix`.
allPackagesQuery = devPackagesQuery // {
# Use the OCaml compiler from nixpkgs
ocaml-system = "*";
};
# Package-specific derivation overrides.
overlay = eachSystem (system:
final: prev: { });
buildOpamProject = system: options:
(opam-nix.lib.${system}.buildOpamProject' options ./. allPackagesQuery).overrideScope
overlay.${system};
legacyPackages = eachSystem (system:
buildOpamProject system { });
packages = eachSystem (system:
lib.getAttrs
(lib.attrNames localPackagesQuery.${system})
legacyPackages.${system});
devPackages = eachSystem (system:
lib.getAttrs
(lib.attrNames devPackagesQuery)
legacyPackages.${system});
in
{
# Exposed packages that can be built or run with `nix build` or
# `nix run` respectively:
#
# $ nix build .#<name>
# $ nix run .#<name>
# $ nix run .#<name> -- <args>
#
inherit packages;
# Used for nixpkgs packages, also accessible via `nix build`:
#
# $ nix build .#<name>
#
inherit legacyPackages;
# Development shells
#
# $ nix develop .#<name>
# $ nix develop .#<name> --command dune build @test
#
devShells = eachSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
# Packages with development dependencies enabled
packages =
lib.getAttrs
(lib.attrNames localPackagesQuery.${system})
(buildOpamProject system {
resolveArgs.with-doc = true;
resolveArgs.with-test = true;
});
in
{
default = pkgs.mkShell {
inputsFrom = lib.attrValues packages;
buildInputs = lib.attrValues devPackages.${system} ++ [
pkgs.nixpkgs-fmt
pkgs.nodejs_23
];
};
});
};
}