Is there a default declarative Nix configuration similar to .config/home-manager/home.nix
that can install Nix packages into a profile? I’m running Nix in Ubuntu Server, not NixOS.
You can use buildEnv
to do things like that: Nixpkgs 23.05 manual | Nix & NixOS
home-manager does a lot of additional heavy lifting for systemd user services and configuration symlinks that aren’t trivial with this approach.
What is the equivalent of nix-env -iA nixpkgs.myPackages
and nix-env -f. -iA myPackages
using the new experimental nix
commands?
That doesn’t exist. You’d probably do something with a flake.nix
:
{
inputs = {
# Grab a static nixpkgs or the one from your registry
};
outputs = {nixpkgs, ...}: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
packages.${system}.default = pkgs.buildEnv {
name = "my-packages";
paths = with pkgs; [
aspell
bc
coreutils
gdb
ffmpeg
nixUnstable
emscripten
jq
nox
silver-searcher
];
};
};
}
Then install with nix profile install .#
YMMV, this is more pseudocode than anything else, I haven’t tested it at all.
How does nix profile install .#
know to “install” the flake?
nix profile install .#
will look at the flake outputs, and look for an outputs.packages.${system}.default
. .#
in this case tells nix what to install, specifically an output of the flake in the current directory (.
), and since we omit the output it will install the default one. See this doc for details.
If the default output exists, and is a derivation, it will add that derivation to the profile, which basically just means that nix will add certain symlinks from those packages to your nix profile directory, which in turn should be referred to in $PATH
and the like so that you can run the binaries in question.
buildEnv
in this case just collects all packages in its paths
into such a set of symlinks, which are then recursively installed into your profile.