make this compatible with the new nix way of doing things

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-01-01 16:24:41 -05:00
parent 474fd908bc
commit 9c5250d10a
4 changed files with 71 additions and 70 deletions

View File

@ -15,13 +15,14 @@ jobs:
- uses: cachix/cachix-action@v7 - uses: cachix/cachix-action@v7
with: with:
name: xe name: xe
- run: nix-build - run: nix-build --no-out-link
- name: Log into GitHub Container Registry - name: Log into GitHub Container Registry
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u Xe --password-stdin
- name: Docker push - name: Docker push
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
run: | run: |
nix-build ./docker.nix
docker load -i result docker load -i result
docker tag xena/christinewebsite:latest ghcr.io/xe/site:$GITHUB_SHA docker tag xena/christinewebsite:latest ghcr.io/xe/site:$GITHUB_SHA
docker push ghcr.io/xe/site docker push ghcr.io/xe/site

View File

@ -1,23 +1,51 @@
{ system ? builtins.currentSystem }: { sources ? import ./nix/sources.nix, pkgs ? import sources.nixpkgs { } }:
with pkgs;
let let
sources = import ./nix/sources.nix; srcNoTarget = dir:
pkgs = import sources.nixpkgs { inherit system; }; builtins.filterSource
callPackage = pkgs.lib.callPackageWith pkgs; (path: type: type != "directory" || builtins.baseNameOf path != "target")
site = callPackage ./site.nix { }; dir;
dockerImage = pkg: naersk = pkgs.callPackage sources.naersk { };
pkgs.dockerTools.buildLayeredImage { dhallpkgs = import sources.easy-dhall-nix { inherit pkgs; };
name = "xena/christinewebsite"; src = srcNoTarget ./.;
tag = "latest";
contents = [ pkgs.cacert pkg ]; xesite = naersk.buildPackage {
inherit src;
config = { buildInputs = [ pkg-config openssl git ];
Cmd = [ "${pkg}/bin/xesite" ]; remapPathPrefix = true;
Env = [ "CONFIG_FNAME=${pkg}/config.dhall" "RUST_LOG=info" ];
WorkingDir = "/";
};
}; };
in dockerImage site config = stdenv.mkDerivation {
pname = "xesite-config";
version = "HEAD";
buildInputs = [ dhallpkgs.dhall-simple ];
phases = "installPhase";
installPhase = ''
cd ${src}
dhall resolve < ${src}/config.dhall >> $out
'';
};
in pkgs.stdenv.mkDerivation {
inherit (xesite) name;
inherit src;
phases = "installPhase";
installPhase = ''
mkdir -p $out $out/bin
cp -rf ${config} $out/config.dhall
cp -rf $src/blog $out/blog
cp -rf $src/css $out/css
cp -rf $src/gallery $out/gallery
cp -rf $src/signalboost.dhall $out/signalboost.dhall
cp -rf $src/static $out/static
cp -rf $src/talks $out/talks
cp -rf ${xesite}/bin/xesite $out/bin/xesite
'';
}

23
docker.nix Normal file
View File

@ -0,0 +1,23 @@
{ system ? builtins.currentSystem }:
let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs { inherit system; };
callPackage = pkgs.lib.callPackageWith pkgs;
site = callPackage ./site.nix { };
dockerImage = pkg:
pkgs.dockerTools.buildLayeredImage {
name = "xena/christinewebsite";
tag = "latest";
contents = [ pkgs.cacert pkg ];
config = {
Cmd = [ "${pkg}/bin/xesite" ];
Env = [ "CONFIG_FNAME=${pkg}/config.dhall" "RUST_LOG=info" ];
WorkingDir = "/";
};
};
in dockerImage site

View File

@ -1,51 +0,0 @@
{ sources ? import ./nix/sources.nix, pkgs ? import sources.nixpkgs { } }:
with pkgs;
let
srcNoTarget = dir:
builtins.filterSource
(path: type: type != "directory" || builtins.baseNameOf path != "target")
dir;
naersk = pkgs.callPackage sources.naersk { };
dhallpkgs = import sources.easy-dhall-nix { inherit pkgs; };
src = srcNoTarget ./.;
xesite = naersk.buildPackage {
inherit src;
buildInputs = [ pkg-config openssl git ];
remapPathPrefix = true;
};
config = stdenv.mkDerivation {
pname = "xesite-config";
version = "HEAD";
buildInputs = [ dhallpkgs.dhall-simple ];
phases = "installPhase";
installPhase = ''
cd ${src}
dhall resolve < ${src}/config.dhall >> $out
'';
};
in pkgs.stdenv.mkDerivation {
inherit (xesite) name;
inherit src;
phases = "installPhase";
installPhase = ''
mkdir -p $out $out/bin
cp -rf ${config} $out/config.dhall
cp -rf $src/blog $out/blog
cp -rf $src/css $out/css
cp -rf $src/gallery $out/gallery
cp -rf $src/signalboost.dhall $out/signalboost.dhall
cp -rf $src/static $out/static
cp -rf $src/talks $out/talks
cp -rf ${xesite}/bin/xesite $out/bin/xesite
'';
}