From 36ad5c4a3962d54b00e9d6eddcfd7bdc59e8ed88 Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 12 Nov 2022 23:05:58 +0100 Subject: [PATCH] add nix flake and related files --- .envrc | 7 ++++ .gitignore | 1 + README.md | 4 ++ default.nix | 16 ++++++++ flake.lock | 26 +++++++++++++ flake.nix | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 16 ++++++++ 7 files changed, 175 insertions(+) create mode 100644 .envrc create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..6125787 --- /dev/null +++ b/.envrc @@ -0,0 +1,7 @@ +use flake + +# ref: https://github.com/direnv/direnv/wiki/Vim +# comment out if not planning to use this +#add_extra_vimrc + +# vim: ff=unix ft=sh diff --git a/.gitignore b/.gitignore index 6bca4ac..a7342e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.direnv # backup files *.tex\~ # vim swap files diff --git a/README.md b/README.md index 10efed0..1056abb 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ prerequisities: * `make` * [`distrobox`](https://github.com/89luca89/distrobox) +alternatively, when using [Nix](https://builtwithnix.org/), just run `direnv +allow`, `nix develop` (with [flakes](https://nixos.wiki/wiki/Flakes) enabled) +or `nix shell` (when using nix without flakes). + ### instructions: * clone this repo and cd into it ```sh diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..c580745 --- /dev/null +++ b/default.nix @@ -0,0 +1,16 @@ +( + import + ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { + src = ./.; + } +) +.defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b7db1d4 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1668288759, + "narHash": "sha256-olmFmG3er2sYTnwcZSjfxf/SiZo9mNgfGVA/O05DIIg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "eda76eb80e5a98f1cfdfe925032aae251f812eef", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..16a4bc0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,105 @@ +{ + # check out https://git.dotya.ml/mirre-mt/thesis-tmpl/ + description = "Thesis tmpl"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + }; + + outputs = { + self, + nixpkgs, + ... + }: let + # to work with older version of flakes + lastModifiedDate = + self.lastModifiedDate or self.lastModified or "19700101"; + supportedSystems = ["aarch64-linux" "x86_64-linux" "x86_64-darwin"]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + + thesisType = ""; # ms, bc + throw "Set thesis type!" + documentName = "thesis"; + pname = thesisType + "_" + documentName; + version = "0.0.1"; + + pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system}); + nixpkgsFor = forAllSystems ( + system: + import nixpkgs { + inherit system; + overlays = [self.overlay]; + } + ); + in rec { + formatter = forAllSystems ( + system: + nixpkgsFor.${system}.alejandra + ); + overlay = with pkgs; + final: prev: { + watcher = with final; + writeScriptBin "watch" '' + out=".latexmkout" + mkdir "$out" + latexmk \ + -pvc \ + -outdir="$out" \ + -pdf \ + -pdflatex="pdflatex -synctex=1 -file-line-error -interaction=nonstopmode" \ + -use-make ${documentName}.tex + rm -r "$out" + ''; + }; + + packages = with pkgs; + forAllSystems (system: { + inherit (nixpkgsFor.${system}) watcher; + }); + + defaultPackage = + forAllSystems (system: self.packages."${system}".watcher); + + apps = forAllSystems (system: rec { + watch = { + type = "app"; + program = "${self.packages."${system}".watcher}/bin/watch"; + }; + default = watch; + }); + devShells = with pkgs; + forAllSystems (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [self.overlay]; + }; + watcher = pkgs.writeShellScriptBin "watcher" '' + out=".latexmkout" + mkdir "$out" + latexmk \ + -pvc \ + -outdir="$out" \ + -pdf \ + -pdflatex="pdflatex -synctex=1 -file-line-error -interaction=nonstopmode" \ + -use-make ${documentName}.tex + rm -r "$out" + ''; + in { + default = nixpkgsFor.${system}.mkShell { + name = "${pname}-" + version; + shellHook = '' + echo " -- in ${pname} dev shell..." + ''; + + packages = with nixpkgsFor.${system}; [ + watcher + + gnumake + alejandra + distrobox + podman + ]; + }; + }); + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..017cf3f --- /dev/null +++ b/shell.nix @@ -0,0 +1,16 @@ +( + import + ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { + src = ./.; + } +) +.shellNix