diff --git a/flake.nix b/flake.nix index fcd77300..19616249 100644 --- a/flake.nix +++ b/flake.nix @@ -3,10 +3,54 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils = { url = "github:numtide/flake-utils"; }; }; - outputs = { nixpkgs, flake-utils, ... }: + + outputs = inputs@{ self, nixpkgs, flake-utils, ... }: (flake-utils.lib.eachDefaultSystem (system: - let pkgs = nixpkgs.legacyPackages.${system}; - in { + let + pkgs = import nixpkgs { + inherit system; + config = { + # Ensure that the op CLI command can be used in this flake without getting warnings about it being unfree + allowUnfreePredicate = pkg: + builtins.elem (nixpkgs.lib.getName pkg) [ + "1password-cli" + ]; + }; + }; + in + { + apps.make-supported-plugins = { + type = "app"; + program = "${self.packages.${system}.make-supported-plugins}/bin/make-supported-plugins"; + meta = { + description = "Generate a Nix expression containing an array of plugins that are currently supported by 1Password."; + }; + }; + + packages.make-supported-plugins = pkgs.writeShellApplication { + name = "make-supported-plugins"; + runtimeInputs = [ + pkgs.git + pkgs._1password + ]; + text = '' + + # Get the flake's directory so the command can be run in subdirectories reproducibly + PROJECT_ROOT=$(git rev-parse --show-toplevel) + + # Get the supported plugins separated by line breaks + SUPPORTED_PLUGINS=$(op plugin list | cut -d ' ' -f1 | tail -n +2) + + if [ -z "$SUPPORTED_PLUGINS" ]; then + echo "Error: No plugins found when calling 'op plugin list' command." >&2 + exit 1 + fi + + echo "# This file was automatically generated using 'nix run .#make-supported-plugins'" > "$PROJECT_ROOT/nix/supported-plugins.nix" + echo "$SUPPORTED_PLUGINS" | awk 'BEGIN { print "[" } {print " \""$0"\""} END { print "]" }' >> "$PROJECT_ROOT/nix/supported-plugins.nix" + ''; + }; + devShells.default = pkgs.mkShell { name = "Shell with Go toolchain"; packages = with pkgs; [ go gopls ]; diff --git a/nix/shell-plugins.nix b/nix/shell-plugins.nix index 907bf2f5..cf8acfef 100644 --- a/nix/shell-plugins.nix +++ b/nix/shell-plugins.nix @@ -2,14 +2,7 @@ with lib; let cfg = config.programs._1password-shell-plugins; - - supported_plugins = splitString "\n" (lib.readFile "${ - # get the list of supported plugin executable names - pkgs.runCommand "op-plugin-list" { } - # 1Password CLI tries to create the config directory automatically, so set a temp XDG_CONFIG_HOME - # since we don't actually need it for this - "mkdir $out && XDG_CONFIG_HOME=$out ${pkgs._1password}/bin/op plugin list | cut -d ' ' -f1 | tail -n +2 > $out/plugins.txt" - }/plugins.txt"); + supported_plugins = import ./supported-plugins.nix; getExeName = package: # NOTE: SAFETY: This is okay because the `packages` list is also referred # to below as `home.packages = packages;` or `environment.systemPackages = packages;` diff --git a/nix/supported-plugins.nix b/nix/supported-plugins.nix new file mode 100644 index 00000000..194f6007 --- /dev/null +++ b/nix/supported-plugins.nix @@ -0,0 +1,68 @@ +# This file was automatically generated using 'nix run .#make-supported-plugins' +[ + "akamai" + "argocd" + "aws" + "cdk" + "axiom" + "binance-cli" + "cachix" + "cargo" + "circleci" + "civo" + "wrangler" + "crowdin" + "databricks" + "dog" + "doctl" + "fastly" + "flyctl" + "fly" + "fossa" + "tea" + "gh" + "glab" + "vault" + "heroku" + "hcloud" + "brew" + "huggingface-cli" + "influx" + "kaggle" + "lacework" + "forge" + "vapor" + "linode-cli" + "localstack" + "atlas" + "mysql" + "ngrok" + "ohdear" + "okta" + "openai" + "oaieval" + "oaievalset" + "pd" + "psql" + "pg_dump" + "pg_restore" + "pgcli" + "pulumi" + "rdme" + "sentry-cli" + "snowsql" + "snyk" + "src" + "stripe" + "todoist" + "td" + "tugboat" + "twilio" + "upstash" + "vercel" + "vsql" + "vultr-cli" + "ysqlsh" + "zapier" + "zcli" +]