Minor changes

- Redid the flake module to be based on extendModules instead
- Added wrappers
- Refactored code
- Updated dependencies
This commit is contained in:
Nikodem Rabuliński 2023-08-31 22:27:07 +02:00
parent 9661927410
commit ee7223ca36
No known key found for this signature in database
GPG key ID: FF629AA9E08138DB
19 changed files with 468 additions and 97 deletions

26
wrappers/default.nix Normal file
View file

@ -0,0 +1,26 @@
{inputs, ...}: {
perSystem = {
pkgs,
inputs',
...
}: let
argsModule = {
_module.args = {
inherit inputs';
inherit inputs;
};
};
wrapped = inputs.wrapper-manager.lib {
inherit pkgs;
modules = [
inputs.wrapper-manager-hm-compat.wrapperManagerModules.homeManagerCompat
argsModule
./starship
./helix
./rash
];
};
in {
inherit (wrapped.config.build) packages;
};
}

View file

@ -0,0 +1,44 @@
{
pkgs,
lib,
...
}: {
programs.helix = {
enable = true;
settings = {
editor = {
true-color = true;
line-number = "relative";
mouse = false;
cursor-shape.insert = "bar";
color-modes = true;
cursorline = true;
auto-save = true;
indent-guides.render = true;
};
};
languages = {
language = [
{
name = "koka";
scope = "scope.koka";
file-types = ["kk"];
roots = [];
indent = {
tab-width = 4;
unit = " ";
};
}
{
name = "racket";
indent = {
tab-width = 2;
unit = " ";
};
}
];
};
};
wrappers.helix.pathAdd = [pkgs.nil];
}

56
wrappers/rash/default.nix Normal file
View file

@ -0,0 +1,56 @@
{
pkgs,
inputs',
config,
...
}: {
wrappers.rash = let
readlinePatched = pkgs.fetchFromGitHub {
owner = "nrabulinski";
repo = "readline";
rev = "8eb52c163d6ea7c3cec2cc6b1011ce00738942e1";
hash = "sha256-1yU0ZUBQqYEn85j4T2pLs02MTyJnO5BbYALIa88iomY=";
};
racket-with-libs = inputs'.racket.packages.racket.newLayer {
withRacketPackages = ps:
with ps; [
readline-gpl
(readline-lib.override {
src = "${readlinePatched}/readline-lib";
})
rash
threading
functional
racket-langserver
# TODO: Remove once dependency resolution is fixed
slideshow-lib
r5rs-lib
data-enumerate-lib
plot-lib
plot-gui-lib
plot-compat
srfi-lib
typed-racket-compatibility
future-visualizer-pict
macro-debugger-text-lib
profile-lib
images-gui-lib
];
buildInputs = with pkgs; [readline];
};
in {
basePackage = pkgs.writeShellScriptBin "rash" ''
exec "${racket-with-libs}/bin/rash-repl" "$@"
'';
env.
XDG_CONFIG_HOME = pkgs.linkFarm "rash-config" {
"rash/rashrc" = ./rashrc;
"rash/rashrc.rkt" = ./rashrc.rkt;
};
pathAdd = [
racket-with-libs
config.wrappers.starship.wrapped
];
};
}

17
wrappers/rash/rashrc Normal file
View file

@ -0,0 +1,17 @@
(require readline/pread
data/maybe
(prefix-in f: data/functor)
data/applicative
data/monad
threading
racket/string
racket/cmdline
racket/system
racket/pretty
racket/format
racket/list
racket/function
racket/port)
(current-prompt-function prompt-f)

48
wrappers/rash/rashrc.rkt Normal file
View file

@ -0,0 +1,48 @@
#lang racket
(require readline/pread
data/maybe
(prefix-in f: data/functor)
data/applicative
data/monad
threading
racket/function
racket/port)
(provide prompt-f)
(define (maybe-regexp-match* regexp str)
(define res (regexp-match* regexp str #:match-select cadr))
(if (empty? res) nothing (just (car res))))
(define (mfilter proc m)
(chain (lambda (x) (if (proc x) m nothing)) m))
(define (run-cmd cmd . args)
(define exe (find-executable-path cmd))
(define proc (apply process* exe args))
((fifth proc) 'wait)
(define output (port->string (first proc)))
(close-input-port (first proc))
(close-output-port (second proc))
(close-input-port (fourth proc))
output)
(define (prompt-f #:last-return-value [last-ret #f])
; TODO: Patch rash so that it throws an error without the need to parse the error message
(define last-code
(~>> (just last-ret)
(mfilter exn:fail?)
(f:map exn-message)
(chain (lambda~>> (maybe-regexp-match* #rx"terminated with code ([0-9]+)")))))
; TODO: Don't show last-ret if it's this error ^^^^^^^^^^^^^^^
(when (and last-ret (not (void? last-ret)))
(display last-ret))
(define prompt
(run-cmd "starship"
"prompt"
; TODO: Set status to 1 if last-ret was some other exn
(format "--status=~a" (from-just "0" last-code))))
(readline-prompt (string->bytes/utf-8 prompt)))

View file

@ -0,0 +1,5 @@
{
programs.starship = {
enable = true;
};
}