benclmnt / til

Today I Learned: mainly configs, gotchas, setups, workflows
1 stars 0 forks source link

Nix #28

Open benclmnt opened 9 months ago

benclmnt commented 9 months ago

Background: use Nix on MacOS

Where to start with Nix

Glossary

Nix, the language

Nix Flakes

tldr: a standardized way to package a software in a hermetic way. like package.json. There is flake.lock that works similar to package.lock

useful commands

benclmnt commented 9 months ago

Related issues:

benclmnt commented 8 months ago

An example of a flake.nix for a golang monorepo that requires go1.17

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-22.05-darwin";
  };

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

      # Helper to provide system-specific attributes
      forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
        pkgs = import nixpkgs { inherit system; };
      });
    in
    {
      devShells = forAllSystems ({ pkgs }: {
        default = pkgs.mkShell {
          packages = with pkgs; [
            go_1_17
            gotools
            buf
          ];

          shellHook = ''
          go env -w GONOPROXY="golang.org,github.com,go.uber.org"
          '';
        };
      });
    };
}