commit 300b165da924d243906ddc22d372b4e8f8980ebf Author: Florian Schroedl Date: Thu Jan 20 17:00:00 2022 +0100 Init diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..24f9236 --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,4 @@ +((nil . ((projectile-project-project-file . "nim_org_parse.nimble") + (projectile-project-name . "Nim Org Parser") + (projectile-project-type . nim) + (projectile-test-prefix . "test_")))) diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d3e739 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +result +.nimble/ +.direnv/ +/dst/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3321f67 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Florian Schrödl + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.org b/README.org new file mode 100644 index 0000000..8b992d5 --- /dev/null +++ b/README.org @@ -0,0 +1,5 @@ +#+TITLE: Readme + +A simple [[https://orgmode.org/][org]] document parser. + +This is not a full-fledged parser and only updated/fitted to my personal needs. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..aa4e912 --- /dev/null +++ b/flake.lock @@ -0,0 +1,90 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1642700792, + "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nimble": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1622481822, + "narHash": "sha256-Cc7WmnQ1GQSdhlRunmxlGBSNikgiNpxWjs60Mvgg2Ps=", + "owner": "floscr", + "repo": "flake-nimble", + "rev": "7892251d6d0e5c6380e5fb04d8d79249b9e340c9", + "type": "github" + }, + "original": { + "owner": "floscr", + "repo": "flake-nimble", + "type": "github" + } + }, + "nixos": { + "locked": { + "lastModified": 1641528457, + "narHash": "sha256-FyU9E63n1W7Ql4pMnhW2/rO9OftWZ37pLppn/c1aisY=", + "path": "/nix/store/pwz0d92vl5hjrvhiri3qzazxjnf1r8wy-source", + "rev": "ff377a78794d412a35245e05428c8f95fef3951f", + "type": "path" + }, + "original": { + "id": "nixos", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1619945546, + "narHash": "sha256-jDQB+5iGBS0AqtT060yzQLixwNBcxNn4EOuu1bK6Pcw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c576998594b4b8790f291d17fa92d499d1dc5d42", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1642970779, + "narHash": "sha256-wccCiIecPkPE6wpidSRe9XEdJ6uCrNLmRtuhNwt1Kuk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a3d847c3bd3a3b75b3057d7b3730d3308dd8fd59", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nimble": "nimble", + "nixos": "nixos", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..99f39c3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,69 @@ +{ + description = "A simple [[https://orgmode.org/][org]] document parser"; + + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + inputs.nimble.url = "github:floscr/flake-nimble"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = + { self + , nixpkgs + , nimble + , nixos + , flake-utils + }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + nimpkgs = nimble.packages.${system}; + customNimPkgs = import ./nix/packages/nimExtraPackages.nix { inherit pkgs; inherit nimpkgs; }; + + buildInputs = with pkgs; [ ]; + utils = import ./nix/lib/nimBuildGenerator.nix; + inherit (nixos.lib) flatten; + in + rec { + packages.nim_org_parse = + let + pkgName = "nim_org_parse"; + in + pkgs.stdenv.mkDerivation { + name = pkgName; + src = ./.; + + nativeBuildInputs = with pkgs; [ + nim + ]; + + buildInputs = buildInputs; + + buildPhase = utils.makeNimBuildScript { + srcFile = "./src/${pkgName}.nim"; + dstName = pkgName; + packages = flatten [ + (with nimpkgs; [ + ]) + customNimPkgs.fusion + customNimPkgs.nimfp + ]; + extraLines = [ ]; + }; + + installPhase = '' + mkdir -p $out/lib + install -Dt \ + $out/bin \ + $TMPDIR/${pkgName} + ''; + }; + + devShell = import ./shell.nix { + inherit pkgs; + inherit nimpkgs; + inherit buildInputs; + }; + + defaultPackage = packages.nim_org_parse; + + }); +} diff --git a/nim_org_parse.nimble b/nim_org_parse.nimble new file mode 100644 index 0000000..5f2aed5 --- /dev/null +++ b/nim_org_parse.nimble @@ -0,0 +1,22 @@ +# Package + +version = "0.1.0" +author = "Florian Schroedl" +description = "A simple [[https://orgmode.org/][org]] document parser" +license = "MIT" +srcDir = "src" +bin = @["nim_org_parse"] +binDir = "./dst" + +# Dependencies + +requires "nim >= 1.4.4" +requires "https://github.com/floscr/nimfp#master" +requires "fusion" +# requires "print" +# requires "zero_functional" +# requires "cascade" + +import distros +if detectOs(NixOS): + foreignDep "pkgconfig" diff --git a/nix/lib/nimBuildGenerator.nix b/nix/lib/nimBuildGenerator.nix new file mode 100644 index 0000000..0057a1f --- /dev/null +++ b/nix/lib/nimBuildGenerator.nix @@ -0,0 +1,30 @@ +let + inherit (builtins) foldl'; +in +rec { + makeNimBuildScript = + { srcFile + , dstName + , packages ? [ ] + , extraLines ? [ ] + }: + let + packageLines = map (a: "-p:${a}/src") packages; + lines = [ + "nim compile" + "-d:release" + "--hint[Processing]:off" + "--excessiveStackTrace:on" + ] ++ packageLines + ++ extraLines + ++ [ + "--out:$TMPDIR/${dstName}" + srcFile + ]; + buildCommand = foldl' (a: b: a + " " + b) "" lines; + in + '' + HOME=$TMPDIR + ${buildCommand} + ''; +} diff --git a/nix/packages/nimExtraPackages.nix b/nix/packages/nimExtraPackages.nix new file mode 100644 index 0000000..1ed9ee9 --- /dev/null +++ b/nix/packages/nimExtraPackages.nix @@ -0,0 +1,24 @@ +{ pkgs, nimpkgs, ... }: + +with pkgs; +{ + fusion = + (fetchFromGitHub + ({ + owner = "nim-lang"; + repo = "fusion"; + rev = "v1.1"; + sha256 = "9tn0NTXHhlpoefmlsSkoNZlCjGE8JB3eXtYcm/9Mr0I="; + })); + nimfp = with nimpkgs; [ + (pkgs.fetchFromGitHub + ({ + owner = "floscr"; + repo = "nimfp"; + rev = "master"; + sha256 = "sha256-gEs4qovho5qTXCquEG+fZOsL3rGB+Ql/r0IeLhnHjFk="; + })) + classy + nimboost + ]; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..b3657c8 --- /dev/null +++ b/shell.nix @@ -0,0 +1,16 @@ +{ pkgs, nimpkgs, buildInputs }: + +pkgs.mkShell { + shellHook = '' + export NIMBLE_DIR="$PWD/.nimble" + export NIMBLE_BIN_DIR="$NIMBLE_DIR/bin" + export PATH="$NIMBLE_BIN_DIR:$PATH" + # Mutable nimble install + [[ ! -f "$NIMBLE_BIN_DIR" ]] && nimble install + [[ ! -f "$NIMBLE_BIN_DIR/inim" ]] && nimble --accept install inim + ''; + buildInputs = with pkgs; buildInputs ++ [ + nim + nimlsp + ]; +} diff --git a/src/nim_org_parse.nim b/src/nim_org_parse.nim new file mode 100644 index 0000000..b5b6a5a --- /dev/null +++ b/src/nim_org_parse.nim @@ -0,0 +1 @@ +echo "Hello World"