Skip to content

Commit

Permalink
Add nix flake (#104)
Browse files Browse the repository at this point in the history
Added nix flake 

Signed-off-by: emilpriver <[email protected]>
  • Loading branch information
emilpriver authored May 6, 2024
1 parent 688bb3c commit 8552462
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 6 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Nix

on:
pull_request:
push:

env:
CARGO_TERM_COLOR: always

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup
run: |
sudo apt-get install -y mariadb-client postgresql-client
- name: Databases
run: docker compose up -d
- name: Run tests
run: cargo test --verbose
nix:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Databases
run: docker compose up -d
- name: Nix flake check
run: nix flake check
- name: Test nix build
run: |
nix run . -- --help | grep -q "Usage: geni <COMMAND>" || exit 2
1 change: 0 additions & 1 deletion .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,3 @@ jobs:
env:
GITHUN_REF_NAME: ${{github.ref_name}}
run: bash scripts/update-homebrew-geni-formula.sh

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ example.db
*.sqlite3
/tmp/
scripts/migrations
result
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "geni"
version = "1.0.5"
version = "1.0.6"
edition = "2021"
resolver = "2"
description = "A standalone database CLI migration tool"
Expand Down Expand Up @@ -30,7 +30,6 @@ async-trait = "0.1.80"
chrono = { version = "0.4.31", features = ["serde"] }
clap = { version = "4.5.2", features = ["env", "string", "derive", "cargo"] }
futures = "0.3.30"
libsql-client = { git = "https://github.com/libsql/libsql-client-rs.git", version = "0.33.2", rev = "a432666", features = ["futures-util", "http"] }
serde = { version = "1.0.200", features = ["derive"] }
log = { version = "0.4.21", features = ["max_level_debug", "serde"] }
serde_json = "1.0.108"
Expand All @@ -41,6 +40,7 @@ sqlx = { version = "0.7.3", features = ["runtime-tokio", "chrono", "postgres",
url = { version = "2.5.0", features = ["serde"] }
which = "6.0.1"
regex = "1.10.4"
libsql-client = { version = "0.33.4", features = ["futures-util", "http"] }

[dev-dependencies]
mockall = "0.12.0"
Expand Down
31 changes: 31 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ pkgs ? import <nixpkgs> {} }:
let manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
in pkgs.rustPlatform.buildRustPackage rec {
pname = "geni";
version = manifest.version;
cargoLock.lockFile = ./Cargo.lock;
src = pkgs.lib.sources.cleanSource ./.;
# The test is running before we build nix
doCheck = false;

buildPhase = ''
cargo build --release --locked
'';

installPhase = ''
mkdir -p $out/bin
cp target/release/geni $out/bin/
'';

meta = with pkgs.lib; {
description = manifest.description;
longDescription = ''
Standalone database migration tool which works for Postgres, MariaDB, MySQL, Sqlite and LibSQL(Turso).
'';
homepage = manifest.repository;
changelog = "${manifest.repository}/releases/tag/v${version}";
license = licenses.mit;
maintainers = [ maintainers.emilpriver ];
platforms = platforms.all;
};
}
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
description = "A very basic flake";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # We want to use packages from the binary cache
flake-utils.url = "github:numtide/flake-utils";
};

outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: let
pkgs = nixpkgs.legacyPackages.${system};
in rec {
packages.geni = pkgs.callPackage ./default.nix { };

legacyPackages = packages;

defaultPackage = packages.geni;

devShell = pkgs.mkShell {
CARGO_INSTALL_ROOT = "${toString ./.}/.cargo";

buildInputs = with pkgs; [ cargo rustc git ];
};
});
}

0 comments on commit 8552462

Please sign in to comment.