Skip to content

Commit

Permalink
nix derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoog committed Aug 1, 2023
1 parent 6457095 commit 39701d4
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 76 deletions.
31 changes: 6 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
name: build
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
package:
runs-on: ubuntu-20.04
defaults:
run:
shell: nix develop -c bash {0}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: cachix/install-nix-action@v16
# TODO: implement build cache
- run: npm ci
- run: ./compile_sqls.fish
- run: npx vsce package --out sqlnotebook-${{ github.sha }}.vsix
- uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v2
- run: nix build
- name: Prepare to upload
run: cp ./result/* sqlnotebook-${{ github.sha }}.vsix
- name: Upload vsix as artifact
uses: actions/upload-artifact@v1
with:
name: sqlnotebook-${{ github.sha }}.vsix
path: sqlnotebook-${{ github.sha }}.vsix
test:
runs-on: ubuntu-20.04
defaults:
run:
shell: nix develop -c bash {0}
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: cachix/install-nix-action@v16
- run: npm ci
- run: npm run lint
16 changes: 6 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ on:

jobs:
publish:
runs-on: ubuntu-latest
defaults:
run:
shell: nix develop -c bash {0}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: cachix/install-nix-action@v16
- uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Parse version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- run: npm ci
- run: ./compile_sqls.fish
- run: npx vsce package --out sqlnotebook-${{ env.RELEASE_VERSION }}.vsix
- run: nix build
- name: Prepare to upload
run: cp ./result/* sqlnotebook-${{ env.RELEASE_VERSION }}.vsix
- name: Upload vsix as artifact
uses: actions/upload-artifact@v1
with:
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ Open any `.sql` file with the `Open With` menu option. Then, select the `SQL Not
![Screen Shot 2021-12-30 at 1 30 39 PM](https://user-images.githubusercontent.com/7585078/147782929-f9b7846b-6911-45ed-8354-ff0130a912b1.png)

![Screen Shot 2021-12-30 at 1 34 32 PM](https://user-images.githubusercontent.com/7585078/147782853-c0ea8ecb-e5f7-410f-83c2-af3d0562302e.png)

## FAQ

**If the file is stored as a regular `.sql` file, how are cell boundaries detected?**

Cell boundaries are inferred from the presence of two consecutive empty lines.

Note: this can pose issues with certain code formatters. You will need to
configure them to respect consecutive newlines.
32 changes: 0 additions & 32 deletions compile_sqls.fish

This file was deleted.

25 changes: 21 additions & 4 deletions flake.lock

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

51 changes: 48 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,65 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
npmlock2nix = {
url = "github:nix-community/npmlock2nix";
flake = false;
};
};

outputs = { self, nixpkgs, flake-utils }:
outputs = { self, nixpkgs, npmlock2nix, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
npm2nix = import npmlock2nix { inherit pkgs; };
sqls = { arch, os }: with pkgs; (buildGoModule {
name = "sqls_${arch}_${os}";
src = fetchFromGitHub {
owner = "cmoog";
repo = "sqls";
rev = "8f600074d1b0778c7a0b6b9b820dd4d2d05fbdee";
sha256 = "sha256-3nYWMDKqmQ0NnflX/4vx1BA+rubWV7pRdZcDaKUatO0=";
};
doCheck = false;
vendorHash = "sha256-Xv/LtjwgxydMwychQtW1+quqUbkC5PVzhga5qT5lI3s=";
CGO_ENABLED = 0;
}).overrideAttrs (old: old // { GOOS = os; GOARCH = arch; });
# build each os/arch combination
sqlsInstallCommands = builtins.concatStringsSep "\n" (pkgs.lib.flatten (map
(os: (map
(arch:
# skip this invalid os/arch combination
if arch == "386" && os == "darwin" then "" else
"cp $(find ${sqls { inherit os arch; }} -type f) $out/bin/sqls_${arch}_${os}"
) [ "amd64" "arm64" "386" ])) [ "linux" "darwin" "windows" ]));
sqlsBins = pkgs.runCommand "multiarch-sqls" { } ''
mkdir -p $out/bin
${sqlsInstallCommands}
'';
in
{
formatter = pkgs.nixpkgs-fmt;
packages = {
inherit sqlsBins;
default = npm2nix.v2.build {
src = pkgs.runCommand "src-with-sqls" { } ''
mkdir $out
cp -r ${./.}/* $out
cp -r ${sqlsBins}/bin $out/sqls_bin
'';
nodejs = pkgs.nodejs;
buildCommands = [ "npm run build" ];
installPhase = ''
mkdir -p $out
cp *.vsix $out/
'';
};
};
devShells.default = pkgs.mkShell {
packages = with pkgs; [
fish
go_1_17
nodejs-16_x
go
nodejs
typos
upx
];
Expand Down
7 changes: 5 additions & 2 deletions src/serializer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { TextDecoder, TextEncoder } from 'util';
import * as vscode from 'vscode';

// Cell block delimiter
const DELIMITER = '\n\n';

export class SQLSerializer implements vscode.NotebookSerializer {
async deserializeNotebook(
context: Uint8Array,
Expand Down Expand Up @@ -42,14 +45,14 @@ export class SQLSerializer implements vscode.NotebookSerializer {
? value
: `/*markdown\n${value}\n*/`
)
.join('\n\n')
.join(DELIMITER)
);
}
}

function splitSqlBlocks(raw: string): string[] {
const blocks = [];
for (const block of raw.split('\n\n')) {
for (const block of raw.split(DELIMITER)) {
if (block.trim().length > 0) {
blocks.push(block);
continue;
Expand Down

0 comments on commit 39701d4

Please sign in to comment.