Skip to content

Commit

Permalink
feat: Add Nix packaging and more CI
Browse files Browse the repository at this point in the history
  • Loading branch information
gabyx committed Jun 28, 2024
1 parent 9a3b0e8 commit 5e77c97
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 88 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
---
name: rdf-protect

on:
Expand Down Expand Up @@ -48,8 +49,31 @@ jobs:
run: |
source .gitlab/scripts/before-script.sh &&
just nix-develop-ci just build
# - name: 3.1 - tests
# run: |
# source .gitlab/scripts/before-script.sh &&
# just nix-develop-ci just test

deploy:
test:
runs-on: ubuntu-latest
container:
image: ghcr.io/sdsc-ordes/rdf-protect:ci-build-1.0.0
image: ghcr.io/sdsc-ordes/rdf-protect:ci-test-1.0.0
steps:
- name: Checkout
uses: actions/checkout@v4
- name: 4 - test
run: |
source .gitlab/scripts/before-script.sh &&
just nix-develop-ci just test
package:
runs-on: ubuntu-latest
container:
image: ghcr.io/sdsc-ordes/rdf-protect:ci-package-1.0.0
steps:
- name: Checkout
uses: actions/checkout@v4
- name: 5 - package (nix)
run: |
source .gitlab/scripts/before-script.sh &&
just build-package
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
/target
# Tooling
.direnv

# Rust
/target

# Nix
result
package
8 changes: 8 additions & 0 deletions .gitlab/images/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ FROM ci-nix as ci-lint
# Build image.
# ===============================================
FROM ci-nix as ci-build

# Test image.
# ===============================================
FROM ci-nix as ci-test

# Package image.
# ===============================================
FROM ci-nix as ci-package
30 changes: 25 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ root_dir := `git rev-parse --show-toplevel`
# You can chose either "podman" or "docker".
container_mgr := "podman"

# Default recipe to list all recipes.
default:
just --list

# Enter a Nix development shell.
nix-develop shell="zsh":
cd "{{root_dir}}" && nix develop ./tools/nix#default --command zsh


## Standard stuff =============================================================
# Build the executable.
build *args:
cd "{{root_dir}}" && cargo build "${@:1}"
Expand All @@ -24,6 +28,10 @@ watch:
run:
cd "{{root_dir}}" && cargo run "${@:1}"

# Run the tests.
test:
cd "{{root_dir}}" && cargo test "${@:1}"

# Format the code.
format *args:
cd "{{comp_dir}}" && \
Expand All @@ -38,12 +46,24 @@ format-general *args:
lint *args:
cd "{{comp_dir}}" && \
"{{root_dir}}/tools/lint-rust.sh" {{args}}
## ============================================================================

# Upload all images for CI.
upload-ci-images:
cd "{{root_dir}}" && \
.gitlab/scripts/upload-images.sh

## CI stuff ===================================================================
# Enter a Nix development shell for CI.
nix-develop-ci:
cd "{{root_dir}}" && nix develop ./tools/nix#default --command "$@"

# Build the nix package into the folder `package` (first argument).
nix-package *args:
dir="${1:-package}" && \
cd "{{root_dir}}" && \
nix build "./tools/nix#rdf-protect" \
--out-link "$dir" \
"${@:2}"

# Upload all images for CI.
upload-ci-images:
cd "{{root_dir}}" && \
.gitlab/scripts/upload-images.sh
## ============================================================================
21 changes: 9 additions & 12 deletions tools/nix/flake.lock

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

18 changes: 4 additions & 14 deletions tools/nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@
# The Rust overlay to include the latest toolchain.
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};

# The library to build the rust package.
crane = {
url = "https://github.com/ipetkov/crane";
inputs = {
nixpkgs.follows = "nixpkgs";
};
Expand All @@ -50,10 +41,9 @@
nixpkgsStable,
flake-utils,
rust-overlay,
crane,
...
} @ inputs: let
rootDir = "./" + "../../";
rootDir = ./. + "../../..";
in
flake-utils.lib.eachDefaultSystem
# Creates an attribute map `{ devShells.<system>.default = ...}`
Expand All @@ -63,6 +53,7 @@
overlays = [(import rust-overlay)];

# Import nixpkgs and load it into pkgs.
# Overlay the rust toolchain
pkgs = import nixpkgs {
inherit system overlays;
};
Expand Down Expand Up @@ -104,9 +95,8 @@
};

packages = {
rdf-protect = (import pkgs/rdf-protect) {
inherit crane;
inherit rootDir;
rdf-protect = (import ./pkgs/rdf-protect.nix) {
inherit rootDir rustToolchain pkgs lib;
};

images = {
Expand Down
82 changes: 28 additions & 54 deletions tools/nix/pkgs/rdf-protect.nix
Original file line number Diff line number Diff line change
@@ -1,54 +1,28 @@
{pkgs, lib, rustPlatform, rootDir}:
rustPlatform.buildRustPackage rec {
inherit buildInputs nativeBuildInputs;

name = "rdf-protect";
src = rootDir;
version = "1.0.0";

cargoLock = {
lockFile = "${rootDir}/Cargo.lock";
allowBuiltinFetchGit = true;
};

preConfigure = ''
'';

postPatch = ''
'';

preFixup = lib.optionalString stdenv.isLinux ''
patchelf \
--add-needed "${pkgs.libGL}/lib/libEGL.so.1" \
--add-needed "${pkgs.vulkan-loader}/lib/libvulkan.so.1" \
$out/bin/wezterm-gui
'';

postInstall = ''
mkdir -p $out/nix-support
echo "${passthru.terminfo}" >> $out/nix-support/propagated-user-env-packages
install -Dm644 assets/icon/terminal.png $out/share/icons/hicolor/128x128/apps/org.wezfurlong.wezterm.png
install -Dm644 assets/wezterm.desktop $out/share/applications/org.wezfurlong.wezterm.desktop
install -Dm644 assets/wezterm.appdata.xml $out/share/metainfo/org.wezfurlong.wezterm.appdata.xml
install -Dm644 assets/shell-integration/wezterm.sh -t $out/etc/profile.d
installShellCompletion --cmd wezterm \
--bash assets/shell-completion/bash \
--fish assets/shell-completion/fish \
--zsh assets/shell-completion/zsh
install -Dm644 assets/wezterm-nautilus.py -t $out/share/nautilus-python/extensions
'';

passthru = {
terminfo =
pkgs.runCommand "wezterm-terminfo"
{
nativeBuildInputs = [pkgs.ncurses];
} ''
mkdir -p $out/share/terminfo $out/nix-support
tic -x -o $out/share/terminfo ${src}/termwiz/data/wezterm.terminfo
'';
};
};
{
pkgs,
lib,
rustToolchain,
rootDir,
...
}: let
rustPlatform = pkgs.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
in
rustPlatform.buildRustPackage {
name = "rdf-protect";
src = rootDir;
version = "1.0.0";

cargoLock = {
lockFile = rootDir + "/Cargo.lock";
};

meta = {
description = "A simple Rust CLI tool to protect sensitive values in RDF triples through pseudonymization";
homepage = "https://github.com/sdsc-ordes/rdf-protect";
license = lib.licenses.asl20;
maintainers = ["gabyx" "cmdoret"];
};
}

0 comments on commit 5e77c97

Please sign in to comment.