Skip to content

Commit

Permalink
Add common settings to all configurations (#75)
Browse files Browse the repository at this point in the history
These are sensible defaults we generally want across all configurations
-- home-manager, NixOS, nix-darwin.

Note: NixOS (and nix-darwin) recently gained some defaults that we don't
add here: NixOS/nixpkgs#254405
  • Loading branch information
srid authored Oct 1, 2024
1 parent 5593460 commit cb794a4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
15 changes: 9 additions & 6 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ emanote:

nixos-flake provides the following features:

- [[activate]]: An `.#activate` flake app that works both on macOS and NixOS.
- `.#activate` can also *remotely* activate machines (be it macOS or NixOS) over SSH.
- All NixOS/ nix-darwin/ home-manager modules receive `specialArgs` which includes all the information in the top-level flake.
- This enables those modules to be aware of the flake inputs, for instance.
- A `.#update` flake app to update the primary inputs (which can be overriden)
- **One-click activation & deployment**
- [[activate]]: An `.#activate` flake app that works both on macOS and NixOS.
- `.#activate` can also *remotely* activate machines (be it macOS or NixOS) over SSH, thus acting as a simple alternative to deployment tools like `deploy-rs` and `colmena`.
- Also: an `.#update` flake app to update the primary inputs (which can be overriden)
- **Seamless access to top-level flake**
- All NixOS/ nix-darwin/ home-manager modules receive `specialArgs` which includes all the information in the top-level flake.
- This enables those modules to be aware of the flake inputs, for instance.
- **Sensible defaults**
- Sensible defaults for home-manager/ nix-darwin/ and NixOS configurations ([\#75](https://github.com/srid/nixos-flake/pull/75)).

## Getting Started

See: [[start]]# and [[guide]]#. For examples, see [[examples]]#

[home-manager]: https://github.com/nix-community/home-manager

44 changes: 30 additions & 14 deletions nix/modules/flake-parts/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ let
}
];
};

# Common and useful setting across all platforms
common = { lib, ... }: {
nix = {
settings = {
# Use all CPU cores
max-jobs = lib.mkDefault "auto";
# Duh
experimental-features = lib.mkDefault "nix-command flakes";
};
};
};
};

homeModules = {
common = { pkgs, ... }: {
home.sessionPath = lib.mkIf pkgs.stdenv.isDarwin [
"/etc/profiles/per-user/$USER/bin" # To access home-manager binaries
"/nix/var/nix/profiles/system/sw/bin" # To access nix-darwin binaries
"/usr/local/bin" # Some macOS GUI programs install here
];
};
};

darwinModules = {
Expand All @@ -33,26 +55,15 @@ let
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = specialArgsFor.darwin;
home-manager.sharedModules = [{
home.sessionPath = [
"/etc/profiles/per-user/$USER/bin" # To access home-manager binaries
"/nix/var/nix/profiles/system/sw/bin" # To access nix-darwin binaries
"/usr/local/bin" # Some macOS GUI programs install here
];
}];
home-manager.sharedModules = [ homeModules.common ];
}
];
};
# nix-darwin module containing necessary configuration
# Required when using the DetSys installer
# cf. https://github.com/srid/nixos-flake/issues/52
nix-darwin = {
nix = {
useDaemon = true; # Required on multi-user Nix install
settings = {
experimental-features = "nix-command flakes"; # Enable flakes
};
};
nix.useDaemon = true; # Required on multi-user Nix install
};
};
in
Expand All @@ -67,6 +78,7 @@ in
specialArgs = specialArgsFor.nixos;
modules = [
../configurations
nixosModules.common
mod
] ++ lib.optional home-manager nixosModules.home-manager;
};
Expand All @@ -75,6 +87,7 @@ in
specialArgs = specialArgsFor.darwin;
modules = [
../configurations
nixosModules.common
darwinModules.nix-darwin
mod
] ++ lib.optional home-manager darwinModules.home-manager;
Expand All @@ -83,7 +96,10 @@ in
mkHomeConfiguration = pkgs: mod: inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = specialArgsFor.common;
modules = [ mod ];
modules = [
homeModules.common
mod
];
};
};
};
Expand Down

0 comments on commit cb794a4

Please sign in to comment.