Skip to content

Commit

Permalink
Static build
Browse files Browse the repository at this point in the history
  • Loading branch information
cofob committed Aug 31, 2024
1 parent bc8826d commit 60b6f84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
name: Build Nix
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
derivation: [fastside, fastside-static]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -51,9 +54,9 @@ jobs:
name: cofob
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"

- name: Build derivations
- name: Build derivation ${{ matrix.derivation }}
run: |
nix build .#fastside
nix build .#${{ matrix.derivation }}
build-linux:
name: Build Linux
Expand Down
18 changes: 15 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
let
pkgs = import nixpkgs { inherit system; };
naersk' = pkgs.callPackage naersk { };
pkgsStatic = pkgs.pkgsStatic;
naersk'static = pkgsStatic.callPackage naersk { };

# This needed to remove dependency on services.json file and avoid useless rebuilds
constructed-source = pkgs.runCommand "constructed-source" { } ''
Expand All @@ -26,29 +28,38 @@
cp ${./Cargo.lock} $out/Cargo.lock
'';

fastside = naersk'.buildPackage {
fastside-attrs = {
name = "fastside-0.2.0";
src = constructed-source;
nativeBuildInputs = with pkgs; [ mold ];
NIX_CFLAGS_LINK = " -fuse-ld=mold";
};

fastside = naersk'.buildPackage fastside-attrs;

fastside-static = naersk'static.buildPackage fastside-attrs;

fastside-baked-services = pkgs.writeShellScriptBin "fastside-baked-services" ''
export FS__SERVICES_PATH=${./services.json}
${fastside}/bin/fastside $@
'';

fastside-baked-services-static = pkgs.writeShellScriptBin "fastside-baked-services" ''
export FS__SERVICES_PATH=${./services.json}
${fastside-static}/bin/fastside $@
'';

fastside-docker = pkgs.dockerTools.buildLayeredImage {
name = "fastside";
tag = "latest";
contents = [ fastside ];
contents = [ fastside-static ];
config = { Cmd = [ "/bin/fastside" "serve" "-l" "0.0.0.0:8080" ]; };
};

fastside-docker-baked-services = pkgs.dockerTools.buildLayeredImage {
name = "fastside";
tag = "latest";
contents = [ fastside fastside-baked-services ];
contents = [ fastside-static fastside-baked-services-static ];
config = { Cmd = [ "/bin/fastside-baked-services" "serve" "-l" "0.0.0.0:8080" ]; };
};

Expand All @@ -59,6 +70,7 @@
packages = {
default = fastside;
fastside = fastside;
fastside-static = fastside-static;
fastside-baked-services = fastside-baked-services;
fastside-docker = fastside-docker;
fastside-docker-baked-services = fastside-docker-baked-services;
Expand Down

0 comments on commit 60b6f84

Please sign in to comment.