diff options
author | Brian Picciano <me@mediocregopher.com> | 2024-06-08 20:47:33 +0200 |
---|---|---|
committer | Brian Picciano <me@mediocregopher.com> | 2024-06-08 20:47:33 +0200 |
commit | 0856b53afe74619a072e3753442ff05aa94291ee (patch) | |
tree | 07380aae7aa8c09a56f575fb0a04058f6886a52d /bin/init-project | |
parent | 2a52d32e0d998828e94c0137edb4500f6002da78 (diff) |
init-project script
Diffstat (limited to 'bin/init-project')
-rwxr-xr-x | bin/init-project | 48 |
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" |