summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/init-project48
1 files changed, 48 insertions, 0 deletions
diff --git a/bin/init-project b/bin/init-project
new file mode 100755
index 0000000..ec5e19c
--- /dev/null
+++ b/bin/init-project
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+
+if [ -f "default.nix" ]; then
+ echo "default.nix already exists in this directory"
+ #exit 1
+fi
+
+git init -b main .
+
+nixpkgsURL="https://github.com/NixOS/nixpkgs"
+
+echo "Fetching tags from $nixpkgsURL..."
+
+line=$(git ls-remote --tags "$nixpkgsURL" | \
+ grep -P 'refs/tags/[0-9]{2}\.[0-9]{2}$' | \
+ sort -k2 | \
+ tail -n1)
+echo "$line"
+
+commit="$(echo "$line" | awk '{print $1}')"
+version="$(echo "$line" | awk '{print $2}' | cut -d/ -f3)"
+archiveURL="$nixpkgsURL/archive/$commit.tar.gz"
+
+echo "prefetching $archiveURL..."
+sha256="$(nix-prefetch-url --type sha256 --unpack "$archiveURL")"
+
+cat >default.nix <<EOF
+{
+ pkgsSrc ? builtins.fetchTarball {
+ name = "nixpkgs-$version";
+ url = "$archiveURL";
+ sha256 = "sha256:$sha256";
+ },
+}: let
+ pkgs = (import pkgsSrc) {};
+in {
+ shell = pkgs.mkShell {
+ name = "project-shell";
+ buildInputs = [
+ #pkgs.go
+ #pkgs.golangci-lint
+ ];
+ };
+}
+EOF
+
+git add --all
+git commit -m "Initial commit"