Skip to content

Commit e0e0986

Browse files
committed
initial commit
1 parent 0ec29f0 commit e0e0986

File tree

11 files changed

+386
-2
lines changed

11 files changed

+386
-2
lines changed

.envrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export DIRENV_WARN_TIMEOUT=2m
2+
use flake

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
update-hashes
2+
pd
3+
result
4+
/.pre-commit-config.yaml
5+
/.direnv

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
1-
# pipedream-cli
2-
Nix flake with the Pipedream CLI
1+
# Pipedream CLI
2+
3+
This is a Nix flake for the [Pipedream CLI](https://pipedream.com/docs/cli/install).
4+
5+
## Development
6+
7+
### Update the hashes
8+
9+
1. Update the version in `config.nix`
10+
1. Run:
11+
12+
```sh
13+
nix-build generate-update-script.nix -o update-hashes && ./update-hashes/bin/update-hashes
14+
```
15+
16+
### Direnv
17+
18+
This repo is [direnv](https://direnv.net/)-enabled. If you have Nix and direnv
19+
on your system, you can ignore any `nix develop --command` prefixes and just
20+
work in the folder as if you were inside the nix flake environment. This is the
21+
recommended way, as it greatly simplifies the handling of dev tasks and
22+
pre-commit checks.
23+
24+
### Pre commit hooks
25+
26+
Pre-commit hooks are managed by Nix. Once you run your commit, it will analyze
27+
the changes and run required hooks.

config.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
# Get new version via:
3+
# curl https://cli.pipedream.com/LATEST_VERSION 2>/dev/null
4+
version = "0.3.3";
5+
# Supported systems can be found here:
6+
# https://cli.pipedream.com/install
7+
supportedSystems = [
8+
"x86_64-linux"
9+
"i686-linux"
10+
"aarch64-linux"
11+
"armv7l-linux"
12+
"x86_64-darwin"
13+
"aarch64-darwin"
14+
];
15+
}

cpuOsToGoArch.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ lib }:
2+
3+
let
4+
cpuOsToGoArch = {
5+
"x86_64-linux" = "linux/amd64";
6+
"i686-linux" = "linux/386";
7+
"aarch64-linux" = "linux/amd64";
8+
"armv7l-linux" = "linux/arm";
9+
"x86_64-darwin" = "darwin/amd64";
10+
"aarch64-darwin" = "darwin/amd64";
11+
"x86_64-windows" = "windows/amd64";
12+
"i686-windows" = "windows/386";
13+
"x86_64-freebsd" = "freebsd/amd64";
14+
"aarch64-freebsd" = "freebsd/amd64";
15+
"x86_64-openbsd" = "openbsd/amd64";
16+
"aarch64-openbsd" = "openbsd/amd64";
17+
};
18+
in
19+
{ cpuOs }:
20+
let goArch = lib.getAttrFromPath [ cpuOs ] cpuOsToGoArch;
21+
in if goArch == null then
22+
throw "Unsupported CPU-OS string: ${cpuOs}"
23+
else
24+
goArch

flake.lock

