Skip to content

Commit 9118909

Browse files
authored
Add Nix flakes (#800)
* added nix flake files * added nix installation * added install * added default.nix * added installPhase * Renamed Build to Nix * changed cubical derivation * added FinWeak * added more indentation * removed useless {n} * added more indentation * added agdaWithCubical in flake.nix * removed unnecessary FinWeak * added nix flake in install.md * changed CI to master * changed name to nix flakes instructions * improved nix flakes * nixpkgs is referred to nixos-22.05 * changed defaultPackage to default * updated flake.nix * added install.md instruction * updated nix flakes * changed to flake-compat
1 parent 0420f86 commit 9118909

File tree

6 files changed

+184
-0
lines changed

6 files changed

+184
-0
lines changed

.github/workflows/ci-nix.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Nix
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
paths:
8+
- '**.nix'
9+
- 'flake.lock'
10+
11+
jobs:
12+
deploy:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: cachix/install-nix-action@v17
17+
- name: Build
18+
run: nix build -v --print-build-logs

INSTALL.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,42 @@ cubical
282282
$ cat .agda/libraries
283283
/path/to/cubical.agda-lib
284284
```
285+
286+
Nix flakes instructions
287+
=======================
288+
289+
Create a nix flake like this one:
290+
```nix
291+
{
292+
inputs.cubical = {
293+
url = "github:agda/cubical";
294+
inputs.nixpkgs.follows = "nixpkgs";
295+
};
296+
outputs = { self, nixpkgs, cubical }:
297+
let system = "x86_64-linux";
298+
cub-packages = cubical.packages.${system};
299+
cubical-lbry = cub-packages.cubical;
300+
in
301+
with import nixpkgs { system = system; };
302+
rec {
303+
packages.${system} = {
304+
cubical = cubical-lbry;
305+
agda = agda.withPackages [cubical-lbry];
306+
};
307+
defaultPackage.${system} = packages.${system}.agda;
308+
};
309+
}
310+
```
311+
cubical-lbry is the cubical library that you have to add in Agda packages.
312+
313+
You can test if Agda with the cubical library is working after adding this file:
314+
`test.agda`
315+
```agda
316+
{-# OPTIONS --cubical #-}
317+
open import Cubical.Foundations.Prelude
318+
```
319+
And running:
320+
```shell
321+
nix --extra-experimental-features "nix-command flakes" shell
322+
agda -l cubical -i . test.agda
323+
```

RELEASE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ Post-release
1414
include: .
1515
depend:
1616
```
17+
18+
* Increment the `version` field in `flake.nix`.
19+
20+
* Update flake inputs by running `nix flake update`.

default.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(import
2+
(
3+
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
4+
fetchTarball {
5+
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
6+
sha256 = lock.nodes.flake-compat.locked.narHash;
7+
}
8+
)
9+
{ src = ./.; }
10+
).defaultNix

flake.lock

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

flake.nix

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
description = "Cubical Agda";
3+
4+
inputs.nixpkgs.url = "nixpkgs/nixpkgs-unstable";
5+
inputs.flake-utils.url = "github:numtide/flake-utils";
6+
inputs.flake-compat = {
7+
url = "github:edolstra/flake-compat";
8+
flake = false;
9+
};
10+
11+
outputs = { self, flake-compat, flake-utils, nixpkgs }:
12+
let
13+
inherit (nixpkgs.lib) cleanSourceWith hasSuffix;
14+
overlay = final: prev: {
15+
cubical = final.agdaPackages.mkDerivation rec {
16+
pname = "cubical";
17+
version = "0.4";
18+
19+
src = cleanSourceWith {
20+
filter = name: type:
21+
!(hasSuffix ".nix" name)
22+
;
23+
src = ./.;
24+
};
25+
26+
27+
LC_ALL = "C.UTF-8";
28+
29+
# The cubical library has several `Everything.agda` files, which are
30+
# compiled through the make file they provide.
31+
nativeBuildInputs = [ final.ghc ];
32+
buildPhase = ''
33+
make
34+
'';
35+
meta = {
36+
description = "An experimental library for Cubical Agda";
37+
homepage = "https://github.com/agda/cubical";
38+
license = "MIT License";
39+
};
40+
};
41+
agdaWithCubical = final.agdaPackages.agda.withPackages [final.cubical];
42+
};
43+
overlays = [ overlay ];
44+
in
45+
{ overlays.default = overlay; } //
46+
flake-utils.lib.eachDefaultSystem (system:
47+
let pkgs = import nixpkgs { inherit system overlays; };
48+
in rec {
49+
packages = with pkgs; rec {
50+
inherit cubical agdaWithCubical;
51+
default = cubical;
52+
};
53+
});
54+
}

0 commit comments

Comments
 (0)