Created
November 29, 2025 17:51
-
-
Save abdivasiyev/792939fc4d961b4ad049e7ebb8d8bcf8 to your computer and use it in GitHub Desktop.
Setup development environment for Go compiler development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| description = "Go compiler development environment"; | |
| nixConfig = { | |
| allow-import-from-derivation = true; | |
| }; | |
| inputs = { | |
| nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | |
| flake-utils.url = "github:numtide/flake-utils"; | |
| }; | |
| outputs = { | |
| self, | |
| nixpkgs, | |
| flake-utils, | |
| ... | |
| } @ inputs: | |
| flake-utils.lib.eachDefaultSystem ( | |
| system: let | |
| # pkgs = import nixpkgs {localSystem = {inherit system;};}; | |
| pkgs = nixpkgs.legacyPackages.${system}; | |
| go_dev = pkgs.callPackage ./package.nix {inherit pkgs inputs;}; | |
| in { | |
| packages.default = go_dev; | |
| devShells.default = pkgs.callPackage ./shell.nix {inherit pkgs go_dev;}; | |
| } | |
| ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| pkgs ? let | |
| lock = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.nixpkgs.locked; | |
| nixpkgs = fetchTarball { | |
| url = "https://github.com/nixos/nixpkgs/archive/${lock.rev}.tar.gz"; | |
| sha256 = lock.narHash; | |
| }; | |
| in | |
| import nixpkgs {overlays = [];}, | |
| ... | |
| }: | |
| pkgs.stdenv.mkDerivation { | |
| pname = "go"; | |
| src = ./go; | |
| version = "1.26"; | |
| env = { | |
| GOROOT = "${pkgs.go_1_25}"; | |
| }; | |
| nativeBuildInputs = [ | |
| pkgs.git | |
| pkgs.darwin.sigtool | |
| pkgs.go_1_25 | |
| ]; | |
| buildPhase = '' | |
| export GOCACHE=$TMPDIR/go-cache | |
| cd src/ | |
| bash make.bash | |
| cd .. | |
| mkdir -p $out/share/go | |
| cp -a bin pkg src lib misc api doc go.env $out/share/go | |
| cp VERSION.cache $out/share/go/VERSION | |
| # Create symlinks for go and gofmt binaries | |
| mkdir -p $out/bin | |
| ln -s $out/share/go/bin/* $out/bin | |
| ''; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| pkgs ? let | |
| lock = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.nixpkgs.locked; | |
| nixpkgs = fetchTarball { | |
| url = "https://github.com/nixos/nixpkgs/archive/${lock.rev}.tar.gz"; | |
| sha256 = lock.narHash; | |
| }; | |
| in | |
| import nixpkgs {overlays = [];}, | |
| go_dev, | |
| ... | |
| }: | |
| pkgs.stdenv.mkDerivation { | |
| name = "go-dev-env"; | |
| src = ./go; | |
| # Build time dependencies | |
| nativeBuildInputs = [ | |
| ]; | |
| # Runtime dependencies | |
| buildInputs = [ | |
| go_dev | |
| ]; | |
| # Things to run before entering devShell | |
| shellHook = '' | |
| export PATH=$PATH:${go_dev}/bin | |
| ${go_dev}/bin/go version | |
| ''; | |
| # Environmental variables | |
| NIX_CONFIG = "extra-experimental-features = nix-command flakes"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment