Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flake.nix for Nix package manager #83

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ To download a CIEL binary:
<https://gitlab.com/vindarel/ciel/-/pipelines>, download the latest
artifacts, unzip the `ciel-v0-{platform}.zip` archive and run `ciel-v0-{platform}/ciel`.
- if you use the [Guix](https://guix.gnu.org/) package manager, install package `sbcl-ciel-repl`.
- if you use the [Nix](https://nixos.org/) package manager in Linux and macOS, install package `ciel` and `ciel` in SBCL.

CIEL is currently built for the following platforms:

Expand Down Expand Up @@ -128,6 +129,85 @@ In either case, you get a Lisp environment with CIEL preloaded, so all you have
(in-package :ciel-user)
```

### Nix

CIEL's repository contains a `flake.nix` file that can be used to build CIEL with Nix.
To use it, you need to add the CIEL repository to your `flake.nix` file.

#### Install CIEL with home-manager

You can use CIEL with home-manager by adding the CIEL repository to your `home.nix` file.

1. Add the CIEL repository to your `flake.nix` file.
2. Add the CIEL overlay to your Nixpkgs overlay list.
3. Add CIEL to your `home.packages` list.

```diff
# flake.nix
inputs = {
+ # Add the CIEL repository
+ ciel.url = "github:ciel-lang/CIEL";
+ ciel.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, ciel, nixpkgs, ... }:
flake-utils.lib.eachDefaultSystem (system: {
legacyPackages.homeConfigurations."USERNAME" = home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs {
inherit system;
overlays = [
+ # Add the CIEL overlay
+ ciel.overlays.default
];
};
```

```diff
# home.nix
packages = with pkgs; [
+ # Use CIEL command line interface
+ ciel
+ # Use CIEL as a library
+ sbcl.withPackages (ps: [ ps.ciel ]);
];
```

#### Install CIEL to your devShell

You need to modify your `flake.nix` file to include CIEL in your development environment.

1. Add the CIEL repository to your `flake.nix` file.
2. Add the CIEL overlay to your Nixpkgs overlay list.
3. Add CIEL to your `devShell` packages or any other package set.

```diff
{
inputs = {
+ # Add the CIEL repository
+ ciel.url = "github:ciel-lang/CIEL";
+ ciel.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, ciel, nixpkgs }:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
+ # Add the CIEL overlay
+ ciel.overlays.default
];
};
in
{
devShell = nixpkgs.mkShell {
packages = with pkgs; [
+ # Use CIEL command line interface
+ ciel
+ # Use CIEL as a library
+ sbcl.withPackages (ps: [ ps.ciel ]);
];
};
};
}
```

## Using CIEL as a library in your Lisp code

Expand Down
58 changes: 58 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

171 changes: 171 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
description = "A basic flake to with flake-parts";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
};

outputs = inputs@{ nixpkgs, flake-parts, ... }:

flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ flake-parts.flakeModules.easyOverlay ];
systems = nixpkgs.lib.platforms.all;
perSystem = { pkgs, lib, ... }:
let
### Package Information ###
src = ./.;
pygments = pkgs.python312Packages.pygments;
nativeLibs = with pkgs;
[
asdf
zstd
pygments
] ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [
inotify-tools
];
lisp = pkgs.sbcl;
lispLibs = with lisp.pkgs; [
## (asdf:system-depends-on (asdf:find-system "ciel"))
### Exception:
### cl-json-pointer/synonyms -> cl-json-pointer-with-synonyms
### moira/light -> moira
### Note:
### termp and cl-json-pointer-with-synonyms are not in Quicklisp and are fetched from GitHub
cl-reexport
cl-ansi-text
access
alexandria
arrow-macros
file-finder
moira
bordeaux-threads
trivial-monitored-thread
lparallel
cl-cron
closer-mop
cl-ansi-text
cl-csv
shasht
cl-json-pointer-synonyms
dissect
fset
file-notify
generic-cl
dexador
hunchentoot
easy-routes
quri
lquery
spinneret
cl-ftp
clingon
local-time
modf
parse-float
parse-number
dbi
sxql
vgplot
cl-ppcre
str
secret-values
progressons
termp
pythonic-string-reader
trivia
trivial-arguments
trivial-package-local-nicknames
trivial-types
metabang-bind
defstar
for
trivial-do
cmd
serapeum
shlex
fiveam
which
log4cl
printv
repl-utilities
named-readtables
clesh
quicksearch
## (asdf:system-depends-on (asdf:find-system "ciel/repl"))
cl-readline
lisp-critic
magic-ed
];
### Package Information End ###
version =
let
asd = builtins.readFile ./ciel.asd;
res = builtins.split '':version[[:space:]]*"([^"]*)"'' asd;
ver = builtins.elemAt (builtins.elemAt res 1) 0;
in
"${ver}-git";
cl-json-pointer-synonyms = lisp.buildASDFSystem {
pname = "cl-json-pointer";
version = "20221106-git";
systems = [ "cl-json-pointer" "cl-json-pointer/synonyms" ];
src = builtins.fetchGit {
url = "https://github.com/y2q-actionman/cl-json-pointer";
rev = "f6760e2a02972783f96b92a15f801e14a6828e0c";
};
lispLibs = with lisp.pkgs; [ alexandria closer-mop ];
};
termp = lisp.buildASDFSystem {
pname = "termp";
version = "20241103-git";
systems = [ "termp" ];
src = builtins.fetchGit {
url = "https://github.com/vindarel/termp";
rev = "29789fe83db624679b6f341e3fae3f2577ce6a45";
};
};
ciel = lisp.buildASDFSystem {
inherit version src lispLibs nativeLibs;
pname = "ciel";
systems = [ "ciel" "ciel/repl" ];
};
lisp' = lisp.withPackages (ps: [ ciel ]) // { inherit (lisp) meta; };
ciel-repl-image = pkgs.stdenv.mkDerivation {
pname = "ciel-repl";
inherit version src;
nativeBuildInputs = [ lisp' pkgs.asdf ];
buildInputs = [ pygments ];
buildPhase = "# no build phase";
installPhase = ''
mkdir -p $out
export LD_LIBRARY_PATH=${lib.makeLibraryPath nativeLibs}
${lisp'}/bin/${lisp'.meta.mainProgram} --noinform <<EOF
(load (sb-ext:posix-getenv "ASDF"))
(asdf:load-system :ciel)
(asdf:load-system :ciel/repl)
(setf sbcli:*syntax-highlighting* t)
(setf sbcli::*pygmentize* "${pygments}/bin/pygmentize")
(uiop:dump-image "$out/ciel")
EOF
'';
};
ciel-repl = pkgs.writeShellScriptBin "ciel" ''
export LD_LIBRARY_PATH=${lib.makeLibraryPath nativeLibs}
exec ${lisp'}/bin/${lisp'.meta.mainProgram} --noinform \
--core '${ciel-repl-image}/ciel' \
--eval '(ciel::main)' \
"$@"
'';
in {
overlayAttrs = {
sbcl = pkgs.sbcl.withOverrides (self: super: { inherit ciel; });
ciel = ciel-repl;
};
apps.default = {
type = "app";
program = ciel-repl;
};
devShells.default = pkgs.mkShell { packages = [ ciel-repl lisp' ]; };
};
};
}
4 changes: 2 additions & 2 deletions repl.lisp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;; #!/usr/bin/sbcl --script
(load "~/quicklisp/setup")

(ignore-errors (load "~/quicklisp/setup"))
#+quicklisp
(let ((*standard-output* (make-broadcast-stream)))
(ql:quickload "cl-readline"))
(uiop:define-package :sbcli
Expand Down