{ description = "Bob: The HTML and HTML fragment builder"; # Nixpkgs / NixOS version to use. inputs.nixpkgs.url = "nixpkgs/nixos-23.05"; outputs = { self, nixpkgs }: let # to work with older version of flakes lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; rootPath = ./.; # System types to support. supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. forAllSystems = nixpkgs.lib.genAttrs supportedSystems; # Nixpkgs instantiated for supported system types. nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); in { # Provide some binary packages for selected system types. packages = forAllSystems (system: let pkgs = nixpkgsFor.${system}; projectDefinition = import ./project.nix; projectHash = if (self ? shortRev) then self.shortRev else "dirty"; lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; sourcePath = ././source; in { bob = pkgs.buildGoModule { pname = projectDefinition.name; version = projectDefinition.version; # In 'nix develop', we don't need a copy of the source tree # in the Nix store. src = sourcePath; tags = []; # add your tags here (eq "netgo" "osusergo" "static_build") ldflags = [ "-X '${projectDefinition.modulePath}/internal/release.version=${projectDefinition.version}'" "-X '${projectDefinition.modulePath}/internal/release.commit=${projectHash}'" "-X '${projectDefinition.modulePath}/internal/release.name=${projectDefinition.name}'" "-X '${projectDefinition.modulePath}/internal/release.mnemonic=${projectDefinition.mnemonic}'" "-X '${projectDefinition.modulePath}/internal/release.buildDate=${lastModifiedDate}'" ]; vendorHash = projectDefinition.vendorHash; proxyVendor = true; meta = with system.lib; { description = projectDefinition.description; homepage = "https://" + projectDefinition.modulePath; license = licenses.mit; maintainers = with maintainers; ["schukai GmbH"]; }; buildInputs = [pkgs.bash]; nativeBuildInputs = with system; [pkgs.alejandra pkgs.shellcheck pkgs.shfmt]; doCheck = true; checkPhase = '' cd ${sourcePath} if ! go test -v ./... 2>&1 | cat ; then echo "Test failed." exit 1 fi echo "Test passed: '$out' is as expected." ''; }; }); # Add dependencies that are only needed for development devShells = forAllSystems (system: let pkgs = nixpkgsFor.${system}; in { default = pkgs.mkShell { buildInputs = with pkgs; [ go gopls gotools go-tools ]; }; }); # The default package for 'nix build'. This makes sense if the # flake provides only one package or there is a clear "main" # package. defaultPackage = forAllSystems (system: self.packages.${system}.bob); }; }