|
| 1 | +{ |
| 2 | + description = "Bifrost's Nix Flake"; |
| 3 | + |
| 4 | + # Flake inputs |
| 5 | + inputs = { |
| 6 | + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; |
| 7 | + }; |
| 8 | + |
| 9 | + # Flake outputs |
| 10 | + outputs = {self, ...} @ inputs: let |
| 11 | + # The systems supported for this flake's outputs |
| 12 | + supportedSystems = [ |
| 13 | + "x86_64-linux" # 64-bit Intel/AMD Linux |
| 14 | + "aarch64-linux" # 64-bit ARM Linux |
| 15 | + "aarch64-darwin" # 64-bit ARM macOS |
| 16 | + ]; |
| 17 | + |
| 18 | + # Helper for providing system-specific attributes |
| 19 | + forEachSupportedSystem = f: |
| 20 | + inputs.nixpkgs.lib.genAttrs supportedSystems ( |
| 21 | + system: |
| 22 | + f { |
| 23 | + inherit system; |
| 24 | + # Provides a system-specific, configured Nixpkgs |
| 25 | + pkgs = import inputs.nixpkgs { |
| 26 | + inherit system; |
| 27 | + # Enable using unfree packages |
| 28 | + config.allowUnfree = true; |
| 29 | + }; |
| 30 | + } |
| 31 | + ); |
| 32 | + in { |
| 33 | + # To activate the default environment: |
| 34 | + # nix develop |
| 35 | + # Or if you use direnv: |
| 36 | + # direnv allow |
| 37 | + devShells = forEachSupportedSystem ( |
| 38 | + { |
| 39 | + pkgs, |
| 40 | + system, |
| 41 | + }: { |
| 42 | + # Run `nix develop` to activate this environment or `direnv allow` if you have direnv installed |
| 43 | + default = pkgs.mkShellNoCC { |
| 44 | + # The name of the environment |
| 45 | + name = "bifrost-nix-dev-shell"; |
| 46 | + |
| 47 | + # The Nix packages provided in the environment |
| 48 | + packages = with pkgs; [ |
| 49 | + go |
| 50 | + nodejs_24 |
| 51 | + ]; |
| 52 | + |
| 53 | + # Set any environment variables for your development environment |
| 54 | + env = {}; |
| 55 | + |
| 56 | + # Add any shell logic you want executed when the environment is activated |
| 57 | + shellHook = '' |
| 58 | + ## |
| 59 | + ## Go: project-local GOPATH/GOBIN |
| 60 | + ## |
| 61 | + export GOPATH="$PWD/.nix-store/go" |
| 62 | + export GOBIN="$GOPATH/bin" |
| 63 | + export GOMODCACHE="$GOPATH/pkg/mod" |
| 64 | + export GOCACHE="$PWD/.nix-store/gocache" |
| 65 | +
|
| 66 | + mkdir -p "$GOBIN" "$GOMODCACHE" "$GOCACHE" |
| 67 | +
|
| 68 | + export PATH="$PATH:$GOBIN" |
| 69 | +
|
| 70 | + # Install gopls into this project's Go bin if missing |
| 71 | + if ! command -v gopls >/dev/null 2>&1; then |
| 72 | + go install golang.org/x/tools/gopls@latest |
| 73 | + fi |
| 74 | + # Install air into this project's Go bin if missing |
| 75 | + if ! command -v air >/dev/null 2>&1; then |
| 76 | + go install github.com/air-verse/air@latest |
| 77 | + fi |
| 78 | + # Install dlv into this project's Go bin if missing |
| 79 | + if ! command -v dlv >/dev/null 2>&1; then |
| 80 | + go install github.com/go-delve/delve/cmd/dlv@latest |
| 81 | + fi |
| 82 | + # Install staticcheck into this project's Go bin if missing |
| 83 | + if ! command -v staticcheck >/dev/null 2>&1; then |
| 84 | + go install honnef.co/go/tools/cmd/staticcheck@latest |
| 85 | + fi |
| 86 | +
|
| 87 | + ## |
| 88 | + ## Node: project-local "global" npm prefix |
| 89 | + ## |
| 90 | + # npm reads npm_config_prefix (or NPM_CONFIG_PREFIX) as the "prefix" config, |
| 91 | + # which is where `npm i -g` installs to. |
| 92 | + export npm_config_prefix="$PWD/.nix-store/npm-global" |
| 93 | +
|
| 94 | + mkdir -p "$npm_config_prefix/bin" |
| 95 | +
|
| 96 | + # Ensure "global" npm bin is on PATH for this shell only |
| 97 | + export PATH="$PATH:$npm_config_prefix/bin" |
| 98 | + ''; |
| 99 | + }; |
| 100 | + } |
| 101 | + ); |
| 102 | + }; |
| 103 | +} |
0 commit comments