Open benclmnt opened 9 months ago
Related issues:
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"
'';
};
});
};
}
Background: use Nix on MacOS
Where to start with Nix
Glossary
/nix/store
(by default)/nix/store
~/.nix-defexpr
is where nixpkgs is stored.nixpkgs
just refer to https://github.com/nixos/nixpkgs/.import <nixpkgs> {}
is kinda similar toimport (fetchGithub https://github.com/nixos/nixpkgs/)
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 topackage.lock
useful commands
nix shell [flakes] --command [binary name] [args]