From 42b6a0396276a7ed961768fc2fde1b2de5155ffb Mon Sep 17 00:00:00 2001 From: Christian Harke Date: Wed, 3 Jan 2024 21:10:24 +0100 Subject: [PATCH] Extract duplicated nix configuration --- lib/builders/mkNixDarwin.nix | 1 + lib/builders/mkNixos.nix | 1 + lib/builders/modules/nix/default.nix | 36 ++++++++++++++++++++++++++++ nix-darwin/nix/default.nix | 28 ---------------------- nixos/base/nix/default.nix | 29 ---------------------- 5 files changed, 38 insertions(+), 57 deletions(-) create mode 100644 lib/builders/modules/nix/default.nix diff --git a/lib/builders/mkNixDarwin.nix b/lib/builders/mkNixDarwin.nix index 64909170..0c3c042d 100644 --- a/lib/builders/mkNixDarwin.nix +++ b/lib/builders/mkNixDarwin.nix @@ -8,6 +8,7 @@ inputs.darwin.lib.darwinSystem { }; modules = [ + ./modules/nix inputs.home-manager.darwinModules.home-manager "${inputs.self}/hosts/${name}" diff --git a/lib/builders/mkNixos.nix b/lib/builders/mkNixos.nix index f1baf6d5..348246bd 100644 --- a/lib/builders/mkNixos.nix +++ b/lib/builders/mkNixos.nix @@ -8,6 +8,7 @@ inputs.nixpkgs.lib.nixosSystem { }; modules = [ + ./modules/nix "${inputs.self}/hosts/${name}" { diff --git a/lib/builders/modules/nix/default.nix b/lib/builders/modules/nix/default.nix new file mode 100644 index 00000000..4f455391 --- /dev/null +++ b/lib/builders/modules/nix/default.nix @@ -0,0 +1,36 @@ +{ pkgs, config, lib, inputs, ... }: + +{ + nix = { + nixPath = [ "nixpkgs=flake:nixpkgs" ]; + registry = { + nixpkgs.flake = inputs.nixpkgs; + nix-config.flake = inputs.self; + }; + settings = { + allowed-users = builtins.attrNames config.users.users; + auto-optimise-store = true; + experimental-features = [ "nix-command" "flakes" ]; + log-lines = 30; + substituters = [ + "https://christianharke.cachix.org/" + "https://nix-community.cachix.org" + "https://cache.nixos.org" + ]; + trusted-public-keys = [ + "christianharke.cachix.org-1:TzmbiNLRcH8G0932XRlQzh8GPvuV9pJcHLqLnzznLKU=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + ]; + }; + }; + + system.activationScripts.diff = { + supportsDryActivation = true; + text = '' + if [[ -e /run/current-system ]]; then + ${lib.getExe pkgs.nix} store diff-closures /run/current-system "$systemConfig" + fi + ''; + }; +} diff --git a/nix-darwin/nix/default.nix b/nix-darwin/nix/default.nix index dccfa245..d081d9e5 100644 --- a/nix-darwin/nix/default.nix +++ b/nix-darwin/nix/default.nix @@ -1,37 +1,9 @@ { pkgs, config, lib, inputs, ... }: { - # TODO: Extract duplications from nixos config nix = { - nixPath = [ "nixpkgs=flake:nixpkgs" ]; - registry = { - nixpkgs.flake = inputs.nixpkgs; - nix-config.flake = inputs.self; - }; settings = { - allowed-users = builtins.attrNames config.users.users; auto-optimise-store = true; - experimental-features = [ "nix-command" "flakes" ]; - log-lines = 30; - substituters = [ - "https://christianharke.cachix.org/" - "https://nix-community.cachix.org" - "https://cache.nixos.org" - ]; - trusted-public-keys = [ - "christianharke.cachix.org-1:TzmbiNLRcH8G0932XRlQzh8GPvuV9pJcHLqLnzznLKU=" - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" - ]; }; }; - - system.activationScripts.diff = { - supportsDryActivation = true; - text = '' - if [[ -e /run/current-system ]]; then - ${lib.getExe pkgs.nix} store diff-closures /run/current-system "$systemConfig" - fi - ''; - }; } diff --git a/nixos/base/nix/default.nix b/nixos/base/nix/default.nix index 0b2c3c6e..f04e622b 100644 --- a/nixos/base/nix/default.nix +++ b/nixos/base/nix/default.nix @@ -7,35 +7,6 @@ dates = "04:00"; options = "--delete-older-than 7d"; }; - nixPath = [ "nixpkgs=flake:nixpkgs" ]; optimise.automatic = true; - registry = { - nixpkgs.flake = inputs.nixpkgs; - nix-config.flake = inputs.self; - }; - settings = { - allowed-users = builtins.attrNames config.users.users; - experimental-features = [ "nix-command" "flakes" ]; - log-lines = 30; - substituters = [ - "https://christianharke.cachix.org/" - "https://nix-community.cachix.org" - "https://cache.nixos.org" - ]; - trusted-public-keys = [ - "christianharke.cachix.org-1:TzmbiNLRcH8G0932XRlQzh8GPvuV9pJcHLqLnzznLKU=" - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" - ]; - }; - }; - - system.activationScripts.diff = { - supportsDryActivation = true; - text = '' - if [[ -e /run/current-system ]]; then - ${lib.getExe pkgs.nix} store diff-closures /run/current-system "$systemConfig" - fi - ''; }; }