From c171c51dc57826cea3eff5b02d64391fe4dfbe22 Mon Sep 17 00:00:00 2001 From: Julien Moutinho Date: Wed, 23 Apr 2025 12:33:43 +0200 Subject: [PATCH 1/1] init --- .envrc | 1 + flake.lock | 85 ++++++++++++++++++++++++++++++++++++ flake.nix | 108 ++++++++++++++++++++++++++++++++++++++++++++++ server.properties | 2 + 4 files changed, 196 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 server.properties 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/flake.lock b/flake.lock new file mode 100644 index 0000000..cdd2a95 --- /dev/null +++ b/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1742649964, + "narHash": "sha256-DwOTp7nvfi8mRfuL1escHDXabVXFGT1VlPD1JHrtrco=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1738843498, + "narHash": "sha256-7x+Q4xgFj9UxZZO9aUDCR8h4vyYut4zPUvfj3i+jBHE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f5a32fa27df91dfc4b762671a0e0a859a8a0058f", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ba47fe2 --- /dev/null +++ b/flake.nix @@ -0,0 +1,108 @@ +{ + description = "Nix Flake to use LibreOffice Base with an SQLite database"; + inputs = { + nixpkgs.url = "flake:nixpkgs"; + git-hooks.url = "github:cachix/git-hooks.nix"; + git-hooks.inputs.nixpkgs.follows = "nixpkgs"; + }; + outputs = inputs: + let + lib = inputs.nixpkgs.lib; + forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec { + inherit system; + pkgs = inputs.nixpkgs.legacyPackages.${system}; + }); + in + { + devShells = forAllSystems ({ pkgs, system, ... }: { + default = + let database = "LesQuatreRoux"; in + pkgs.mkShell { + JAVA_HOME = pkgs.libreoffice.unwrapped.jdk; + ODBCSYSINI = + let + odbcsysini = pkgs.writeTextDir "odbcinst.ini" '' + [ODBC Drivers] + SQLite3=Installed + + [SQLite3] + Description = SQLite ODBC Driver + Driver = ${pkgs.lib.getLib pkgs.unixODBCDrivers.sqlite}/lib/libsqlite3odbc.so + Setup = ${pkgs.lib.getLib pkgs.unixODBCDrivers.sqlite}/lib/libsqlite3odbc.so + Threading = 2 + UsageCount=1 + FileUsage= 1 + CPTimeout= + CPReuse= + FKSupport=Yes + SyncPragma= + + # Sadly does not work: https://github.com/sqitchers/docker-sqitch/pull/16/. + [Default] + Driver=SQLite3 + ''; + odbcini = pkgs.writeTextDir "odbc.ini" '' + [${database}] + Description=${database} database + Driver=SQLite + NoCreat=No + LongNames=Yes + Database=${database} + TraceFile=/tmp/${database}.log + # DescriptionNote: optional lock timeout in milliseconds; default 100000 + #Timeout=2000 + ''; + in + # ExplanationNote: somehow using ODBCINI= does not work, so keep everything in ODBCSYSINI= + pkgs.symlinkJoin { + name = "ODBCSYSINI"; + paths = [ + odbcsysini + odbcini + ]; + }; + buildInputs = [ + #pkgs.bat + pkgs.dbeaver-bin + pkgs.hsqldb + pkgs.libreoffice + pkgs.sqlfluff + #pkgs.sqlite + #pkgs.sqlitebrowser + #pkgs.unixODBC + (pkgs.writeShellScriptBin "sql" '' + exec ${pkgs.hsqldb}/bin/sqltool --inlineRc='url=jdbc:hsqldb:hsql://localhost:9001/LesQuatreRoux' --autoCommit "$@" + '') + ]; + shellHook = '' + #bat $ODBCSYSINI/odbcinst.ini + #bat $ODBCSYSINI/odbc.ini + export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [pkgs.unixODBC]}:$LD_LIBRARY_PATH + set -x + #odbcinst -j + #odbcinst -q -d -n SQLite3 + #odbcinst -q -s -h + #odbcinst -q -s -n ${database} + set +x + echo "You may now launch runServer" + '' # + checks.${system}.git-hooks-check.shellHook + ; + }; + }); + # nix flake check + checks = forAllSystems (args: with args; { + git-hooks-check = inputs.git-hooks.lib.${system}.run { + src = ./.; + hooks = { + nixpkgs-fmt.enable = true; + sqlfluff.enable = true; + reuse = { + enable = true; + entry = "${pkgs.reuse}/bin/reuse lint"; + pass_filenames = false; + }; + }; + }; + }); + }; +} diff --git a/server.properties b/server.properties new file mode 100644 index 0000000..f2c1475 --- /dev/null +++ b/server.properties @@ -0,0 +1,2 @@ +server.database.0=file:LesQuatreRoux;hsqldb.default_schema=true,hsqldb.default_table_type=cached,hsqldb.shutdown=true,sql.lowercase_ident=true +server.dbname.0=LesQuatreRoux -- 2.47.2