diff --git a/flake.nix b/flake.nix index 3c81421e5e6817b4f65a620d36b0ebf724a191da..bb688c8236acf85a20ff78d350aa8bde2250c62a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,8 +1,6 @@ { description = "docman is a document management tool"; - # Nixpkgs / NixOS version to use. - inputs = { nixpkgs.url = "nixpkgs/nixos-23.05"; versionTool.url = "https://gitlab.schukai.com/oss/utilities/version/-/archive/0.5.0/version-0.5.0.tar.gz"; @@ -11,86 +9,49 @@ outputs = { self, nixpkgs, versionTool, ... }: 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; }); pkgs = import nixpkgs { system = "x86_64-linux"; }; -# versionTool = pkgs.fetchzip { -# url = "https://gitlab.schukai.com/oss/utilities/version/-/archive/0.5.0/version-0.5.0.tar.gz"; -# # You'll need to provide the correct hash here. -# sha256 = "sha256-jzixQKFFW4oxO0S4GYqbkFCXzhBd6com6Z9+MtVKakU="; -# }; - - in { - # Provide some binary packages for selected system types. + packages = forAllSystems (system: let pkgs = nixpkgsFor.${system}; - # Build the versionTool for the current system. versionToolPackage = versionTool.defaultPackage.${system}; - -# versionAndBuild = pkgs.runCommand "get-version-and-build" {} '' -# ${versionToolPackage}/bin/version print --git > $out.version -# ${versionToolPackage}/bin/version build > $out.build -# ''; -# -# version = builtins.trace (builtins.readFile "${versionAndBuild}.version"; -# build = builtins.readFile "${versionAndBuild}.build"; - - versionAndBuild = pkgs.runCommand "get-version-and-build" { - outputFiles = [ "version" "build" ]; - } '' - ${versionToolPackage}/bin/version print --git > $out/version - ${versionToolPackage}/bin/version build > $out/build - ''; - version = builtins.trace (builtins.readFile "${versionAndBuild}.version") "Reading version"; - build = builtins.trace (builtins.readFile "${versionAndBuild}.build") "Reading build"; + versionAndBuild = pkgs.runCommand "get-version-and-build" { + outputFiles = [ "version" "build" ]; + } '' + ${versionToolPackage}/bin/version print --git > $out/version + ${versionToolPackage}/bin/version build > $out/build + ''; + + version = builtins.trace (builtins.readFile "${versionAndBuild}/version") "Reading version"; + build = builtins.trace (builtins.readFile "${versionAndBuild}/build") "Reading build"; + + + in { docman = pkgs.buildGoModule { - buildPhase = '' - version=$(${versionTool}/bin/version print --git) - build=$(${versionTool}/bin/version build) - - go build -ldflags "-X 'gitlab.schukai.com/oss/utilities/documentation-manager/release.version=$version' -X 'gitlab.schukai.com/oss/utilities/documentation-manager/release.build=$build'" - ''; - name = "docman"; - # In 'nix develop', we don't need a copy of the source tree - # in the Nix store. src = ././source; version = "${version}"; - # This hash locks the dependencies of this package. It is - # necessary because of how Go requires network access to resolve - # VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for - # details. Normally one can build with a fake sha256 and rely on native Go - # mechanisms to tell you what the hash should be or determine what - # it should be "out-of-band" with other tooling (eg. gomod2nix). - # To begin with it is recommended to set this, but one must - # remeber to bump this hash when your dependencies change. - #vendorSha256 = pkgs.lib.fakeSha256; - - #vendorSha256 = "sha256-XdB+u94Rqsb29jVs4miyOq1NEYaVJHWFXg6QebFJzNQ="; vendorSha256 = "sha256-81IBG8H1jsYKD+tmFeCpAWFdz6cuQDt9r+FV56xboBU="; ldflags = [ @@ -109,7 +70,6 @@ }; }); - # Add dependencies that are only needed for development devShells = forAllSystems (system: let pkgs = nixpkgsFor.${system}; @@ -120,9 +80,7 @@ }; }); - # 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}.docman); }; }