Lines changed: 163 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
description = "Pipedream CLI utility";
3+
4+
inputs = {
5+
flake-parts.url = "github:hercules-ci/flake-parts";
6+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
7+
hashes = {
8+
url = "path:./hashes.nix";
9+
flake = false;
10+
};
11+
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
12+
};
13+
14+
outputs = inputs@{ flake-parts, nixpkgs, hashes, ... }:
15+
let
16+
version = "0.3.3";
17+
systems = builtins.attrNames hashes;
18+
lib = inputs.nixpkgs.lib;
19+
getUrl = import ./url.nix { inherit lib; };
20+
hashes = import inputs.hashes;
21+
in
22+
flake-parts.lib.mkFlake { inherit inputs; } {
23+
24+
imports = [ ];
25+
26+
systems = systems;
27+
28+
perSystem = { config, self', inputs', pkgs, system, ... }: rec {
29+
packages.default = pkgs.stdenv.mkDerivation {
30+
pname = "pd";
31+
version = version;
32+
# Not using fetchzip due to https://github.com/NixOS/nixpkgs/issues/111508
33+
src = pkgs.fetchurl {
34+
35+
url = getUrl {
36+
cpuOs = system;
37+
version = version;
38+
};
39+
sha256 = lib.getAttrFromPath [ system ] hashes;
40+
};
41+
nativeBuildInputs = with pkgs; [ unzip ];
42+
43+
# Work around the "unpacker appears to have produced no directories"
44+
# case that happens when the archive doesn't have a subdirectory.
45+
sourceRoot = ".";
46+
47+
installPhase = ''
48+
mkdir -p $out/bin
49+
cp -r * $out/bin
50+
'';
51+
};
52+
53+
checks = {
54+
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
55+
src = ./.;
56+
hooks = {
57+
nixpkgs-fmt.enable = true;
58+
markdownlint.enable = true;
59+
};
60+
};
61+
};
62+
devShells.default = pkgs.mkShell {
63+
inherit (checks.pre-commit-check) shellHook;
64+
buildInputs = [ packages.default ] ++ checks.pre-commit-check.enabledPackages;
65+
};
66+
};
67+
68+
flake = {
69+
# The usual flake attributes can be defined here, including system-
70+
# agnostic ones like nixosModule and system-enumerating ones, although
71+
# those are more easily expressed in perSystem.
72+
};
73+
};
74+
}

generate-update-script.nix

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{ pkgs ? import <nixpkgs> { } }:
2+
3+
let
4+
config = import ./config.nix;
5+
version = config.version;
6+
7+
systems = config.supportedSystems;
8+
lib = pkgs.lib;
9+
getUrl = import ./url.nix { inherit lib; };
10+
11+
urls = map
12+
(system:
13+
let
14+
url = getUrl {
15+
cpuOs = system;
16+
version = version;
17+
};
18+
in
19+
{
20+
system = system;
21+
url = url;
22+
})
23+
systems;
24+
25+
fetchCommands = pkgs.lib.concatMapStringsSep "\n"
26+
(entry: ''
27+
echo "Prefetching ${entry.system}..."
28+
hash=$(nix-prefetch-url ${entry.url})
29+
echo " \"${entry.system}\" = \"$hash\";" >> $HASHES_FILE
30+
'')
31+
urls;
32+
in
33+
pkgs.writeScriptBin "update-hashes" ''
34+
#!/usr/bin/env bash
35+
36+
set -euo pipefail
37+
38+
HASHES_FILE="hashes.nix"
39+
40+
cat <<EOF > $HASHES_FILE
41+
{
42+
EOF
43+
44+
${fetchCommands}
45+
46+
cat <<EOF >> $HASHES_FILE
47+
}
48+
EOF
49+
''

hashes.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"x86_64-linux" = "09c5f0wz263wxkzv0s4cmwpvvxwpvk7kvsjn3z1nargn1g8jangq";
3+
"i686-linux" = "1mv9pgcf1ksd6szl51fd5dg1h4x5j0wm9ia1jxf9wmab4lw86idp";
4+
"aarch64-linux" = "09c5f0wz263wxkzv0s4cmwpvvxwpvk7kvsjn3z1nargn1g8jangq";
5+
"armv7l-linux" = "1cahrl3xxcymrnz5vhqb5l19rycpfviksxr38kjwip7w64i0zjp4";
6+
"x86_64-darwin" = "0fdcb9dgmpyk5q6ggwc02s9lrns6qmax1vlvaw6xkp7adp7lixfb";
7+
"aarch64-darwin" = "0fdcb9dgmpyk5q6ggwc02s9lrns6qmax1vlvaw6xkp7adp7lixfb";
8+
}

shell.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ pkgs ? import <nixpkgs> { } }:
2+
3+
pkgs.mkShell {
4+
buildInputs = [ pkgs.pd ];
5+
6+
shellHook = ''
7+
echo "To install the binary, run: nix build
8+
'';
9+
}

0 commit comments

Comments
 (0)