|
| 1 | +# Nix configuration for QueueSheet |
| 2 | +# |
| 3 | +# Usage: |
| 4 | +# |
| 5 | +# * Build QueueSheet with the default compiler: |
| 6 | +# |
| 7 | +# $ nix-build |
| 8 | +# |
| 9 | +# * Build QueueSheet with a specific compiler version: |
| 10 | +# |
| 11 | +# $ nix-build --argstr compiler ghc8104 |
| 12 | + |
| 13 | +{ # This string argument specifies the compiler (example: "ghc8104"). When |
| 14 | + # not specified, the default compiler (configured below) is used. |
| 15 | + compiler ? null |
| 16 | + # This path argument specifies the packages to use. When not specified, a |
| 17 | + # working revision for the selected compiler is used. When a working |
| 18 | + # revision for the selected compiler is not defined (below), the packages |
| 19 | + # configured on the filesystem are used. |
| 20 | +, nixpkgs ? null |
| 21 | + # This boolean argument is used by `shell.nix`. When `True`, build tools |
| 22 | + # are added to the derivation. |
| 23 | +, isShell ? false |
| 24 | +}: |
| 25 | + |
1 | 26 | let |
2 | 27 |
|
3 | | - nixpkgsRev = "c92ca95afb5043bc6faa0d526460584eccff2277"; |
4 | | - compilerVersion = "ghc8104"; |
| 28 | + # This string defines the default compiler version. |
| 29 | + defaultCompiler = "ghc8104"; |
5 | 30 |
|
6 | | - githubTarball = owner: repo: rev: |
7 | | - builtins.fetchTarball { url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; }; |
| 31 | + # This set defines working revisions for supported compiler versions. |
| 32 | + nixpkgsRevs = { |
| 33 | + ghc8104 = "c92ca95afb5043bc6faa0d526460584eccff2277"; |
| 34 | + ghc884 = "c92ca95afb5043bc6faa0d526460584eccff2277"; |
| 35 | + # ghc865 = "2d9888f61c80f28b09d64f5e39d0ba02e3923057"; NOTE ginger broken |
| 36 | + ghc844 = "6a80140fdf2157d1a5500a04c87033c0dcd6bf9b"; |
| 37 | + ghc822 = "6a80140fdf2157d1a5500a04c87033c0dcd6bf9b"; |
| 38 | + }; |
8 | 39 |
|
9 | | - gitIgnore = pkgs.nix-gitignore.gitignoreSourcePure; |
| 40 | + # This function fetches the specified nixpkgs revision. |
| 41 | + nixpkgsTarball = rev: |
| 42 | + builtins.fetchTarball { |
| 43 | + url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; |
| 44 | + }; |
10 | 45 |
|
11 | | - config = { |
12 | | - packageOverrides = super: let self = super.pkgs; in rec { |
13 | | - haskell = super.haskell // { |
14 | | - packageOverrides = self: super: { |
15 | | - haskell-nix = super.callCabal2nix "haskell-nix" (gitIgnore [./.gitignore] ./.) {}; |
16 | | - }; |
17 | | - }; |
| 46 | + # This function fetches source from GitHub by tag. |
| 47 | + githubTagTarball = owner: repo: tag: |
| 48 | + builtins.fetchTarball { |
| 49 | + url = "https://github.com/${owner}/${repo}/archive/refs/tags/${tag}.tar.gz"; |
18 | 50 | }; |
19 | | - }; |
20 | 51 |
|
21 | | - pkgs = import (githubTarball "NixOS" "nixpkgs" nixpkgsRev) { inherit config; }; |
22 | | - compilerSet = pkgs.haskell.packages."${compilerVersion}"; |
| 52 | + # The compiler is explicitly specified or the default. |
| 53 | + compiler' = if isNull compiler then defaultCompiler else compiler; |
23 | 54 |
|
24 | | -in { |
| 55 | + # Packages are explicitly specified, those for the revision defined for the |
| 56 | + # selected compiler, or those configured on the filesystem. |
| 57 | + pkgs = if isNull nixpkgs |
| 58 | + then if nixpkgsRevs ? ${compiler'} |
| 59 | + then import (nixpkgsTarball nixpkgsRevs.${compiler'}) {} |
| 60 | + else import <nixpkgs> {} |
| 61 | + else nixpkgs; |
25 | 62 |
|
26 | | - inherit pkgs; |
| 63 | + # Git ignore functionality from a fixed `nixpkgs` revision is used. Old |
| 64 | + # revisions do not work, proably due to an API change. |
| 65 | + gitIgnore = ( |
| 66 | + import (nixpkgsTarball nixpkgsRevs.ghc8104) {} |
| 67 | + ).nix-gitignore.gitignoreSourcePure; |
27 | 68 |
|
28 | | - shell = compilerSet.shellFor { |
29 | | - packages = p: [p.haskell-nix]; |
30 | | - buildInputs = with pkgs; [ |
31 | | - compilerSet.cabal-install |
32 | | - ]; |
33 | | - }; |
| 69 | +in |
34 | 70 |
|
35 | | -} |
| 71 | + # Configure the development environment for the package using the selected |
| 72 | + # packages and compiler. |
| 73 | + pkgs.haskell.packages.${compiler'}.developPackage { |
| 74 | + root = gitIgnore [./.gitignore] ./.; |
| 75 | + name = "queue-sheet"; |
| 76 | + source-overrides = { |
| 77 | + ttc = githubTagTarball "ExtremaIS" "ttc-haskell" "ttc-haskell-1.1.0.0"; |
| 78 | + }; |
| 79 | + modifier = drv: |
| 80 | + if isShell |
| 81 | + then pkgs.haskell.lib.addBuildTools drv |
| 82 | + [ pkgs.cabal-install pkgs.texlive.combined.scheme-small |
| 83 | + ] |
| 84 | + else drv; |
| 85 | + } |
0 commit comments