-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
184 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: nixidy action | ||
description: Generate manifest for a nixidy environment | ||
|
||
inputs: | ||
environment: | ||
description: Name of the environment to build | ||
required: true | ||
cwd: | ||
description: Path to directory containing the checked out repository | ||
default: '.' | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- shell: bash | ||
env: | ||
FLAKE: github:${{github.action_repository}}/${{github.action_ref}} | ||
DEST_DIR: ${{runner.temp}}/${{inputs.environment}} | ||
run: | | ||
TARGET_BRANCH=$(nix run '${{env.FLAKE}}#' -- info '${{inputs.cwd}}#${{inputs.environment}}' --json | jq -r .branch) | ||
if git -C "${{inputs.cwd}}" fetch origin "$TARGET_BRANCH"; then | ||
git -C "${{inputs.cwd}}" worktree add --checkout "${{env.DEST_DIR}}" "$TARGET_BRANCH" | ||
else | ||
git -C "${{inputs.cwd}}" worktree add --orphan -b "$TARGET_BRANCH" "${{env.DEST_DIR}}" | ||
fi | ||
RESULT=$(nix run '${{env.FLAKE}}#' -- build '${{inputs.cwd}}#${{inputs.environment}}' --print-out-paths --no-link) | ||
rsync --recursive --delete --exclude=.git -L "$RESULT/" "${{env.DEST_DIR}}" | ||
echo "BRANCH=$TARGET_BRANCH" >> "$GITHUB_ENV" | ||
- uses: EndBug/add-and-commit@v9 | ||
with: | ||
cwd: ${{inputs.cwd}} | ||
default_author: github_actions | ||
message: "chore(${{inputs.environment}}): promote to ${{inputs.environment}} ${{github.sha}}" | ||
fetch: false | ||
push: --set-upstream origin ${{env.BRANCH}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
{ | ||
lib, | ||
config, | ||
pkgs, | ||
... | ||
}: let | ||
envName = lib.replaceStrings ["/"] ["-"] config.nixidy.target.branch; | ||
|
||
apps = | ||
lib.mapAttrs ( | ||
n: v: { | ||
name = n; | ||
path = v.output.path; | ||
resources = lib.flatten ( | ||
lib.mapAttrsToList ( | ||
group: groupData: | ||
lib.mapAttrsToList ( | ||
kind: kindData: | ||
lib.mapAttrsToList ( | ||
res: resData: | ||
resData | ||
// { | ||
apiVersion = group; | ||
kind = kind; | ||
metadata = {name = res;} // (resData.metadata or {}); | ||
} | ||
) | ||
kindData | ||
) | ||
groupData | ||
) | ||
v.resources | ||
); | ||
} | ||
) | ||
config.applications; | ||
|
||
mkApp = app: let | ||
resources = | ||
map ( | ||
res: rec { | ||
filename = "${res.kind}-${builtins.replaceStrings ["."] ["-"] res.metadata.name}.yaml"; | ||
manifest = let | ||
resource = builtins.toJSON res; | ||
in | ||
pkgs.stdenv.mkDerivation { | ||
inherit resource; | ||
|
||
name = "nixidy-app-${app.name}-${filename}"; | ||
|
||
passAsFile = ["resource"]; | ||
|
||
phases = ["installPhase"]; | ||
|
||
installPhase = '' | ||
cat $resourcePath | ${pkgs.yq-go}/bin/yq -P > $out | ||
''; | ||
}; | ||
} | ||
) | ||
app.resources; | ||
in | ||
pkgs.stdenv.mkDerivation { | ||
name = "nixidy-app-${app.name}"; | ||
|
||
phases = ["installPhase"]; | ||
|
||
installPhase = | ||
'' | ||
mkdir -p $out | ||
'' | ||
+ (lib.concatStringsSep "\n" (map (res: '' | ||
ln -s ${res.manifest} $out/${res.filename} | ||
'') | ||
resources)); | ||
}; | ||
in { | ||
options = with lib; { | ||
nixidy.extrasPackage = mkOption { | ||
type = types.package; | ||
internal = true; | ||
description = "The package containing all the extra files for an environment."; | ||
}; | ||
|
||
nixidy.environmentPackage = mkOption { | ||
type = types.package; | ||
internal = true; | ||
description = "The package containing all the applications for an environment."; | ||
}; | ||
}; | ||
|
||
config = { | ||
# Build all extra files into its own package | ||
nixidy.extrasPackage = pkgs.stdenv.mkDerivation { | ||
name = "nixidy-extras-${envName}"; | ||
|
||
phases = ["installPhase"]; | ||
|
||
installPhase = | ||
'' | ||
mkdir -p $out | ||
'' | ||
+ (lib.concatStringsSep "\n" (lib.mapAttrsToList (_: file: '' | ||
mkdir -p $out/$(dirname ${file.path}) | ||
cat <<EOF > "$out/${file.path}" | ||
${file.text} | ||
EOF | ||
'') | ||
config.nixidy.extraFiles)); | ||
}; | ||
|
||
# Build final environment into a package | ||
nixidy.environmentPackage = let | ||
joined = pkgs.linkFarm "nixidy-apps-joined-${envName}" (lib.mapAttrsToList (_: app: { | ||
name = app.path; | ||
path = mkApp app; | ||
}) | ||
apps); | ||
in | ||
pkgs.symlinkJoin { | ||
name = "nixidy-environment-${envName}"; | ||
paths = [ | ||
joined | ||
config.nixidy.extrasPackage | ||
]; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[ | ||
./applications.nix | ||
./nixidy.nix | ||
./environment.nix | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters