Skip to content

Commit

Permalink
added: deploy.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesloetzsch committed Jan 6, 2021
1 parent da3c3a6 commit d5755a9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
31 changes: 29 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,38 @@ jobs:
- nix-{{ checksum "flake.lock" }}-{{ checksum "flake.nix" }}
- nix
- run: nix run .#example-clj-lein
deploy:
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 .#deploy
workflows:
version: 2
build+test:
build+test+deploy:
jobs:
- build
- build:
filters: # tags+branches
tags:
only: /.*/
- test:
requires:
- build
filters: # tags+branches
tags:
only: /.*/
- deploy:
requires:
- test
filters: # tags only
tags:
only: /.*/
branches:
ignore: /.*/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ The repository contains a `.circleci/config.yml`, showing an example of how to c
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_“.

The example also shows how a file from a derivation can be uploaded to an github release.
14 changes: 14 additions & 0 deletions deploy.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ pkgs, release-from }:
(pkgs.writeScriptBin "deploy" ''
#!${pkgs.runtimeShell} -xe
export PATH="${pkgs.stdenv.lib.makeBinPath (with pkgs; [github-release])}"
export GITHUB_USER="$CIRCLE_PROJECT_USERNAME"
export GITHUB_REPO="$CIRCLE_PROJECT_REPONAME"
export TAG="$CIRCLE_TAG"
[ "$TAG" = "v${release-from.version}" ]
github-release release -t $TAG
github-release upload -t $TAG -f "${release-from}/${release-from.release-file}" -n ${release-from.release-file}
'')
5 changes: 4 additions & 1 deletion examples/clj-lein/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ inherit (pkgs) lib stdenv jdk11_headless maven makeWrapper leiningen;
inherit (stdenv) mkDerivation;
in mkDerivation rec {
pname = "example";
version = "0.1.0-SNAPSHOT";
version = "0.0.1-SNAPSHOT";
name = "${pname}-${version}";
src = lib.cleanSource ./.;

Expand Down Expand Up @@ -37,4 +37,7 @@ in mkDerivation rec {
# this should be the paths from the dependency derivation
makeWrapper ${jdk11_headless}/bin/java $out/bin/${pname} --add-flags "-jar $out/${name}-standalone.jar"
'';

## Upload into github release via ../../deploy.nix
release-file = "${name}-standalone.jar";
}
2 changes: 1 addition & 1 deletion examples/clj-lein/project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject example "0.1.0-SNAPSHOT"
(defproject example "0.0.1-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
Expand Down
9 changes: 7 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@
system = "x86_64-linux";
pkgs = import nixpkgs { system="x86_64-linux"; };
buildMavenRepositoryFromLockFile = mvn2nix-pkgs.legacyPackages.x86_64-linux.buildMavenRepositoryFromLockFile;
release-from = import ./examples/clj-lein/default.nix { inherit pkgs buildMavenRepositoryFromLockFile; };
in
rec {
legacyPackages.x86_64-linux = {
## Tools
mvn2nix = mvn2nix-pkgs.legacyPackages.x86_64-linux.mvn2nix;
deploy = import ./deploy.nix { inherit pkgs release-from; };

example-clj-lein = import ./examples/clj-lein/default.nix { inherit pkgs buildMavenRepositoryFromLockFile; };
example-clj-lein-docker = import ./examples/clj-lein/docker.nix { inherit pkgs buildMavenRepositoryFromLockFile; };
## Builds

flake-docker = import ./flake-docker.nix { inherit pkgs; };

example-clj-lein = import ./examples/clj-lein/default.nix { inherit pkgs buildMavenRepositoryFromLockFile; };
example-clj-lein-docker = import ./examples/clj-lein/docker.nix { inherit pkgs buildMavenRepositoryFromLockFile; };
};

defaultPackage.x86_64-linux = legacyPackages.x86_64-linux.flake-docker;
Expand Down

0 comments on commit d5755a9

Please sign in to comment.