add Nix flake, shell

This commit is contained in:
Gregory Burd 2023-10-19 14:45:46 -04:00
parent 5dc705134e
commit 1f471e54a2
2 changed files with 124 additions and 0 deletions

98
flake.nix Normal file
View file

@ -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 <greg@burd.me>" ];
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; };
}
);
}

26
shell.nix Normal file
View file

@ -0,0 +1,26 @@
{ pkgs ? import <nixpkgs> {} }:
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;
}