From 0b5b538077934125d87d29e4e8510fbbd8addd20 Mon Sep 17 00:00:00 2001 From: Gabor Pihaj Date: Sat, 30 Sep 2023 17:44:43 +0000 Subject: [PATCH] refactor: split flake.nix into multiple files (#8) Reviewed-on: https://git.vdx.hu/voidcontext/woodpecker-plugin-nix-attic/pulls/8 Co-authored-by: Gabor Pihaj Co-committed-by: Gabor Pihaj --- entrypoint.nix | 33 +++++++++++++++++++++++++++ flake.nix | 62 +++----------------------------------------------- mkImage.nix | 31 +++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 59 deletions(-) create mode 100644 entrypoint.nix create mode 100644 mkImage.nix diff --git a/entrypoint.nix b/entrypoint.nix new file mode 100644 index 0000000..0b3356e --- /dev/null +++ b/entrypoint.nix @@ -0,0 +1,33 @@ +{pkgs, ...}: +pkgs.writeShellApplication { + name = "woodpecker-nix-attic-entrypoint"; + text = '' + cat << EOF >> /etc/nix/nix.conf + experimental-features = nix-command flakes + trusted-substituters = $PLUGIN_BINARY_CACHE + extra-trusted-public-keys = $PLUGIN_BINARY_CACHE_PUBLIC_KEY + extra-substituters = $PLUGIN_BINARY_CACHE + netrc-file = /tmp/netrc + EOF + + if [[ $PLUGIN_BINARY_CACHE =~ ^https?:\/\/([^\/]+) ]]; then + machine=''${BASH_REMATCH[1]} + cat << EOF >> /tmp/netrc + machine $machine + password $PLUGIN_BINARY_CACHE_TOKEN + EOF + + fi + + cat << EOF >> run.sh + #!/usr/bin/env bash + export PATH=/bin:$PATH + + set -x -e -o pipefail + + $PLUGIN_SCRIPT + EOF + + sh run.sh + ''; +} diff --git a/flake.nix b/flake.nix index e17fcd6..0191d51 100644 --- a/flake.nix +++ b/flake.nix @@ -13,67 +13,11 @@ system = "x86_64-linux"; overlays = [attic.overlays.default]; }; - entrypoint = pkgs.writeShellApplication { - name = "woodpecker-nix-attic-entrypoint"; - text = '' - cat << EOF >> /etc/nix/nix.conf - experimental-features = nix-command flakes - trusted-substituters = $PLUGIN_BINARY_CACHE - extra-trusted-public-keys = $PLUGIN_BINARY_CACHE_PUBLIC_KEY - extra-substituters = $PLUGIN_BINARY_CACHE - netrc-file = /tmp/netrc - EOF - - if [[ $PLUGIN_BINARY_CACHE =~ ^https?:\/\/([^\/]+) ]]; then - machine=''${BASH_REMATCH[1]} - cat << EOF >> /tmp/netrc - machine $machine - password $PLUGIN_BINARY_CACHE_TOKEN - EOF - - fi - - cat << EOF >> run.sh - #!/usr/bin/env bash - export PATH=/bin:$PATH - - set -x -e -o pipefail - - $PLUGIN_SCRIPT - EOF - - sh run.sh - ''; - }; - nixImage = pkgs.dockerTools.pullImage { - imageName = "nixos/nix"; - imageDigest = "sha256:cee9f1cda2d794c53ca0db0794ee54cfea32748dddb718beba9bf654416e437a"; - sha256 = "1angy2h02q3smpcyja3h3rzqx6nip50w56pn3yc56qcr9q896ffb"; - finalImageName = "nixos/nix"; - finalImageTag = "2.15.1"; - }; - mkImage = tag: - pkgs.dockerTools.buildImage { - name = "git.vdx.hu/voidcontext/woodpecker-plugin-nix-attic"; - tag = tag; - fromImage = nixImage; - # runAsRoot = '' - # #!${pkgs.stdenv.shell} - # export PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH - # ''; - copyToRoot = pkgs.buildEnv { - name = "woodpecker-plugin-nix-attic-image-root"; - paths = [pkgs.gnumake pkgs.attic-client entrypoint]; - pathsToLink = ["/bin"]; - }; - - config.Cmd = ["/bin/woodpecker-nix-attic-entrypoint"]; - diskSize = 2048; - }; - latest = mkImage "latest"; + entrypoint = import ./entrypoint.nix {inherit pkgs;}; + mkImage = import ./mkImage.nix {inherit pkgs entrypoint;}; in { packages.x86_64-linux.default = mkImage null; - packages.x86_64-linux.woodpecker-plugin-nix-attic-latest = latest; + packages.x86_64-linux.woodpecker-plugin-nix-attic-latest = mkImage "latest"; packages.x86_64-linux.woodpecker-plugin-nix-attic-release = mkImage "0.1.0"; }; } diff --git a/mkImage.nix b/mkImage.nix new file mode 100644 index 0000000..7e2b5c5 --- /dev/null +++ b/mkImage.nix @@ -0,0 +1,31 @@ +{ + pkgs, + entrypoint, + ... +}: let + nixImage = pkgs.dockerTools.pullImage { + imageName = "nixos/nix"; + imageDigest = "sha256:cee9f1cda2d794c53ca0db0794ee54cfea32748dddb718beba9bf654416e437a"; + sha256 = "1angy2h02q3smpcyja3h3rzqx6nip50w56pn3yc56qcr9q896ffb"; + finalImageName = "nixos/nix"; + finalImageTag = "2.15.1"; + }; +in + tag: + pkgs.dockerTools.buildImage { + name = "git.vdx.hu/voidcontext/woodpecker-plugin-nix-attic"; + tag = tag; + fromImage = nixImage; + # runAsRoot = '' + # #!${pkgs.stdenv.shell} + # export PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH + # ''; + copyToRoot = pkgs.buildEnv { + name = "woodpecker-plugin-nix-attic-image-root"; + paths = [pkgs.gnumake pkgs.attic-client entrypoint]; + pathsToLink = ["/bin"]; + }; + + config.Cmd = ["/bin/woodpecker-nix-attic-entrypoint"]; + diskSize = 2048; + }