Skip to content

Commit 6be39d6

Browse files
Merge branch 'main' into bjs/fish-plugins
2 parents 821d07e + 6f2097e commit 6be39d6

File tree

2 files changed

+48
-36
lines changed

2 files changed

+48
-36
lines changed
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
# CI job to periodically (once a week) update flake.lock
22
name: Update flake dependencies
3-
43
on:
54
schedule:
65
- cron: '0 16 * * 5'
76
workflow_dispatch: # for allowing manual triggers of the workflow
8-
97
jobs:
108
update-dependencies:
119
runs-on: ubuntu-latest
1210
steps:
13-
- uses: actions/checkout@v4
14-
- uses: DeterminateSystems/nix-installer-action@main
15-
- uses: DeterminateSystems/magic-nix-cache-action@main
16-
- name: Update flake.lock and create signed commit with flake.lock changes
17-
env:
18-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19-
FILE_TO_COMMIT: flake.lock
20-
COMMIT_BRANCH: automation/update-flake-dependencies
21-
COMMIT_MESSAGE: "chore(nix): Update Flake dependencies"
22-
run: |
11+
- uses: actions/checkout@v4
12+
- uses: DeterminateSystems/nix-installer-action@main
13+
- uses: DeterminateSystems/magic-nix-cache-action@main
14+
- name: Update flake.lock and create signed commit with flake.lock changes
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.OP_BOT_TOKEN }}
17+
FILE_TO_COMMIT: flake.lock
18+
COMMIT_BRANCH: automation/update-flake-dependencies
19+
COMMIT_MESSAGE: "chore(nix): Update Flake dependencies"
20+
run: |
2321
# fetch remote state
2422
git fetch
2523
# if branch exists on remote already
24+
BRANCH_EXISTS=false
2625
if git checkout "$COMMIT_BRANCH" > /dev/null 2>&1; then
2726
# pull changes
2827
git pull
28+
BRANCH_EXISTS=true
2929
else
3030
# otherwise, create the branch and push it to remote
3131
git checkout -b "$COMMIT_BRANCH"
@@ -41,10 +41,11 @@ jobs:
4141
--field content=@<(base64 -i $FILE_TO_COMMIT) \
4242
--field branch="$COMMIT_BRANCH" \
4343
--field sha="$(git rev-parse $COMMIT_BRANCH:$FILE_TO_COMMIT)"
44-
gh pr create --title "[automation]: Update Flake dependencies" \
45-
--body "This is an automated PR to update \`flake.lock\`" \
46-
--label "flake.lock automation" \
47-
--reviewer mrjones2014 \
48-
--reviewer AndyTitu \
49-
--base main --head $COMMIT_BRANCH
44+
if [ "$BRANCH_EXISTS" = "false" ]; then
45+
gh pr create --title "[automation]: Update Flake dependencies" \
46+
--body "This is an automated PR to update \`flake.lock\`" \
47+
--label "flake.lock automation" \
48+
--reviewer mrjones2014 \
49+
--base main --head $COMMIT_BRANCH
50+
fi
5051
fi

nix/shell-plugins.nix

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1-
{ pkgs, lib, config, is-home-manager, ... }:
1+
{
2+
pkgs,
3+
lib,
4+
config,
5+
is-home-manager,
6+
...
7+
}:
28
with lib;
39
let
410
cfg = config.programs._1password-shell-plugins;
511

6-
supported_plugins = splitString "\n" (lib.readFile "${
7-
# get the list of supported plugin executable names
12+
supported_plugins = splitString "\n" (
13+
lib.readFile "${
14+
# get the list of supported plugin executable names
815
pkgs.runCommand "op-plugin-list" { }
9-
# 1Password CLI tries to create the config directory automatically, so set a temp XDG_CONFIG_HOME
10-
# since we don't actually need it for this
11-
"mkdir $out && XDG_CONFIG_HOME=$out ${pkgs._1password}/bin/op plugin list | cut -d ' ' -f1 | tail -n +2 > $out/plugins.txt"
12-
}/plugins.txt");
13-
getExeName = package:
16+
# 1Password CLI tries to create the config directory automatically, so set a temp XDG_CONFIG_HOME
17+
# since we don't actually need it for this
18+
"mkdir $out && XDG_CONFIG_HOME=$out ${
19+
if cfg.package != null then cfg.package else pkgs._1password-cli
20+
}/bin/op plugin list | cut -d ' ' -f1 | tail -n +2 > $out/plugins.txt"
21+
}/plugins.txt"
22+
);
23+
getExeName =
24+
package:
1425
# NOTE: SAFETY: This is okay because the `packages` list is also referred
1526
# to below as `home.packages = packages;` or `environment.systemPackages = packages;`
1627
# depending on if it's using `home-manager` or not; this means that Nix can still
1728
# compute the dependency tree, even though we're discarding string context here,
1829
# since the packages are still referred to below without discarding string context.
1930
strings.unsafeDiscardStringContext (baseNameOf (getExe package));
20-
in {
31+
in
32+
{
2133
options = {
2234
programs._1password-shell-plugins = {
2335
enable = mkEnableOption "1Password Shell Plugins";
@@ -32,24 +44,23 @@ in {
3244
cachix
3345
]
3446
'';
35-
description =
36-
"CLI Packages to enable 1Password Shell Plugins for; ensure that a Shell Plugin exists by checking the docs: https://developer.1password.com/docs/cli/shell-plugins/";
47+
description = "CLI Packages to enable 1Password Shell Plugins for; ensure that a Shell Plugin exists by checking the docs: https://developer.1password.com/docs/cli/shell-plugins/";
3748
# this is a bit of a hack to do option validation;
3849
# ensure that the list of packages include only packages
3950
# for which the executable has a supported 1Password Shell Plugin
40-
apply = package_list:
41-
map (package:
51+
apply =
52+
package_list:
53+
map (
54+
package:
4255
if (elem (getExeName package) supported_plugins) then
4356
package
4457
else
45-
abort "${
46-
getExeName package
47-
} is not a valid 1Password Shell Plugin. A list of supported plugins can be found by running `op plugin list` or at: https://developer.1password.com/docs/cli/shell-plugins/")
48-
package_list;
58+
abort "${getExeName package} is not a valid 1Password Shell Plugin. A list of supported plugins can be found by running `op plugin list` or at: https://developer.1password.com/docs/cli/shell-plugins/"
59+
) package_list;
4960
};
5061
};
5162
};
52-
63+
5364
config = let
5465
# executable names as strings, e.g. `pkgs.gh` => `"gh"`, `pkgs.awscli2` => `"aws"`
5566
pkg-exe-names = map getExeName cfg.plugins;

0 commit comments

Comments
 (0)