Skip to content

Commit

Permalink
added: .circleci/config.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesloetzsch committed Jan 6, 2021
1 parent d60eb47 commit da3c3a6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
40 changes: 40 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: 2.1
jobs:
build:
docker:
- image: johannesloetzsch/nix-flake:latest
steps:
- run:
name: Disable Sandbox
command: mkdir -p ~/.config/nix/; echo 'sandbox = false' > ~/.config/nix/nix.conf;
- checkout
- restore_cache:
keys:
- nix-{{ checksum "flake.lock" }}-{{ checksum "flake.nix" }}
- nix
- run: nix build .#example-clj-lein
- save_cache:
key: nix-{{ checksum "flake.lock" }}-{{ checksum "flake.nix" }}
paths:
- /nix/
test:
docker:
- image: johannesloetzsch/nix-flake:latest
steps:
- run:
name: Disable Sandbox
command: mkdir -p ~/.config/nix/; echo 'sandbox = false' > ~/.config/nix/nix.conf;
- checkout
- restore_cache:
keys:
- nix-{{ checksum "flake.lock" }}-{{ checksum "flake.nix" }}
- nix
- run: nix run .#example-clj-lein
workflows:
version: 2
build+test:
jobs:
- build
- test:
requires:
- build
4 changes: 0 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
FROM johannesloetzsch/nix-flake
## Building local repositorys with flake requires git
RUN nix-channel --add https://nixos.org/channels/nixpkgs-unstable && \
nix-channel --update && \
nix-env -i git

RUN mkdir /source/
COPY . /source/
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Run or bootstrap a docker-container containing nix with flake-support

bootstrap-test-push: bootstrap run run-derived-buildserver push
bootstrap-test-push: bootstrap run run-derived-buildserver ci push

run:
## Just as an example we use nix-flakes to run a hello-world-app
Expand All @@ -17,6 +17,10 @@ bootstrap:
nix build .#flake-docker
docker load < result

ci:
## Note: `circle-ci local` doesn't support workflows but only single jobs (defaults to build)
nix run nixpkgs#circleci-cli local execute

push:
docker login
docker push johannesloetzsch/nix-flake:latest
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
This repository contains examples how to package clojure(script) applications with nix.

## buildserver
## Buildserver

[
![docker image size](https://img.shields.io/docker/image-size/johannesloetzsch/nix-flake.svg)
![docker pulls](https://img.shields.io/docker/pulls/johannesloetzsch/nix-flake.svg)
](https://hub.docker.com/repository/docker/johannesloetzsch/nix-flake)

In case your build-system doesn't have nix installed, you can use the docker-container defined in `flake-docker.nix` [from hub.docker.com](https://hub.docker.com/repository/docker/johannesloetzsch/nix-flake).

Expand All @@ -18,11 +23,20 @@ docker build -t buildserver-example .
docker run -ti -v nix:/nix/ buildserver-example
```

## caching
## Caching

Using nix allows simple and efficient caching. To keep downloaded and built derivations between restarts of the docker-buildserver, define `/nix` to be a volume.
For efficient usage of remote flakes, keep `~/.cache/nix/flake-registry.json`. Further speedup is achieved, by memorization of nix-expressions in `~/.cache/nix/eval-cache*`.

```shell
docker run -ti -v nix:/nix/ -v root:/root/ johannesloetzsch/nix-flake:latest nix run nixpkgs#hello
```

## Circleci

[![circleci](https://circleci.com/gh/johannesloetzsch/nix-docker-cljc.svg?style=shield)](https://app.circleci.com/pipelines/github/johannesloetzsch/nix-docker-cljc)

The repository contains a `.circleci/config.yml`, showing an example of how to configure a ci build based on nix.
Caching is done based on `flake.lock` and `flake.nix`. In case one of the files changed, it will fallback to the latest available cache.

Note: Circleci requires that nix builds run without sandboxing, otherwise it fails with „_cannot set host name: Operation not permitted_“.
6 changes: 5 additions & 1 deletion flake-docker.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{ pkgs }:
let
contents = with pkgs; [ nixFlakes coreutils shadow cacert bashInteractive ];
contents = with pkgs; [ ## Minimal dependencies (~50MB)
nixFlakes coreutils shadow cacert bashInteractive
## Requirements for circleci (~110MB)
git gnutar gzip
];
binPath = pkgs.stdenv.lib.makeBinPath contents;
in
pkgs.dockerTools.buildImage {
Expand Down

0 comments on commit da3c3a6

Please sign in to comment.