Skip to content

Commit

Permalink
[WIP] Last tweaks and plumbing ...
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka committed Mar 16, 2023
1 parent f1d950c commit cb431c7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 47 deletions.
37 changes: 20 additions & 17 deletions bootstrap.nix
Expand Up @@ -8,17 +8,6 @@
{ devShells, pkgs, supportedSystems, ... }:
with builtins;
let
closure = drv:
pkgs.runCommand "test" {
requiredSystemFeatures = [ "recursive-nix" ];
nativeBuildInputs = [ pkgs.nix ];
} ''
mkdir -p $out/nix-support
HOME=$(mktemp -d)
# TODO: replace zstd by zip?
nix-store --export "${drv}" | zstd -z8T8 > $out/closure.zstd"
echo "file binary-dist \"$out/closure.zstd\"" > $out/nix-support/hydra-build-products
'';
# TODO: rather use `pkgs.writeShellApplication` so the script content run
# against `shellcheck`?
bootstrapScript = pkgs.writeTextFile {
Expand All @@ -45,6 +34,22 @@ let
extra_nix_config: |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
substituters = https://cache.iog.io/ https://cache.nixos.org/"
# TODO: explain how to use the shell with something better than:
#
# - name: Add devx-shell
# run: |
# echo $PATH
# cat <<EOF > /usr/local/bin/devx-shell
# #!/bin/bash
# nix develop github:input-output-hk/devx#ghc8107-static-minimal \
# --command /usr/bin/bash <(echo 'eval "\$shellHook\"'; cat "$1")
# EOF
# chmod +x /usr/local/bin/devx-shell
# - name: Build
# shell: devx-shell {0}
# run: |
# cabal update
# cabal build
exit 1
else
echo "... we can run https://github.com/DeterminateSystems/nix-installer for you!"
Expand All @@ -70,7 +75,6 @@ let
if [[ "$OS" == darwin* ]]; then OS="darwin"; fi
if [[ "$OS" == linux* ]]; then OS="linux"; fi
SYSTEM="$ARCH-$OS"
# TODO: @angerman is it okay to just say that devShell is first CLI arg?!
DEVSHELL="$1"
# 2. Generate per system / devShell shell snippet...
Expand All @@ -81,11 +85,10 @@ let
echo "Warning: this script should be run (the first time) as a trusted Nix user:"
echo "https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-trusted-users"
echo "n.b. root is by default the only trusted user on a fresh nix setup!"
# TODO: I should also ensure that zstd is available on user machine ... replace zstd by zip?
curl "TODO: the right /latest/ url hydra with closure build product" | zstd -d | nix-store --import
curl "https://ci.zw3rk.com/job/input-output-hk-devx/pullrequest-25/$DEVSHELL-closure.$SYSTEM/latest/download/1" | unzip | nix-store --import
fi
# TODO: This should rather be the fallback ... and this be just the loading of `nix print-dev-env` output
nix develop "github:input-output-hk/devx#$devshell" --no-write-lock-file --refresh
# TODO: We should have -source of this in the /nix/store somewhere, with the `flake.nix` file. So we _should_ be able to do `nix develop /nix/store/...-source#$devshell`?
curl "https://ci.zw3rk.com/job/input-output-hk-devx/pullrequest-25/$DEVSHELL-closure.$SYSTEM/latest/download/2" | sh
exit 0
fi
'') devShells))) supportedSystems)}
Expand All @@ -96,4 +99,4 @@ in pkgs.runCommand "bootstrap-devx" { } ''
mkdir -p $out/nix-support
echo "file binary-dist \"$out/bootstrap-devx.sh\"" > $out/nix-support/hydra-build-products
cp ${bootstrapScript} $out/bootstrap-devx.sh
''
''
46 changes: 16 additions & 30 deletions flake.nix
Expand Up @@ -123,34 +123,22 @@
import ./static.nix { pkgs = static-pkgs; inherit compiler compiler-nix-name; withHLS = false; withHlint = false; }
)) (compilers static-pkgs.buildPackages)
);
# TODO: @angerman should I merge `packages.default` inside `hydraJobs`?
# ... not sure that's the right approach?
# packages.default = import ./bootstrap.nix { inherit devShells pkgs supportedSystems; };
hydraJobs = devShells
// pkgs.lib.mapAttrs' (name: drv:
pkgs.lib.nameValuePair "${name}-closure" (
pkgs.runCommand "${name}-closure" {
requiredSystemFeatures = [ "recursive-nix" ];
nativeBuildInputs = [ pkgs.nix pkgs.zstd pkgs.zip ];
}
''
mkdir -p $out/nix-support
HOME=$(mktemp -d)
# TODO: replace zstd by zip?
nix-store --export $(nix-store -qR ${drv}) | zstd -z8T8 > $out/closure.zstd
echo "file binary-dist \"$out/closure.zstd\"" > $out/nix-support/hydra-build-products
nix-store --export $(nix-store -qR ${drv}) | zip -9 > $out/closure.zip
echo "file binary-dist \"$out/closure.zstd\"" >> $out/nix-support/hydra-build-products
nix --offline --extra-experimental-features "nix-command flakes" \
print-dev-env ${drv.drvPath} >> $out/env.sh
echo "file binary-dist \"$out/env.sh\"" >> $out/nix-support/hydra-build-products
'')
) devShells;

# }; # // { bootstrap-shell = packages.default; };
hydraJobs = devShells // (pkgs.lib.mapAttrs' (name: drv:
pkgs.lib.nameValuePair "${name}-closure"
(pkgs.runCommand "${name}-closure" {
requiredSystemFeatures = [ "recursive-nix" ];
nativeBuildInputs = [ pkgs.nix pkgs.zstd pkgs.zip ];
} ''
mkdir -p $out/nix-support
HOME=$(mktemp -d)
nix-store --export $(nix-store -qR ${drv}) | zip -9 > $out/closure.zip
echo "file binary-dist \"$out/closure.zstd\"" >> $out/nix-support/hydra-build-products
nix --offline --extra-experimental-features "nix-command flakes" \
print-dev-env ${drv.drvPath} >> $out/env.sh
echo "file binary-dist \"$out/env.sh\"" >> $out/nix-support/hydra-build-products
'')) devShells) // (import ./bootstrap.nix {
inherit devShells pkgs supportedSystems;
});
});

# --- Flake Local Nix Configuration ----------------------------
Expand All @@ -163,8 +151,6 @@
extra-trusted-public-keys = [
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
"loony-tools:pr9m4BkM/5/eSTZlkQyRt57Jz7OMBxNSUiMC4FkcNfk="
# TODO: @angerman add s3.zw3rk.com key?
# "s3.zw3rk.com:fx41B+c2mUAvQt+wgzD0g/SBesJhUiShi0s6dV549Co="
];
# post-build-hook = "./upload-to-cache.sh";
allow-import-from-derivation = "true";
Expand Down

0 comments on commit cb431c7

Please sign in to comment.