My multi-host NixOS flake!
Important
If you want to adapt these dot files for yourself be sure to configure your own hosts.
- Add a new entry to
nixosConfigurations
inflake.nix
:
# ...
nixosConfigurations = lib.genHosts = {
new-host = {
username = "new-host-user";
userDescription = "probably your name (for display-manager)";
# Other options you may want to change:
# arch (default: "x86_64-linux")
# hostname (default: config name)
};
# ...
};
# ...
- Create
default.nix
inhosts/new-host/
. Import modules likehardware-configuration.nix
orconfig.nix
from there. - Have a look at
options.md
for my custom configuration options.
- After setting up your hosts run
copy_config.sh
:
./copy_config.sh
- For the first rebuild with this config rebuild like this:
sudo nixos-rebuild boot --install-bootloader --flake /etc/nixos#<config-you-want-to-build>
Afterwards, you can run sudo nixos-rebuild switch|boot|etc.
like normal.
After the first build you can also use nh
:
- Set
modules.programs.nh.configPath
to your/path/to/nixos-config
before your first rebuild. (default is/home/${username}/git/dot-files
) - Rebuild the system with
nh os switch|boot|etc
.
In the shells
directory, there are also a couple of nix shells for different usecases. You can enter the default dev shell with nix develop
.
Other shells can be invoked as you would expect. E.g.:
nix develop .#nix
Warning
These shells cannot be used through nix-shell
. This was a conscious decision because I wanted them to always be as reproducable as the rest of the system.
This flake also provides library function similar to lib
in nixpkgs. These can be used in other flakes.
Currently, these functions are provided:
lib.mkHost
: for more easily defining new hosts using this flakelib.genHosts
: used inflake.nix
and maps attribute sets ontolib.mkHost
lib.eachSystem
: defining stuff for all architectures
This is taken from the
flake.nix
from another of my projects.
{
description = "Magma-ECS dev shell";
inputs = {
dot-files.url = "git+https://codeberg.org/DynamicGoose/dot-files.git";
};
outputs =
{ self, dot-files }:
{
devShells = dot-files.lib.eachSystem (pkgs: {
default =
let
libPath =
with pkgs;
lib.makeLibraryPath [
vulkan-loader
];
in
pkgs.mkShell {
name = "magma-ecs";
nativeBuildInputs = with pkgs; [
rustc
cargo
gcc
rust-analyzer
rustfmt
clippy
];
buildInputs = with pkgs; [
pkg-config
];
LD_LIBRARY_PATH = "${libPath}";
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
});
};
}