summaryrefslogtreecommitdiff
path: root/bin/init-project
blob: ec5e19c860bc89652de4989bd37dec7840a3276a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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"