diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..96f9089 --- /dev/null +++ b/flake.nix @@ -0,0 +1,98 @@ +{ + description = "The DBSQL library, a mixup of SQLite and Berkeley DB"; + + nixConfig = { + bash-prompt = "\\[\\e[34;1m\\]nix ~ \\[\\e[0m\\]"; + }; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + inputs.nix-github-actions.url = "github:nix-community/nix-github-actions"; + inputs.nix-github-actions.inputs.nixpkgs.follows = "nixpkgs"; + + outputs = { self, nixpkgs, flake-utils, pre-commit-hooks, nix-github-actions }: + let + inherit (nixpkgs) lib; + officialRelease = false; + + #version = "DBSQL ${DBSQL_VERSION}: (${versionSuffix})"; + version = "DBSQL 0.3.1: (${versionSuffix})"; + versionSuffix = + if officialRelease + then "" + else "pre${builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}_${self.shortRev or "dirty"}"; + + supportedSystems = [ "x86_64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }); + + in + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + + overlays = [ + + (final: prev: { + dbsql = with final; stdenv.mkDerivation rec { + inherit version; + inherit system; + pname = "dbsql"; + src = self; + configureFlags = [ + "--host ${system}" + ]; + nativeBuildInputs = [ autoreconfHook ]; + meta = { + changelog = "https://git.burd.me/greg/dbsql/raw/branch/main/ChangeLog"; + downloadPage = "https://git.burd.me/greg/dbsql/releases"; + homepage = "https://github.com/gburd/dbsql"; + license = "https://github.com/gburd/dbsql/LICENSE"; + mainProgram = "dbsql"; + maintainers = [ "Greg Burd " ]; + platforms = supportedSystems; + }; + }; + }) + ]; + + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + nixpkgs-fmt.enable = true; + }; + }; + }; + + devShell = nixpkgs.legacyPackages.${system}.mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + }; + + }; + + in rec { + packages = { + inherit (pkgs) dbsql; + + githubActions = nix-github-actions.lib.mkGithubMatrix { + checks = nixpkgs.lib.getAttrs [ "x86_64-linux" "x86_64-darwin" ] self.packages; + }; + }; + packages.default = self.packages.${system}.dbsql; + packages.container = pkgs.callPackage ./container.nix { package = packages.default; }; + + apps.dbsql = flake-utils.lib.mkApp { drv = packages.default; }; + apps.${system}.default = apps.dbsql; + + devShells.default = import ./shell.nix { inherit pkgs; }; + } + ); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..edf2961 --- /dev/null +++ b/shell.nix @@ -0,0 +1,26 @@ +{ pkgs ? import {} }: + +pkgs.mkShell { + # nativeBuildInputs is usually what you want -- tools you need to run + nativeBuildInputs = with pkgs.buildPackages; [ + act + autoconf + db4 + ed + gcc + gdb + gettext + libtool + m4 + perl + ripgrep + tcl-8_5 + ]; + + buildInputs = with pkgs; [ + glibc.out + glibc.static + ]; + + DOCKER_BUILDKIT = 1; +}