From 59b112bd609de9b1f8af19f8fb3841aca365f6a0 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Fri, 28 Jun 2024 13:26:44 +0200 Subject: [PATCH 1/3] Add Dolos as package in Flake --- flake.nix | 13 +++++++++++-- package.nix | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 package.nix diff --git a/flake.nix b/flake.nix index 8123dc50e..5cc502167 100644 --- a/flake.nix +++ b/flake.nix @@ -29,14 +29,23 @@ }) ]; }; - in - { + in rec { devShells = rec { default = dolos-general; dolos-general = import ./shell.nix { inherit pkgs system; }; dolos-docs = import ./docs/shell.nix { inherit pkgs system; }; dolos-api = import ./api/shell.nix { inherit pkgs system; }; }; + packages = rec { + default = dolos-cli; + dolos-cli = pkgs.callPackage (import ./package.nix) {}; + }; + checks = rec { + default = dolos-cli; + dolos-cli = pkgs.runCommand "check-dolos-cli" {} '' + ${packages.dolos-cli}/bin/dolos run -f csv -o $out ${./samples/javascript/simple-dataset.zip} + ''; + }; } ); } diff --git a/package.nix b/package.nix new file mode 100644 index 000000000..c59f52f3a --- /dev/null +++ b/package.nix @@ -0,0 +1,55 @@ +{ lib +, buildNpmPackage +, jq +, unzip +}: +buildNpmPackage rec { + pname = "dolos"; + version = "2.7.1"; + + src = ./.; + + npmDepsHash = "sha256-6/+j8KPcVYhsbeTYFp8WRisuVowlYdzKFCKG5qo/HNU="; + + npmWorkspace="cli"; + + makeWrapperArgs = "--prefix PATH : ${lib.makeBinPath [ unzip ]}"; + + makeCacheWritable = true; + + prePatch = '' + test -f parsers/bash/binding.gyp || (echo -e "\n Submodules are not present, run flake with '.?submodules=1'\n" && exit 1) + ''; + + postPatch = '' + ${jq}/bin/jq -r 'del(.devDependencies) | del(.scripts.prepare)' parsers/package.json > package.json.tmp + mv package.json.tmp parsers/package.json + ''; + + buildInputs = [ unzip ]; + + buildPhase = '' + # Build each needed workspace + for dir in core parsers lib web cli; do + echo "Building dolos-$dir" + npm --workspace="$dir" run build + done + ''; + + postInstall = '' + for dir in core parsers lib web; do + # npm creates a symlink to each dependent workspace in node_modules + # overwrite each link with that workspace's build output (with npm pack) + local module="$packageOut/node_modules/@dodona/dolos-$dir" + rm "$module" + while IFS= read -r file; do + local dest="$module/$(dirname "$file")" + mkdir -p "$dest" + cp "$dir/$file" "$dest" + done < <(${jq}/bin/jq --raw-output '.[0].files | map(.path | select(. | startswith("node_modules/") | not)) | join("\n")' <<< "$(npm_config_cache="$HOME/.npm" npm pack --json --dry-run --loglevel=warn --no-foreground-scripts --workspace="$dir")") + done + # dolos-parsers does not include the built parsers with npm pack, copy them + cp -r parsers/build "$packageOut/node_modules/@dodona/dolos-parsers" + ''; + +} From d3b7db4cc094d5834bba6078f667dbfd976ef544 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Wed, 17 Jul 2024 16:25:37 +0200 Subject: [PATCH 2/3] Check flake in CI/CD --- .github/workflows/validation.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 80712f2a9..6a9b36b00 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -7,6 +7,21 @@ concurrency: cancel-in-progress: true jobs: + flake-build-check: + name: "Nix Flake โ„๏ธ" + runs-on: ubuntu-latest + steps: + - name: Checkout ๐Ÿ›Ž๏ธ + uses: actions/checkout@v4 + with: + submodules: true + - name: Setup Nix ๐Ÿ“š + uses: cachix/install-nix-action@v27 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - name: Build & check ๐Ÿงช + run: nix build -L '.?submodules=1#checks.x86_64-linux.dolos-cli' + install-cli: name: "Install and run CLI on ${{ matrix.os }}" strategy: From 41214502477e59cf49505c308ef14c20b065e690 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Wed, 17 Jul 2024 17:25:05 +0200 Subject: [PATCH 3/3] Add dolos overlay --- flake.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flake.nix b/flake.nix index 5cc502167..f2b90b06c 100644 --- a/flake.nix +++ b/flake.nix @@ -40,6 +40,9 @@ default = dolos-cli; dolos-cli = pkgs.callPackage (import ./package.nix) {}; }; + overlays.default = final: prev: { + dolos-cli = final.callPackage (import ./package.nix) {}; + }; checks = rec { default = dolos-cli; dolos-cli = pkgs.runCommand "check-dolos-cli" {} ''