From 93955a991a0352a56c9899e82a98c0c95d5e7ca4 Mon Sep 17 00:00:00 2001 From: SCOTT-HAMILTON Date: Fri, 19 Nov 2021 18:49:21 +0100 Subject: [PATCH 1/3] Init Github Nix Workflow --- .github/workflows/ci.yml | 33 ++++++++++++++++++++++++ .gitignore | 1 + default.nix | 6 +++++ nix/lbstanza-bin/default.nix | 35 +++++++++++++++++++++++++ nix/lbstanza/default.nix | 50 ++++++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 default.nix create mode 100644 nix/lbstanza-bin/default.nix create mode 100644 nix/lbstanza/default.nix diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..e0dbb0a7d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +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: Build + run: | + export NIX_PATH=nixpkgs=channel:${{ matrix.channel-branch }} + nix-build --show-trace + - name: Run Version + run: ./result/bin/stanza version diff --git a/.gitignore b/.gitignore index 8045a76a9..a2514b344 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ build *.o *.exe stanza.aux +shell.nix diff --git a/default.nix b/default.nix new file mode 100644 index 000000000..e0684670d --- /dev/null +++ b/default.nix @@ -0,0 +1,6 @@ +{ pkgs ? import { } }: +let + lbstanza-bin = with pkgs; callPackage ./nix/lbstanza-bin { }; + lbstanza = with pkgs; callPackage ./nix/lbstanza { inherit lbstanza-bin; }; +in + lbstanza diff --git a/nix/lbstanza-bin/default.nix b/nix/lbstanza-bin/default.nix new file mode 100644 index 000000000..6861b7e00 --- /dev/null +++ b/nix/lbstanza-bin/default.nix @@ -0,0 +1,35 @@ +{ lib +, stdenv +, fetchzip +, autoPatchelfHook +}: + +stdenv.mkDerivation rec { + pname = "lbstanza-bin"; + version = "0.14.33"; + + src = fetchzip { + url = "http://lbstanza.org/resources/stanza/lstanza_${lib.replaceStrings ["."] ["_"] version}.zip"; + sha256 = "1az9pddxh5kjqkkxsl3ffc23zjawilpisnvy9sy7ymnsp3b791lf"; + 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 " ]; + platforms = platforms.linux; + }; +} diff --git a/nix/lbstanza/default.nix b/nix/lbstanza/default.nix new file mode 100644 index 000000000..504838479 --- /dev/null +++ b/nix/lbstanza/default.nix @@ -0,0 +1,50 @@ +{ 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 "$out" + cp -r * "$out" + mv "$out/lpkgs" "$out/pkgs" + runHook postInstall + ''; + + nativeBuildInputs = [ lbstanza-bin ]; + + meta = with lib; { + description = "L.B. Stanza Programming Language"; + homepage = "http://lbstanza.org/"; + maintainers = [ "Scott Hamilton " ]; + platforms = platforms.linux; + }; +} From dbd8f4d1ee665378d0480bccdc337e677b5e8166 Mon Sep 17 00:00:00 2001 From: SCOTT-HAMILTON Date: Fri, 21 Jan 2022 14:36:23 +0100 Subject: [PATCH 2/3] CI Automation of nix/lbstanza-bin update --- .github/workflows/ci.yml | 8 ++- .gitignore | 2 +- default.nix | 5 +- nix/default.nix | 5 ++ nix/lbstanza/default.nix | 3 +- nix/update-lbstanza-bin/shell.nix | 32 +++++++++ .../update-lbstanza-bin.py | 70 +++++++++++++++++++ 7 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 nix/default.nix create mode 100644 nix/update-lbstanza-bin/shell.nix create mode 100755 nix/update-lbstanza-bin/update-lbstanza-bin.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0dbb0a7d..75745800f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,8 +12,8 @@ env: jobs: build: runs-on: ubuntu-latest - name: ${{ matrix.channel-branch }} - strategy: + name: ${{ matrix.channel-branch }} + strategy: matrix: channel-branch: - nixpkgs-unstable @@ -25,6 +25,10 @@ jobs: - 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 }} diff --git a/.gitignore b/.gitignore index a2514b344..1f1399bd0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +result .DS_Store logs build @@ -18,4 +19,3 @@ build *.o *.exe stanza.aux -shell.nix diff --git a/default.nix b/default.nix index e0684670d..eea22ccc6 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,5 @@ { pkgs ? import { } }: let - lbstanza-bin = with pkgs; callPackage ./nix/lbstanza-bin { }; - lbstanza = with pkgs; callPackage ./nix/lbstanza { inherit lbstanza-bin; }; + myNix = import ./nix { inherit pkgs; }; in - lbstanza +myNix.lbstanza diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 000000000..00b7dd810 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,5 @@ +{ pkgs ? import { } }: +rec { + lbstanza-bin = with pkgs; callPackage ./lbstanza-bin { }; + lbstanza = with pkgs; callPackage ./lbstanza { inherit lbstanza-bin; }; +} diff --git a/nix/lbstanza/default.nix b/nix/lbstanza/default.nix index 504838479..134b6062c 100644 --- a/nix/lbstanza/default.nix +++ b/nix/lbstanza/default.nix @@ -33,9 +33,10 @@ stdenv.mkDerivation rec { installPhase = '' runHook preInstall - mkdir "$out" + mkdir -p "$out/bin" cp -r * "$out" mv "$out/lpkgs" "$out/pkgs" + mv "$out/lstanza" "$out/bin/stanza" runHook postInstall ''; diff --git a/nix/update-lbstanza-bin/shell.nix b/nix/update-lbstanza-bin/shell.nix new file mode 100644 index 000000000..c4b185fdc --- /dev/null +++ b/nix/update-lbstanza-bin/shell.nix @@ -0,0 +1,32 @@ +{ pkgs ? import {} }: +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 + } + ''; +} + diff --git a/nix/update-lbstanza-bin/update-lbstanza-bin.py b/nix/update-lbstanza-bin/update-lbstanza-bin.py new file mode 100755 index 000000000..a25266e43 --- /dev/null +++ b/nix/update-lbstanza-bin/update-lbstanza-bin.py @@ -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) From c0282562798926daac4f9e45e8203a2015fa6bc2 Mon Sep 17 00:00:00 2001 From: SCOTT-HAMILTON Date: Fri, 21 Jan 2022 14:11:57 +0000 Subject: [PATCH 3/3] Automated nix/lbstanza-bin CI update --- nix/lbstanza-bin/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/lbstanza-bin/default.nix b/nix/lbstanza-bin/default.nix index 6861b7e00..2095b8f5d 100644 --- a/nix/lbstanza-bin/default.nix +++ b/nix/lbstanza-bin/default.nix @@ -6,11 +6,11 @@ stdenv.mkDerivation rec { pname = "lbstanza-bin"; - version = "0.14.33"; + version = "0.15.1"; src = fetchzip { url = "http://lbstanza.org/resources/stanza/lstanza_${lib.replaceStrings ["."] ["_"] version}.zip"; - sha256 = "1az9pddxh5kjqkkxsl3ffc23zjawilpisnvy9sy7ymnsp3b791lf"; + sha256 = "sha256-Ogfe5HX+fk3Tth5J07fWngyHnQjbkYBxKObqsNY8spc="; stripRoot=false; };