Skip to content

Commit 88eab9d

Browse files
authored
Merge pull request #1244 from peterbecich/update-flake
update `flake.nix` for recent `haskell-flake`
2 parents 6d82054 + 1b2d9c6 commit 88eab9d

File tree

4 files changed

+121
-157
lines changed

4 files changed

+121
-157
lines changed

README.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,81 @@ This is the `hackage-server` code. This is what powers <http://hackage.haskell.o
77

88
## Installing dependencies
99

10-
`hackage-server` depends on `libgd` and `zlib`. You'll also need `libbrotli-dev` for enabling tests.
10+
`hackage-server` depends on `libgd`, `zlib`, and other system libraries. You'll also need `libbrotli-dev` for enabling tests.
1111

12-
### [`nix develop`](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-develop.html)
12+
You can use the Nix package manager to provide these dependencies, or install them manually.
1313

14-
If you have the [Nix package manager](https://nixos.org/) installed, the easiest way to run `hackage-server` is by using `nix develop`. It should be unnecessary to install any dependencies manually. In this repository:
14+
### Using the [Nix package manager](https://nixos.org/) and provided [Nix Flake](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html)
15+
16+
If you have the Nix package manager installed, you can build and run `hackage-server` without manually installing any dependencies.
17+
18+
This uses `flake.nix`, implemented with [`srid/haskell-flake`](https://github.com/srid/haskell-flake).
19+
20+
There are at least three ways to use this `flake.nix`. Clone this repository, enter the repository directory, then choose one of these options:
21+
22+
#### [`nix develop`](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-develop.html)
1523

1624
nix develop
1725

1826
(in develop shell)
19-
$ cabal v2-run -- hackage-server init
27+
$ cabal v2-run -- hackage-server init --static-dir=datafiles
2028

21-
$ cabal v2-run -- hackage-server run --static-dir=datafiles/ --base-uri=http://127.0.0.1:8080
29+
$ cabal v2-run -- hackage-server run --static-dir=datafiles --base-uri=http://127.0.0.1:8080
2230
hackage-server: Ready! Point your browser at http://127.0.0.1:8080
2331

24-
`flake.nix` is provided; it uses [`srid/haskell-flake`](https://github.com/srid/haskell-flake).
32+
Note the `init` command will create a new folder `state` in your working directory.
2533

2634
If you have [direnv](https://direnv.net/), `direnv allow` will load this `nix develop` shell automatically.
2735

28-
`nix build` will build a `hackage-server` executable in `result/`. The Hackage dependencies are provided by the inputs specified in `flake.nix`. Because some of these inputs are unpublished commits on GitHub, this build should not be considered authoritative.
36+
#### [`nix build`](https://nixos.org/manual/nix/stable/command-ref/nix-build.html)
37+
38+
nix build
39+
40+
This will produce a `hackage-server` executable in `result/`.
41+
42+
For this executable, Hackage dependencies are not pulled from Hackage directly like usual. Hackage dependencies are provided by the [Nixpkgs](https://search.nixos.org/packages) [`haskell-updates`](https://github.com/NixOS/nixpkgs/tree/haskell-updates) branch, and a few [overrides in `flake.nix`](https://zero-to-flakes.com/haskell-flake/dependency#using-hackage-versions).
43+
44+
#### [`nix run`](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-run)
45+
46+
`nix run` is more convenient to use than `nix build`.
47+
48+
As with `nix build`, Hackage dependencies are not pulled from Hackage directly like usual. See caveat above.
49+
50+
List the available [Flake Apps](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-run#apps) with [`nix flake show`](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake-show.html):
51+
52+
$ nix flake show
53+
...
54+
├───apps
55+
...
56+
│ │ ├───hackage-build: app
57+
│ │ ├───hackage-import: app
58+
│ │ ├───hackage-mirror: app
59+
│ │ └───hackage-server: app
60+
...
61+
62+
Run the `hackage-server` App:
63+
64+
nix run .#hackage-server -- init --static-dir=datafiles
65+
66+
nix run .#hackage-server -- run --static-dir=datafiles --base-uri=http://127.0.0.1:8080
67+
68+
The `.` refers to the `flake.nix` in your working directory. `#hackage-server` refers to the App specified in that `flake.nix`.
69+
70+
`hackage-server` is the default App, so those commands can be shortened:
71+
72+
nix run . -- init --static-dir=datafiles
73+
74+
nix run . -- run --static-dir=datafiles --base-uri=http://127.0.0.1:8080
75+
76+
##### Not working
77+
78+
Please note this App *cannot* be run [directly from GitHub](https://determinate.systems/posts/nix-run) like this:
79+
80+
nix run github:haskell/hackage-server -- init --static-dir=datafiles
81+
82+
nix run github:haskell/hackage-server -- run --static-dir=datafiles --base-uri=http://127.0.0.1:8080
83+
84+
because `hackage-server` expects the directories `state` and `datafiles` to exist in the working directory.
2985

3086
### Manually
3187

cabal.project

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
packages:
2+
.
3+
4+
-- This comment moved below "packages" to fix parsing of this file
5+
-- by flake.nix
6+
17
-- This project config requires cabal 2.4 or later
28

39
-- If in doubt, use GHC 8.8 to build hackage-server; see
@@ -6,8 +12,7 @@
612
--
713
-- with-compiler: ghc-8.8
814

9-
packages: .
10-
15+
1116
allow-newer: rss:time, rss:base
1217

1318
-----------------------------------------------------------------------------

flake.lock

Lines changed: 13 additions & 96 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,60 @@
33
nixpkgs.url = "github:nixos/nixpkgs/haskell-updates";
44
flake-parts.url = "github:hercules-ci/flake-parts";
55
haskell-flake.url = "github:srid/haskell-flake";
6-
treefmt-nix.url = "github:numtide/treefmt-nix";
76
flake-root.url = "github:srid/flake-root";
8-
mission-control.url = "github:Platonic-Systems/mission-control";
9-
10-
nixpkgs-140774-workaround.url = "github:srid/nixpkgs-140774-workaround";
7+
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
118
};
129

1310
outputs = inputs@{ self, nixpkgs, flake-parts, ... }:
1411
flake-parts.lib.mkFlake { inherit inputs; } {
15-
systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
12+
systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
1613
imports = [
1714
inputs.haskell-flake.flakeModule
1815
inputs.flake-root.flakeModule
19-
inputs.mission-control.flakeModule
2016
];
2117
perSystem = { self', system, lib, config, pkgs, ... }: {
2218
# The "main" project. You can have multiple projects, but this template
2319
# has only one.
24-
haskellProjects.main = {
25-
# basePackages = pkgs.haskell.packages.ghc927;
26-
# basePackages = pkgs.haskell.packages.ghc944;
27-
imports = [
28-
inputs.nixpkgs-140774-workaround.haskellFlakeProjectModules.default
29-
];
30-
packages.hackage-server.root = ./.; # Auto-discovered by haskell-flake
31-
32-
overrides = self: super: {
33-
Cabal = super.Cabal_3_10_1_0;
34-
Cabal-syntax = super.Cabal-syntax_3_10_1_0;
35-
36-
ghcide = pkgs.haskell.lib.dontCheck (self.callHackage "ghcide" "1.9.0.0" {});
37-
38-
streamly = self.callHackage "streamly" "0.9.0" {};
39-
streamly_0_9_0 = self.callHackage "streamly" "0.9.0" {};
20+
packages.default = config.packages.hackage-server;
21+
haskellProjects.default = {
22+
settings = {
23+
hackage-server.check = false;
24+
heist.check = false;
4025
};
41-
devShell = {
42-
hlsCheck.enable = false;
26+
packages = {
27+
Cabal.source = "3.10.1.0";
28+
Cabal-syntax.source = "3.10.1.0";
29+
attoparsec-aeson.source = "2.1.0.0";
30+
hedgehog.source = "1.3";
4331
};
44-
};
45-
46-
packages.default = pkgs.haskell.lib.dontCheck (self'.packages.main-hackage-server);
47-
48-
# TODO: fix HLS https://github.com/haskell/haskell-language-server/issues/3518
49-
# Default shell.
50-
# devShells.default =
51-
# config.mission-control.installToDevShell self'.devShells.main;
52-
devShells.default = pkgs.mkShell {
53-
buildInputs =
54-
with pkgs;
55-
[ cabal-install
56-
ghc
57-
58-
glibc
59-
icu67
60-
zlib
61-
openssl
62-
cryptodev
63-
pkg-config
64-
brotli
32+
devShell = {
33+
tools = hp: {
34+
# Setting to null should remove this tool from defaults.
35+
ghcid = null;
36+
haskell-language-server = null;
37+
inherit (pkgs)
38+
cabal-install
39+
ghc
6540

66-
gd
67-
libpng
68-
libjpeg
69-
fontconfig
70-
freetype
71-
expat
41+
# https://github.com/haskell/hackage-server/pull/1219#issuecomment-1597140858
42+
# glibc
43+
# icu67
44+
# zlib
45+
openssl
46+
cryptodev
47+
pkg-config
48+
brotli
7249

73-
];
50+
gd
51+
libpng
52+
libjpeg
53+
fontconfig
54+
freetype
55+
expat
56+
;
57+
};
58+
hlsCheck.enable = false;
59+
};
7460
};
7561
};
7662
};

0 commit comments

Comments
 (0)