Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches:
- master
workflow_dispatch:

env:
NIXPKGS_ALLOW_BROKEN: 0

jobs:
build:
runs-on: ubuntu-latest
name: ${{ matrix.channel-branch }}
strategy:
matrix:
channel-branch:
- nixpkgs-unstable

steps:
- uses: actions/checkout@v2
with:
ref: master
- uses: cachix/install-nix-action@v15
- name: Nix Version
run: nix --version
- name: Update lbstanza-bin
run: |
export NIX_PATH=nixpkgs=channel:${{ matrix.channel-branch }}
nix-shell nix/update-lbstanza-bin/shell.nix --command run_and_commit
- name: Build
run: |
export NIX_PATH=nixpkgs=channel:${{ matrix.channel-branch }}
nix-build --show-trace
- name: Run Version
run: ./result/bin/stanza version
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
result
.DS_Store
logs
build
Expand Down
5 changes: 5 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ pkgs ? import <nixpkgs> { } }:
let
myNix = import ./nix { inherit pkgs; };
in
myNix.lbstanza
5 changes: 5 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ pkgs ? import <nixpkgs> { } }:
rec {
lbstanza-bin = with pkgs; callPackage ./lbstanza-bin { };
lbstanza = with pkgs; callPackage ./lbstanza { inherit lbstanza-bin; };
}
35 changes: 35 additions & 0 deletions nix/lbstanza-bin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{ lib
, stdenv
, fetchzip
, autoPatchelfHook
}:

stdenv.mkDerivation rec {
pname = "lbstanza-bin";
version = "0.15.1";

src = fetchzip {
url = "http://lbstanza.org/resources/stanza/lstanza_${lib.replaceStrings ["."] ["_"] version}.zip";
sha256 = "sha256-Ogfe5HX+fk3Tth5J07fWngyHnQjbkYBxKObqsNY8spc=";
stripRoot=false;
};

nativeBuildInputs = [ autoPatchelfHook ];

installPhase = ''
runHook preInstall

mkdir -p "$out/bin"
cp -r * "$out"
cp "$out/stanza" "$out/bin/stanza"

runHook postInstall
'';

meta = with lib; {
description = "L.B. Stanza Programming Language - stage 1";
homepage = "http://lbstanza.org/";
maintainers = [ "Scott Hamilton <sgn.hamilton+nixpkgs@protonmail.com>" ];
platforms = platforms.linux;
};
}
51 changes: 51 additions & 0 deletions nix/lbstanza/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{ lib
, stdenv
, fetchFromGitHub
, lbstanza-bin
, nix-gitignore
}:

stdenv.mkDerivation rec {
pname = "lbstanza";
version = "master";

src = nix-gitignore.gitignoreSource [] ../..;

postPatch = ''
patchShebangs scripts/*.sh
'';

preBuild = ''
mkdir build
export HOME=$(pwd)
cat << EOF > .stanza
install-dir = "${lbstanza-bin}"
platform = linux
aux-file = "mystanza.aux"
EOF
'';

buildPhase = ''
runHook preBuild
./scripts/make.sh stanza linux compile-clean
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p "$out/bin"
cp -r * "$out"
mv "$out/lpkgs" "$out/pkgs"
mv "$out/lstanza" "$out/bin/stanza"
runHook postInstall
'';

nativeBuildInputs = [ lbstanza-bin ];

meta = with lib; {
description = "L.B. Stanza Programming Language";
homepage = "http://lbstanza.org/";
maintainers = [ "Scott Hamilton <sgn.hamilton+nixpkgs@protonmail.com>" ];
platforms = platforms.linux;
};
}
32 changes: 32 additions & 0 deletions nix/update-lbstanza-bin/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{ pkgs ? import <nixpkgs> {} }:
let
customPython = pkgs.python38.buildEnv.override {
extraLibs = with pkgs.python38Packages; [
# dateutil
packaging
# requests
];
};
in
with pkgs; mkShell {
buildInputs = [
customPython
];
shellHook = ''
run(){
python nix/update-lbstanza-bin/update-lbstanza-bin.py
}
# For the CI
commit(){
git config --global user.name 'SCOTT-HAMILTON'
git config --global user.email 'sgn.hamilton+github@protonmail.com'
git add nix/lbstanza-bin/default.nix
git commit -m "Automated nix/lbstanza-bin CI update"
git push
}
run_and_commit(){
run || commit
}
'';
}

70 changes: 70 additions & 0 deletions nix/update-lbstanza-bin/update-lbstanza-bin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import re
import subprocess
from packaging import version

# returns 1 if we updated a file, 0 otherwise

lbstanza_bin_nix_file = 'nix/lbstanza-bin/default.nix'

notNone = lambda r: r != None
current_version = next(filter(notNone, \
[re.search(r'.*STANZA-VERSION = (.*)',line) \
for line in open('compiler/stz-params.stanza')])).group(1) \
[1:][::-1][1:][::-1].replace(' ', '.')
print(f"current version={current_version}")
ci_version = next(filter(notNone, \
[re.search(r'^ version = "(.*)"',line) \
for line in open(lbstanza_bin_nix_file)])).group(1)
print(f"ci version used={ci_version}")
ci_sha256 = next(filter(notNone, \
[re.search(r'^ sha256 = "(.*)"',line) \
for line in open(lbstanza_bin_nix_file)])).group(1)
print(f"ci sha256 used={ci_sha256}")
vci_versio = version.parse(ci_version)
v_curversion = version.parse(current_version)

def search_n_replace(s, r, file, f):
def read_replace(file):
with open(file, 'r') as file:
return f(file.read())
data = read_replace(file)
with open(file, 'w') as file:
file.write(data)
def str_search_n_replace(s, r, file):
return search_n_replace(s, r, file,
lambda d: d.replace(s, r))

def is_sri(h):
return h[:7] == 'sha256-'
def to_empty_hash(h):
if is_sri(h):
return 'sha256-'+len(h[7:][::-1][1:][::-1])*'A'+'='
else:
return len(h)*'0'

def update_ci_sha256():
stderr_out = subprocess.run(["nix-build", "nix", "-A", "lbstanza-bin"],
capture_output=True).stderr.decode('utf-8')
new_sha256 = re.search(r'got: *(.*)', stderr_out).group(1)
if not is_sri(new_sha256):
new_sha256 = new_sha256[7:]
str_search_n_replace(
to_empty_hash(ci_sha256),
new_sha256,
lbstanza_bin_nix_file)

if vci_versio != v_curversion:
print("Needs Update")
str_search_n_replace(
ci_version,
current_version,
lbstanza_bin_nix_file)
str_search_n_replace(
ci_sha256,
to_empty_hash(ci_sha256),
lbstanza_bin_nix_file)
update_ci_sha256()
exit(1)
else:
print("Doesn't need Update")
exit(0)