Skip to content

Commit

Permalink
Merge pull request #1576 from dodona-edu/nix-package
Browse files Browse the repository at this point in the history
Add package to flake
  • Loading branch information
rien authored Jul 17, 2024
2 parents dafda7f + 4121450 commit 7574145
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 14 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,26 @@
})
];
};
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) {};
};
overlays.default = final: prev: {
dolos-cli = final.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}
'';
};
}
);
}
55 changes: 55 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -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"
'';

}

0 comments on commit 7574145

Please sign in to comment.