thesis/flake.nix

150 lines
5.3 KiB
Nix
Raw Permalink Normal View History

2023-08-20 20:50:20 +02:00
{
description = "Put a short description here";
inputs = {
nixpkgs = {
type = "indirect";
id = "nixpkgs";
};
};
outputs = {self, nixpkgs} :
let
# name to be used as identifier for editor environments and such
name = "Name";
#Generate a user-friendly version number.
version = builtins.substring 0 8 self.lastModifiedDate;
# System types to support.
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in {
packages = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
# LaTex package dependencies
2024-07-28 23:34:21 +02:00
latexdeps = {inherit (pkgs.texlive) scheme-full;};
2023-08-20 20:50:20 +02:00
latex = pkgs.texlive.combine latexdeps;
latexrun = pkgs.latexrun;
in {
default = pkgs.stdenvNoCC.mkDerivation {
name = "output.pdf";
2024-08-07 04:26:06 +02:00
buildInputs = [latex latexrun pkgs.biber pkgs.inkscape pkgs.stix-two];
2023-08-20 20:50:20 +02:00
src = self;
buildPhase = ''
2024-07-28 23:34:21 +02:00
HOME=.
cd src
latexrun --latex-cmd lualatex --bibtex-cmd biber --latex-args '\-shell-escape' -o output.pdf Main.tex
2023-08-20 20:50:20 +02:00
'';
installPhase = ''
mkdir -p $out
2024-07-28 23:34:21 +02:00
env > $out/env
2023-08-20 20:50:20 +02:00
cp output.pdf $out/output.pdf
'';
};
}
);
devShells = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
in ( rec {
# This sets the default devShell
default = kakoune;
kakoune =
let
texlab = pkgs.texlab;
2024-07-28 23:34:21 +02:00
latexTmpDir = "latex.out/";
2023-08-20 20:50:20 +02:00
myKakoune =
let
# this could also be done by generating toml with the
# nixpkgs lib, but I'm lazy
kak-lsp-config = pkgs.writeTextFile {
name = "kak-lsp-config.toml";
text = ''
[language.latex]
filetypes = ["latex"]
2024-07-28 23:34:21 +02:00
roots = [".git", "Main.tex"]
2023-08-20 20:50:20 +02:00
command = "texlab"
2024-08-07 04:26:06 +02:00
# args = ["-vvvv", "--log-file", "/tmp/texlabLog"]
2023-08-20 20:50:20 +02:00
settings_section = "texlab"
[language.latex.settings.texlab.build]
onSave = true
2024-07-28 23:34:21 +02:00
auxDirectory = "${latexTmpDir}"
2023-08-20 20:50:20 +02:00
executable = "latexrun"
2024-07-28 23:34:21 +02:00
args = ["--latex-cmd", "lualatex", "--bibtex-cmd", "biber", "--latex-args", "'-shell-escape -synctex=1'","%f"]
# args = ["--latex-cmd", "lualatex", "--bibtex-cmd", "biber", "%f"]
2023-08-20 20:50:20 +02:00
forwardSearchAfter = true
[language.latex.settings.texlab.forwardSearch]
executable = "zathura"
args = ["--synctex-forward", "%l:1:%f", "%p"]
'';
};
config = pkgs.writeTextFile (rec {
name = "kakrc.kak";
destination = "/share/kak/autoload/${name}";
text = ''
colorscheme solarized-dark
set global tabstop 2
2024-07-28 23:34:21 +02:00
set global indentwidth 0
2024-08-07 04:26:06 +02:00
# eval %sh{kak-lsp --kakoune --session $kak_session -c ${kak-lsp-config} --log /tmp/kak-lspLog -vvvv}
eval %sh{kak-lsp --kakoune --session $kak_session -c ${kak-lsp-config}}
2023-08-20 20:50:20 +02:00
hook global WinSetOption filetype=(latex) %{
lsp-auto-hover-enable
lsp-enable-window
}
add-highlighter global/ number-lines
map global normal <c-p> ': fzf-mode<ret>'
'';
});
in
pkgs.kakoune.override {
plugins = with pkgs.kakounePlugins; [fzf-kak kak-lsp config];
};
in
pkgs.mkShellNoCC {
inputsFrom = [self.outputs.packages.${system}.default];
packages = [myKakoune texlab pkgs.git pkgs.zathura pkgs.fzf];
# TODO only try to start the kakoune session if no session with that
# name exists
shellHook = ''
2024-07-28 23:34:21 +02:00
HOME=.
# unset LANG # This is a very stupid idea but lualatex GRMBLFX!!! # argh this brakes kakoune unicode!!!
2023-08-20 20:50:20 +02:00
alias ..="cd .."
2024-07-28 23:34:21 +02:00
cd src
2023-08-20 20:50:20 +02:00
mkdir -p ${latexTmpDir}
export KAKOUNE_CONFIG_DIR="/dev/null/"
kak -d -s ${name} &
alias vim="kak -c ${name}"
'';
};
texstudio =
pkgs.mkShellNoCC {
inputsFrom = [self.outputs.packages.${system}.default];
packages = [pkgs.texstudio pkgs.git];
shellHook = ''
texstudio
'';
};
texmaker =
pkgs.mkShellNoCC {
inputsFrom = [self.outputs.packages.${system}.default];
packages = [pkgs.texmaker pkgs.git];
shellHook = ''
texmaker
'';
};
})
);
};
}