diff --git a/Justfile b/Justfile new file mode 100644 index 0000000000000000000000000000000000000000..50d5a496ac215f4e11e6297d58d4d85d684b76f9 --- /dev/null +++ b/Justfile @@ -0,0 +1,29 @@ +list: + @just --list + +nix_volume_path := if env_var_or_default("container", "") == "podman" {"/nix"} else {`podman volume inspect --format '{{.Mountpoint}}' nix`} + +load-images: + podman load < {{nix_volume_path}}/export/docker-bundle.tar.gz + +# We use podman not docker. +export COMPOSE_INTERACTIVE_NO_CLI := "1" +compose *ARGS: + docker-compose -f {{nix_volume_path}}/export/docker-compose.yaml --project-directory . {{ARGS}} + +build: + just enter-nix just /src/_build + +start-nix: + @if ! podman container exists nix; then \ + podman run --name nix -v nix:/nix -v $PWD:/src:ro,Z -v $PWD/nix.conf /etc/nix/nix.conf --tmpfs /tmp --detach nixos/nix:latest /nix/var/nix/profiles/pause/bin/pause ; \ + else \ + podman container start nix ; \ + fi + +enter-nix *ARGS: start-nix + podman exec -t -i -w /src nix nix-shell --arg vagrant false {{if ARGS != "" {'--command "' + ARGS + '"'} else {''} }} + +_build: + nix build -v -j auto -f arion.nix package --profile /nix/var/nix/profiles/export --no-link + ln -srnf $(readlink -e /nix/var/nix/profiles/export) /nix/export diff --git a/arion.nix b/arion.nix new file mode 100644 index 0000000000000000000000000000000000000000..4f2680652ce5a9104d7d9ea6d3a13a9a31c760aa --- /dev/null +++ b/arion.nix @@ -0,0 +1,41 @@ +{ pkgs ? import ./nixpkgs-2105.nix {} +, configuration ? ./morph/grid/local/configuration.nix +, includeStorePaths ? false +}: +let + nixpkgs = import <nixpkgs> {}; + local-grid = "${./.}/morph/grid/local"; + arion-src = nixpkgs.fetchFromGitHub { + owner = "tp-la"; + repo = "arion"; + rev = "hack"; + sha256 = "0wv4wbzzd926qm81h78v10wyhiaayx2jggpb1ijzk118a543sz84"; + }; + arion-eval = args@{...}: import "${arion-src}/src/nix/eval-composition.nix" ({ inherit pkgs; } // args); + arion = arion-eval { + modules = [ "${local-grid}/arion-compose.nix" ]; + }; + bundle = pkgs.dockerTools.mergeImages ( + map ( + { imageName, imageTag, imageExe }: + pkgs.runCommand "${baseNameOf imageName}.tar.gz" + { + inherit imageName; + passthru = { inherit imageTag; }; + nativeBuildInputs = [ pkgs.pigz ]; + } "${imageExe} | pigz -nT > $out" + ) arion.config.build.imagesToLoad + ); + docker-yaml = pkgs.runCommand "docker-compose.yaml" + { nativeBuildInputs = [ pkgs.gojsontoyaml ]; } + "${pkgs.gojsontoyaml}/bin/gojsontoyaml <${arion.config.out.dockerComposeYaml} > $out"; + package = pkgs.runCommand "privatestorage" + { preferLocalBuild = true; allowSubstitutes = false; } + '' + mkdir -p $out + ln -sr ${bundle} $out/docker-bundle.tar.gz + ln -sr ${docker-yaml} $out/docker-compose.yaml + ''; + pause = pkgs.callPackage ./pause.nix {}; +in + {inherit pkgs arion local-grid bundle arion-eval arion-src docker-yaml package pause;} diff --git a/pause.nix b/pause.nix new file mode 100644 index 0000000000000000000000000000000000000000..5c7b427f811283c4c5a3b9c70308447cdfa71f34 --- /dev/null +++ b/pause.nix @@ -0,0 +1,19 @@ +{ pkgsStatic, fetchurl }: +let + pause-src = fetchurl { + url = "https://github.com/kubernetes/kubernetes/raw/cd80d70c3df154e8f6f2df5bfe8f7f8a490b7acc/build/pause/linux/pause.c"; + sha256 = "1slm2r6gb5biqfdx1hq4ghy0sjxrydv3wi9bga9n53jzmchzx8ql"; + }; +in +pkgsStatic.stdenv.mkDerivation { + name = "pause"; + dontUnpack = true; + static = true; + CFLAGS = [ + "-Os" "-Wall" "-Werror" #"-static" + ]; + installPhase = '' + mkdir -p $out/bin + $CC $CFLAGS ${pause-src} -o $out/bin/pause + ''; +}