github.com/benchkram/bob@v0.0.0-20240314204020-b7a57f2f9be9/flake.nix (about) 1 { 2 description = "A build system for microservices"; 3 inputs.nixpkgs.url = "nixpkgs/nixos-22.05"; 4 5 6 outputs = { self, nixpkgs }: 7 let 8 # to work with older version of flakes 9 lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; 10 11 # Generate a user-friendly version number. 12 version = builtins.substring 0 8 lastModifiedDate; 13 14 # System types to support. 15 supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; 16 17 # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. 18 forAllSystems = nixpkgs.lib.genAttrs supportedSystems; 19 20 # Nixpkgs instantiated for supported system types. 21 nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); 22 in 23 { 24 25 # Provide some binary packages for selected system types. 26 packages = forAllSystems (system: 27 let 28 pkgs = nixpkgs.legacyPackages.${system}; 29 in 30 { 31 bob = pkgs.buildGoModule { 32 pname = "bob"; 33 inherit version; 34 35 # In 'nix develop', we don't need a copy of the source tree 36 # in the Nix store. 37 src = ./.; 38 39 CGO_ENABLED = 0; 40 41 ldflags = [ "-s" "-w" "-X main.Version=${version}" ]; 42 43 # This hash locks the dependencies of this package. It is 44 # necessary because of how Go requires network access to resolve 45 # VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for 46 # details. Normally one can build with a fake sha256 and rely on native Go 47 # mechanisms to tell you what the hash should be or determine what 48 # it should be "out-of-band" with other tooling (eg. gomod2nix). 49 # To begin with it is recommended to set this, but one must 50 # remeber to bump this hash when your dependencies change. 51 # vendorSha256 = pkgs.lib.fakeSha256; 52 # 53 # error: hash mismatch in fixed-output derivation '/nix/store/cvpva6ww5h4vy29b3zjrw9fymkfgi9kk-bob0.5.3-go-modules.drv': 54 # specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= 55 # got: sha256-BzlZiAXA8wQ7RU6N1knPYH/BDX1Ae+2+4pVJ41ecK7A=*/ 56 # 57 # If on `nix build` you get above error, just replace the value vendorSha256 with value from `got` 58 vendorSha256 = "sha256-S1XUgjdSVTWXehOLCxXcvj0SH12cxqvYadVlCw/saF4="; 59 60 excludedPackages = [ "example/server-db" "test/e2e" "tui-example" ]; 61 62 doCheck = false; 63 }; 64 }); 65 66 # The default package for 'nix build'. This makes sense if the 67 # flake provides only one package or there is a clear "main" 68 # package. 69 defaultPackage = forAllSystems (system: self.packages.${system}.bob); 70 }; 71 }