From 1321374a90306f5a989c69cce97e0d074560f17a Mon Sep 17 00:00:00 2001 From: noe Date: Mon, 24 Mar 2025 23:21:33 -0700 Subject: [PATCH] vendorhash calc automation --- .gitignore | 4 +++- default.nix | 22 ++++++++++++++++++++++ flake.nix | 23 ++--------------------- roleypoly/roleypoly.go | 3 --- scripts/update-vendor-hash.sh | 10 ++++++++++ shell.nix | 29 ++--------------------------- stores/store.go | 1 + 7 files changed, 40 insertions(+), 52 deletions(-) create mode 100644 default.nix create mode 100755 scripts/update-vendor-hash.sh diff --git a/.gitignore b/.gitignore index d136290..e44b9f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .direnv -.env \ No newline at end of file +.env +.storage +result \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..a7c83ae --- /dev/null +++ b/default.nix @@ -0,0 +1,22 @@ +{ + pkgs ? import {}, + vendorHash ? "sha256-YRteL/3725Hm+fdXO+wPYX9nFNbdAHsAwCo3xuVPrwI=", +}: +rec { + default = roleypoly; + roleypoly = pkgs.buildGoModule { + inherit vendorHash; + name = "roleypoly"; + src = ./.; + }; + container = pkgs.dockerTools.buildImage { + name = "roleypoly/roleypoly"; + tag = "latest"; + copyToRoot = [ + pkgs.dockerTools.caCertificates + ]; + config = { + Cmd = [ "${roleypoly}/bin/roleypoly" ]; + }; + }; +} \ No newline at end of file diff --git a/flake.nix b/flake.nix index e73b8c0..c5ab2ca 100644 --- a/flake.nix +++ b/flake.nix @@ -8,29 +8,10 @@ outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" "aarch64-linux" ]; - perSystem = { config, self', pkgs, lib, system, ... }: rec { + perSystem = { config, self', pkgs, lib, system, ... }: { devShells.default = import ./shell.nix { inherit pkgs; }; - packages = let - vendorHash = "sha256-A5hZxo0zZ3w6qryV24PjYaKQatN2G2heyuee6QaU55M="; - in rec { - default = roleypoly; - roleypoly = pkgs.buildGoModule { - inherit vendorHash; - name = "roleypoly"; - src = ./.; - }; - container = pkgs.dockerTools.buildImage { - name = "roleypoly/roleypoly"; - tag = "latest"; - copyToRoot = [ - pkgs.dockerTools.caCertificates - ]; - config = { - Cmd = [ "${roleypoly}/bin/roleypoly" ]; - }; - }; - }; + packages = import ./default.nix { inherit pkgs; }; }; }; } \ No newline at end of file diff --git a/roleypoly/roleypoly.go b/roleypoly/roleypoly.go index ac15be5..c4a2330 100644 --- a/roleypoly/roleypoly.go +++ b/roleypoly/roleypoly.go @@ -1,7 +1,4 @@ package roleypoly -import "github.com/gofiber/fiber/v3/middleware/session" - type Roleypoly struct { - SessionStore *session.Store } diff --git a/scripts/update-vendor-hash.sh b/scripts/update-vendor-hash.sh new file mode 100755 index 0000000..827ff73 --- /dev/null +++ b/scripts/update-vendor-hash.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p nix -p coreutils -p gnused -p gawk + +set -exuo pipefail + +go mod tidy +failedbuild=$(nix build --impure --expr '(with import {}; pkgs.callPackage ./. { vendorHash = ""; }).roleypoly' 2>&1 || true) +echo "$failedbuild" +checksum=$(echo "$failedbuild" | awk '/got:.*sha256/ { print $2 }') +sed -i -e "s|vendorHash ? \".*\"|vendorHash ? \"$checksum\"|" default.nix \ No newline at end of file diff --git a/shell.nix b/shell.nix index 0cc47e0..082b5a3 100644 --- a/shell.nix +++ b/shell.nix @@ -1,33 +1,8 @@ -{ pkgs ? import {} }: let - podmanSetupScript = let - registriesConf = pkgs.writeText "registries.conf" '' - [registries.search] - registries = ['docker.io'] - [registries.block] - registries = [] - ''; - in pkgs.writeScript "podman-setup" '' - #!${pkgs.runtimeShell} - # Dont overwrite customised configuration - if ! test -f ~/.config/containers/policy.json; then - install -Dm555 ${pkgs.skopeo.src}/default-policy.json ~/.config/containers/policy.json - fi - if ! test -f ~/.config/containers/registries.conf; then - install -Dm555 ${registriesConf} ~/.config/containers/registries.conf - fi - ''; - - # Provides a fake "docker" binary mapping to podman - dockerCompat = pkgs.runCommandNoCC "docker-podman-compat" {} '' - mkdir -p $out/bin - ln -s ${pkgs.podman}/bin/podman $out/bin/docker - ''; -in pkgs.mkShell { +{ pkgs ? import {} }: pkgs.mkShell { buildInputs = with pkgs; [ go just - docker-compose - sqlite nil + nix-prefetch ]; } diff --git a/stores/store.go b/stores/store.go index e69de29..8209f73 100644 --- a/stores/store.go +++ b/stores/store.go @@ -0,0 +1 @@ +package stores