about summary refs log tree commit diff
path: root/tools/nixery/default.nix
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-11-11T21·07+0000
committerVincent Ambo <github@tazj.in>2019-11-27T14·12+0000
commit2b82f1b71a50b8b1473421cce0eec1a0d7ddc360 (patch)
treed42dcfd823f63ac77d3517b3c3154619f87f2cd2 /tools/nixery/default.nix
parentdf88da126a5c0dc97aa0fadaf1baf069b80ce251 (diff)
refactor: Reshuffle file structure for better code layout
This gets rid of the package called "server" and instead moves
everything into the project root, such that Go actually builds us a
binary called `nixery`.

This is the first step towards factoring out CLI-based functionality
for Nixery.
Diffstat (limited to 'tools/nixery/default.nix')
-rw-r--r--tools/nixery/default.nix44
1 files changed, 37 insertions, 7 deletions
diff --git a/tools/nixery/default.nix b/tools/nixery/default.nix
index 44ac7313adc7..7454c14a8567 100644
--- a/tools/nixery/default.nix
+++ b/tools/nixery/default.nix
@@ -20,6 +20,8 @@
 with pkgs;
 
 let
+  inherit (pkgs) buildGoPackage;
+
   # Hash of all Nixery sources - this is used as the Nixery version in
   # builds to distinguish errors between deployed versions, see
   # server/logs.go for details.
@@ -30,13 +32,41 @@ let
   # Go implementation of the Nixery server which implements the
   # container registry interface.
   #
-  # Users should use the nixery-bin derivation below instead.
-  nixery-server = callPackage ./server {
-    srcHash = nixery-src-hash;
+  # Users should use the nixery-bin derivation below instead as it
+  # provides the paths of files needed at runtime.
+  nixery-server = buildGoPackage rec {
+    name = "nixery-server";
+    goDeps = ./go-deps.nix;
+    src = ./.;
+
+    goPackagePath = "github.com/google/nixery";
+    doCheck = true;
+
+    # Simplify the Nix build instructions for Go to just the basics
+    # required to get Nixery up and running with the additional linker
+    # flags required.
+    outputs = [ "out" ];
+    preConfigure = "bin=$out";
+    buildPhase = ''
+      runHook preBuild
+      runHook renameImport
+
+      export GOBIN="$out/bin"
+      go install -ldflags "-X main.version=$(cat ${nixery-src-hash})" ${goPackagePath}
+    '';
+
+    fixupPhase = ''
+      remove-references-to -t ${go} $out/bin/nixery
+    '';
+
+    checkPhase = ''
+      go vet ${goPackagePath}
+      go test ${goPackagePath}
+    '';
   };
 in rec {
   # Implementation of the Nix image building logic
-  nixery-build-image = import ./build-image { inherit pkgs; };
+  nixery-prepare-image = import ./prepare-image { inherit pkgs; };
 
   # Use mdBook to build a static asset page which Nixery can then
   # serve. This is primarily used for the public instance at
@@ -50,8 +80,8 @@ in rec {
   # are installing Nixery directly.
   nixery-bin = writeShellScriptBin "nixery" ''
     export WEB_DIR="${nixery-book}"
-    export PATH="${nixery-build-image}/bin:$PATH"
-    exec ${nixery-server}/bin/server
+    export PATH="${nixery-prepare-image}/bin:$PATH"
+    exec ${nixery-server}/bin/nixery
   '';
 
   nixery-popcount = callPackage ./popcount { };
@@ -104,7 +134,7 @@ in rec {
       gzip
       iana-etc
       nix
-      nixery-build-image
+      nixery-prepare-image
       nixery-launch-script
       openssh
       zlib