This document provides instructions for building and installing gnparser
using Nix package manager.
- Nix Files
- Prerequisites
- Building Methods
- Development Shell
- Build Configuration
- Updating vendorHash
- Troubleshooting
- Using in NixOS Configuration
The repository contains the following Nix-related files:
default.nix- Main build derivation using buildGoModuleflake.nix- Nix flakes configuration for modern Nix workflowsshell.nix- Development shell with Go and gopls
- Nix package manager installed (see https://nixos.org/download.html)
- For flake-based builds: Nix 2.4+ with flakes enabled
Make sure that version, date and vendorHash in default.nix
are updated for a successful build.
The simplest way to get the vendorHash is to run build and copy corrected hash from the error message.
gnparser supports both traditional Nix and modern Nix Flakes build methods.
nix buildThis will create a result symlink in the current directory pointing to the
build output.
nix runnix profile installOr install from a specific flake reference:
nix profile install github:gnames/gnparsernix-buildThis will create a result symlink pointing to the built package.
nix-env -f default.nix -i./result/bin/gnparserEnter a development environment with Go and necessary tools:
nix developnix-shellThis provides:
- Go compiler
- gopls (Go language server)
The build is configured in default.nix with the following features:
- Static binary: Built with
-linkmode external -extldflags -static - Version stamping: Version and build date are embedded at build time
- Vendor dependencies: Go dependencies are managed with a fixed
vendorHash - Optimized: Stripped symbols (
-s -w) for smaller binary size
- x86_64-linux
- aarch64-linux
- x86_64-darwin
- aarch64-darwin
If Go dependencies change, you may need to update the vendorHash in default.nix:
- Set
vendorHash = lib.fakeHash;indefault.nix - Run
nix build(ornix-build) - Copy the correct hash from the error message
- Update
vendorHashwith the correct value
If you get an error about flakes not being recognized, enable them:
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.confOr use the flag directly:
nix --experimental-features 'nix-command flakes' buildIf you encounter vendorHash mismatch errors, follow the "Updating vendorHash" section above.
You can add gnparser to your NixOS configuration:
{
environment.systemPackages = [
(pkgs.callPackage /path/to/gnparser/default.nix {})
];
}Or with flakes in your flake.nix:
{
inputs.gnparser.url = "github:gnames/gnparser";
outputs = { self, nixpkgs, gnparser }: {
nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
modules = [
{
environment.systemPackages = [ gnparser.packages.x86_64-linux.default ];
}
];
};
};
}