Hi Nixos forum dwellers,
I’ve just started using Nix on MacOs and I am trying to configure a declarative package management setup.
Goal 1: user specific default packages
My goal is tho have a configuration that I can sync between multiple Macs (and preferably any other unix machines/VMs) and run some command to install packages listed in that configuration. As a result packages in the list should be available only for the current user via $PATH
.
I see that people use home-manager and nix-darwin to configure a list of packages they want to be always installed. But nix-darwin installation is too invasive and I do not want to configure all the system settings with it; and home-manager is also way over the functionality I need.
While checking home-manager code I see that they use pkgs.buildEnv
to provide a list of packages and then they run nix profile install
or nix-env -i
to install packages to the user environment. So I came up with this flake:
{
description = "Nick's flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }: {
packages."aarch64-darwin".default =
let
pkgs = nixpkgs.legacyPackages."aarch64-darwin";
in
pkgs.buildEnv {
name = "global-packages";
paths = with pkgs; [
git
];
};
};
}
It is synced to ~/.config/nixpkgs/flake.nix
so I can add more packages into flake on one computer and go to another computer and get the same config.
I run nix profile install .
(while reading more about nix-env -i
it seems like it’s almost deprecated) in this directory and it installs my packages and makes them available by adding links to ~/.nix-profile
Is this The Proper way to set up declarative package management considering Nix approaches?
Goal 2: system wide default packages
Do the same as goal 1 but instead of doing user specific I want to make it system wide so that all users on a machine/VM get the same set of available packages by default.
Is there a way to have a similar flake for system wide configuration and to run some command to install it to profiles of other users? Or, Is it possible to add those binaries to /nix/var/nix/profiles/default/bin
(already in $PATH
) where all nix executables reside?
User’s in this case should not be required to do anything to bring those packages into their environment. (I have multi-user Nix installation via https://determinate.systems GUI installer)
In NixOs it seems like /etc/nixos/configuration.nix
file handle what I am trying to achieve here but on MacOs I don’t see such file. Will it work if I create it?
I see that nix-darwin
is used for system wide packages via environment.systemPackages
option which it’s also passing to pkgs.buildEnv
Additional Questions
- While looking at
flake.lock
I see it locks version of the input (nixos/nixpkgs/nixos-unstable
) while versions of packages inpkgs.buildEnv
aren’t locked. Does that mean when I runnix profile install .
it will always look for the latest version of the package coming from locked version ofnixos/nixpkgs/nixos-unstable
? - I also see that there is manifest.json concept described here manifest.json - Nix Reference Manual that kind of solves my problem in Goal 1, what is a more preferable way manifest.json or flake.nix?
- How do I list packages and their versions installed via
pkgs.buildEnv
?