Skip to content

Commit

Permalink
add print all images script
Browse files Browse the repository at this point in the history
  • Loading branch information
cottand committed Aug 9, 2024
1 parent 821c3bc commit b3ff91e
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 98 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
REGISTRY_IMAGE: "ghcr.io/cottand/selfhosted"

jobs:
generate-ci:
build-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -23,13 +23,11 @@ jobs:

- uses: DeterminateSystems/magic-nix-cache-action@main

- name: codegen CI
- name: Build images
run: |
nix build .#gh-ci -L
cp result .github/workflows/gh-ci-generated.yml
nix build -L .#scripts.allImages
run-generated:
needs: [ generate-ci ]
uses: ./.github/workflows/gh-ci-generated.yml
- name: Push images
run: |
nix run .#scripts.allImages | while read -r line; do echo "$line"; done
34 changes: 8 additions & 26 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
newVault = final: prev: {
vault-bin = (import nixpkgs-master { system = prev.system; config.allowUnfree = true; }).vault-bin;
};
overlays = [ (import ./overlay.nix) newVault attic.overlays.default ];
withScripts = final: prev: {
scripts = self.legacyPackages.${prev.system}.scripts;
};
overlays = [ (import ./overlay.nix) withScripts newVault attic.overlays.default ];
in
{
colmena = (import ./hive.nix) (inputs // { inherit overlays; });
Expand All @@ -39,33 +42,12 @@
config.allowUnfree = true;
};
in
{
# templates a nomad nix file into JSON and calls nomad run on it
# usage: nixmad path/to/job.nix
packages.nixmad = pkgs.writeShellScriptBin "nixmad" ''
set -e
${pkgs.nix}/bin/nix eval -f $1 --json --show-trace | ${pkgs.nomad}/bin/nomad run -json -
'';
rec {

# fetches a secret from bitwarden-secret by ID
# usage: bws-get <ID>
packages.bws-get = pkgs.writeShellScriptBin "bws-get" ''
set -e
${pkgs.bws}/bin/bws secret get $1 | ${pkgs.jq}/bin/jq -r '.value'
'';

# returns a secret from the MacOS keychain fromatted as JSON for use in TF
# usage: keychain-get <SERVICE>
# returns {"value": "<SECRET>"}
packages.keychain-get = pkgs.writeShellScriptBin "keychain-get" ''
set -e
SECRET=$(/usr/bin/security find-generic-password -gw -l "$1")
${pkgs.jq}/bin/jq -n --arg value "$SECRET" '{ "value": $value }'
'';
legacyPackages.services = (import ./services) pkgs;
legacyPackages.scripts = (import ./scripts) (pkgs // {inherit self; });

# legacyPackages.images = (import ./images { inherit pkgs; });
legacyPackages.services = pkgs.callPackage (import ./services) {};
legacyPackages.gh-ci = pkgs.callPackage (import ./gh-ci.nix) { inherit self; };
packages = legacyPackages.scripts;

devShells.default = pkgs.mkShell {
name = "selfhosted-dev";
Expand Down
21 changes: 0 additions & 21 deletions gh-ci.nix

This file was deleted.

9 changes: 9 additions & 0 deletions scripts/allImages/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ self, writeShellScriptBin, writeText, lib, ... }:
let
services = self.legacyPackages.aarch64-darwin.services;
images = with builtins; lib.strings.concatMapStrings (svc: "${svc.image.out}\n") (attrValues services);
in
writeShellScriptBin "printAllImages" ''
set -e
cat ${writeText "images" images}
''
1 change: 1 addition & 0 deletions scripts/buildAllImages/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ self, scripts, writeShellScriptBin, ...}let in: (scripts.buildYaegiScript "buildAllImages" ./script.go)
5 changes: 5 additions & 0 deletions scripts/buildAllImages/script.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {
print("hello world from yaegi!")
}
23 changes: 0 additions & 23 deletions scripts/cleanup_dead_services.sh

This file was deleted.

36 changes: 36 additions & 0 deletions scripts/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ self, callPackage, nomad, jq, nix, bws, writeShellScriptBin, writeScriptBin, yaegi, ...}: rec {

# buildAllImages = callPackage (import ./buildAllImages) {};

buildYaegiScript = name: filePath: writeScriptBin name ''
#! ${yaegi}/bin/yaegi
${builtins.readFile filePath}
'';

buildAllImages = callPackage (import ./buildAllImages) {};

# templates a nomad nix file into JSON and calls nomad run on it
# usage: nixmad path/to/job.nix
nixmad = writeShellScriptBin "nixmad" ''
set -e
${nix}/bin/nix eval -f $1 --json --show-trace | ${nomad}/bin/nomad run -json -
'';

# fetches a secret from bitwarden-secret by ID
# usage: bws-get <ID>
bws-get = writeShellScriptBin "bws-get" ''
set -e
${bws}/bin/bws secret get $1 | ${jq}/bin/jq -r '.value'
'';

# returns a secret from the MacOS keychain fromatted as JSON for use in TF
# usage: keychain-get <SERVICE>
# returns {"value": "<SECRET>"}
keychain-get = writeShellScriptBin "keychain-get" ''
set -e
SECRET=$(/usr/bin/security find-generic-password -gw -l "$1")
${jq}/bin/jq -n --arg value "$SECRET" '{ "value": $value }'
'';

allImages = callPackage (import ./allImages) { inherit self; };
}
17 changes: 0 additions & 17 deletions scripts/generate_wgmesh.sh

This file was deleted.

4 changes: 1 addition & 3 deletions services/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{ callPackage, ... }: {
name = "services";

{ callPackage, writeText, ... }: {
portfolioStats = callPackage (import ./portfolioStats) { };
}

0 comments on commit b3ff91e

Please sign in to comment.