Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain how to include a flake in the output #295

Open
a-h opened this issue Oct 17, 2023 · 0 comments
Open

Explain how to include a flake in the output #295

a-h opened this issue Oct 17, 2023 · 0 comments

Comments

@a-h
Copy link

a-h commented Oct 17, 2023

To extend the current behaviour to include external flake, I had to do a couple of things:

{
  description = "api";

  # Add my flake input here.
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
    xc.url = "github:joerdav/xc";
  };

  outputs = { self, nixpkgs, xc }:
    let
      # Systems supported
      allSystems = [
        "x86_64-linux" # 64-bit Intel/AMD Linux
        "aarch64-linux" # 64-bit ARM Linux
        "x86_64-darwin" # 64-bit Intel macOS
        "aarch64-darwin" # 64-bit ARM macOS
      ];

      # Helper to provide system-specific attributes.
      # Note, adding `system` to the output here.
      forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
        system = system;
        pkgs = import nixpkgs {
          inherit system;
        };
      });
    in
    {
      # `nix build` builds the app.
      packages = forAllSystems ({ system, pkgs }: {
        default = pkgs.buildGo121Module {
          name = "api";
          src = ./.;
          subPackages = [ "./app" ];
          vendorHash = "sha256-TvncLmPfELnkFnp88xiFXWww7pniZb5YpTeW6oRiweA=";
          proxyVendor = true;
          postInstall = ''
            mv $out/bin/app $out/bin/api
          '';
        };
      });
      # `nix develop` provides a shell containing required tools.
      # Note the use of the `system` attribute that is now output by the `forAllSystems` function as
      # an input to the function. This lets the flake input be referenced.
      devShell = forAllSystems ({ system, pkgs }:
        pkgs.mkShell {
          buildInputs = [
            pkgs.go_1_21
            pkgs.nats-server
            pkgs.minio
            pkgs.minio-client
            pkgs.minio-certgen
            xc.packages.${system}.xc
          ];
        });
    };
}

I don't know if there's a better way of doing this, but I noticed that zero-to-nix doesn't seem to include an example of doing this sort of thing.

If there's appetite, I can do a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant