Skip to content

Commit

Permalink
simplify nix settings
Browse files Browse the repository at this point in the history
- Don't auto-optimise-store by default
    - We should avoid arbitrary "sane defaults" in this template, as nixpkgs already has pretty sane defaults nowadays
- Simplify registry+nixPath
    - Instead of using a file as indirection (to avoid staleness), indirect it through the registry using `flake:nixpkgs`
    - Add a comment about NixOS/nixpkgs#254405, which all this by default for nixpkgs
- Disable channels and flake registry by default
  • Loading branch information
Misterio77 committed Apr 27, 2024
1 parent 1c11308 commit 8204a49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
33 changes: 14 additions & 19 deletions minimal/nixos/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,21 @@
};
};

# This will add each flake input as a registry
# To make nix3 commands consistent with your flake
nix.registry = (lib.mapAttrs (_: flake: {inherit flake;})) ((lib.filterAttrs (_: lib.isType "flake")) inputs);

# This will additionally add your inputs to the system's legacy channels
# Making legacy nix commands consistent as well, awesome!
nix.nixPath = ["/etc/nix/path"];
environment.etc =
lib.mapAttrs'
(name: value: {
name = "nix/path/${name}";
value.source = value.flake;
})
config.nix.registry;
nix = let
flakeInputs = lib.filterAttrs (_: lib.isType "flake") inputs;
in {
settings = {
# Enable flakes and new 'nix' command
experimental-features = "nix-command flakes";
# Opinionated: disable global registry
flake-registry = "";
};
# Opinionated: disable channels
channel.enable = false;

nix.settings = {
# Enable flakes and new 'nix' command
experimental-features = "nix-command flakes";
# Deduplicate and optimize nix store
auto-optimise-store = true;
# Opinionated: make flake registry and nix path match flake inputs
registry = lib.mapAttrs (_: flake: {inherit flake;}) flakeInputs;
nixPath = lib.mapAttrsToList (n: _: "${n}=flake:${n}") flakeInputs;
};

# FIXME: Add the rest of your current configuration
Expand Down
33 changes: 14 additions & 19 deletions standard/nixos/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,21 @@
};
};

# This will add each flake input as a registry
# To make nix3 commands consistent with your flake
nix.registry = (lib.mapAttrs (_: flake: {inherit flake;})) ((lib.filterAttrs (_: lib.isType "flake")) inputs);

# This will additionally add your inputs to the system's legacy channels
# Making legacy nix commands consistent as well, awesome!
nix.nixPath = ["/etc/nix/path"];
environment.etc =
lib.mapAttrs'
(name: value: {
name = "nix/path/${name}";
value.source = value.flake;
})
config.nix.registry;
nix = let
flakeInputs = lib.filterAttrs (_: lib.isType "flake") inputs;
in {
settings = {
# Enable flakes and new 'nix' command
experimental-features = "nix-command flakes";
# Opinionated: disable global registry
flake-registry = "";
};
# Opinionated: disable channels
channel.enable = false;

nix.settings = {
# Enable flakes and new 'nix' command
experimental-features = "nix-command flakes";
# Deduplicate and optimize nix store
auto-optimise-store = true;
# Opinionated: make flake registry and nix path match flake inputs
registry = lib.mapAttrs (_: flake: {inherit flake;}) flakeInputs;
nixPath = lib.mapAttrsToList (n: _: "${n}=flake:${n}") flakeInputs;
};

# FIXME: Add the rest of your current configuration
Expand Down

0 comments on commit 8204a49

Please sign in to comment.