3p/nixpkgs: allow disabling nix in nixos
This commit is contained in:
parent
96f736ab7e
commit
35a2c6b33d
7 changed files with 131 additions and 16 deletions
|
@ -91,7 +91,7 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = mkIf config.nix.enable {
|
||||||
|
|
||||||
system.nixos-generate-config.configuration = mkDefault ''
|
system.nixos-generate-config.configuration = mkDefault ''
|
||||||
# Edit this configuration file to define what should be installed on
|
# Edit this configuration file to define what should be installed on
|
||||||
|
|
|
@ -81,6 +81,14 @@ in
|
||||||
|
|
||||||
nix = {
|
nix = {
|
||||||
|
|
||||||
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = ''
|
||||||
|
If disabled, Nix will not be available on the built NixOS system.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
package = mkOption {
|
package = mkOption {
|
||||||
type = types.package;
|
type = types.package;
|
||||||
default = pkgs.nix;
|
default = pkgs.nix;
|
||||||
|
@ -498,7 +506,7 @@ in
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
assertions = [
|
assertions = [
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,7 @@ in
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = {
|
config = mkIf config.nix.enable {
|
||||||
|
|
||||||
systemd.services.nix-gc =
|
systemd.services.nix-gc =
|
||||||
{ description = "Nix Garbage Collector";
|
{ description = "Nix Garbage Collector";
|
||||||
|
|
|
@ -36,7 +36,7 @@ in
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = {
|
config = mkIf config.nix.enable {
|
||||||
|
|
||||||
systemd.services.nix-optimise =
|
systemd.services.nix-optimise =
|
||||||
{ description = "Nix Store Optimiser";
|
{ description = "Nix Store Optimiser";
|
||||||
|
|
|
@ -124,18 +124,19 @@ def mkdir_p(path):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def get_generations(profile=None):
|
def get_generations(profile=None):
|
||||||
gen_list = subprocess.check_output([
|
generation_dir = "/nix/var/nix/profiles/%s" % ("system-profiles" if profile else "",)
|
||||||
"@nix@/bin/nix-env",
|
profile_name = profile if profile else "system"
|
||||||
"--list-generations",
|
generations = []
|
||||||
"-p",
|
for gen_entry in os.scandir(generation_dir):
|
||||||
"/nix/var/nix/profiles/%s" % ("system-profiles/" + profile if profile else "system"),
|
gen_name = gen_entry.name
|
||||||
"--option", "build-users-group", ""],
|
if not (gen_name.startswith(profile_name + '-') and gen_name.endswith('-link')):
|
||||||
universal_newlines=True)
|
continue
|
||||||
gen_lines = gen_list.split('\n')
|
gen_num = gen_name[len(profile_name+'-'):-len('-link')]
|
||||||
gen_lines.pop()
|
generations.append(int(gen_num))
|
||||||
|
generations.sort()
|
||||||
|
|
||||||
configurationLimit = @configurationLimit@
|
configurationLimit = @configurationLimit@
|
||||||
return [ (profile, int(line.split()[0])) for line in gen_lines ][-configurationLimit:]
|
return [ (profile, gen_num) for gen_num in sorted(generations) ][-configurationLimit:]
|
||||||
|
|
||||||
def remove_old_entries(gens):
|
def remove_old_entries(gens):
|
||||||
rex_profile = re.compile("^@efiSysMountPoint@/loader/entries/nixos-(.*)-generation-.*\.conf$")
|
rex_profile = re.compile("^@efiSysMountPoint@/loader/entries/nixos-(.*)-generation-.*\.conf$")
|
||||||
|
|
|
@ -16,8 +16,6 @@ let
|
||||||
|
|
||||||
systemd = config.systemd.package;
|
systemd = config.systemd.package;
|
||||||
|
|
||||||
nix = config.nix.package.out;
|
|
||||||
|
|
||||||
timeout = if config.boot.loader.timeout != null then config.boot.loader.timeout else "";
|
timeout = if config.boot.loader.timeout != null then config.boot.loader.timeout else "";
|
||||||
|
|
||||||
editor = if cfg.editor then "True" else "False";
|
editor = if cfg.editor then "True" else "False";
|
||||||
|
|
108
third_party/nixpkgs/patches/0001-nixpkgs-allow-disable-nix.patch
vendored
Normal file
108
third_party/nixpkgs/patches/0001-nixpkgs-allow-disable-nix.patch
vendored
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
diff --git a/nixos/modules/installer/tools/tools.nix b/nixos/modules/installer/tools/tools.nix
|
||||||
|
--- a/nixos/modules/installer/tools/tools.nix
|
||||||
|
+++ b/nixos/modules/installer/tools/tools.nix
|
||||||
|
@@ -86,7 +86,7 @@ in
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
- config = {
|
||||||
|
+ config = mkIf config.nix.enable {
|
||||||
|
|
||||||
|
system.nixos-generate-config.configuration = mkDefault ''
|
||||||
|
# Edit this configuration file to define what should be installed on
|
||||||
|
diff --git a/nixos/modules/services/misc/nix-daemon.nix b/nixos/modules/services/misc/nix-daemon.nix
|
||||||
|
--- a/nixos/modules/services/misc/nix-daemon.nix
|
||||||
|
+++ b/nixos/modules/services/misc/nix-daemon.nix
|
||||||
|
@@ -81,6 +81,14 @@ in
|
||||||
|
|
||||||
|
nix = {
|
||||||
|
|
||||||
|
+ enable = mkOption {
|
||||||
|
+ type = types.bool;
|
||||||
|
+ default = true;
|
||||||
|
+ description = ''
|
||||||
|
+ If disabled, Nix will not be available on the built NixOS system.
|
||||||
|
+ '';
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
package = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
default = pkgs.nix;
|
||||||
|
@@ -498,7 +506,7 @@ in
|
||||||
|
|
||||||
|
###### implementation
|
||||||
|
|
||||||
|
- config = {
|
||||||
|
+ config = mkIf cfg.enable {
|
||||||
|
|
||||||
|
nix.binaryCachePublicKeys = [ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" ];
|
||||||
|
nix.binaryCaches = [ "https://cache.nixos.org/" ];
|
||||||
|
diff --git a/nixos/modules/services/misc/nix-gc.nix b/nixos/modules/services/misc/nix-gc.nix
|
||||||
|
--- a/nixos/modules/services/misc/nix-gc.nix
|
||||||
|
+++ b/nixos/modules/services/misc/nix-gc.nix
|
||||||
|
@@ -48,7 +48,7 @@ in
|
||||||
|
|
||||||
|
###### implementation
|
||||||
|
|
||||||
|
- config = {
|
||||||
|
+ config = mkIf config.nix.enable {
|
||||||
|
|
||||||
|
systemd.services.nix-gc =
|
||||||
|
{ description = "Nix Garbage Collector";
|
||||||
|
diff --git a/nixos/modules/services/misc/nix-optimise.nix b/nixos/modules/services/misc/nix-optimise.nix
|
||||||
|
--- a/nixos/modules/services/misc/nix-optimise.nix
|
||||||
|
+++ b/nixos/modules/services/misc/nix-optimise.nix
|
||||||
|
@@ -36,7 +36,7 @@ in
|
||||||
|
|
||||||
|
###### implementation
|
||||||
|
|
||||||
|
- config = {
|
||||||
|
+ config = mkIf config.nix.enable {
|
||||||
|
|
||||||
|
systemd.services.nix-optimise =
|
||||||
|
{ description = "Nix Store Optimiser";
|
||||||
|
diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py
|
||||||
|
--- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py
|
||||||
|
+++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py
|
||||||
|
@@ -124,18 +124,19 @@ def mkdir_p(path):
|
||||||
|
raise
|
||||||
|
|
||||||
|
def get_generations(profile=None):
|
||||||
|
- gen_list = subprocess.check_output([
|
||||||
|
- "@nix@/bin/nix-env",
|
||||||
|
- "--list-generations",
|
||||||
|
- "-p",
|
||||||
|
- "/nix/var/nix/profiles/%s" % ("system-profiles/" + profile if profile else "system"),
|
||||||
|
- "--option", "build-users-group", ""],
|
||||||
|
- universal_newlines=True)
|
||||||
|
- gen_lines = gen_list.split('\n')
|
||||||
|
- gen_lines.pop()
|
||||||
|
+ generation_dir = "/nix/var/nix/profiles/%s" % ("system-profiles" if profile else "",)
|
||||||
|
+ profile_name = profile if profile else "system"
|
||||||
|
+ generations = []
|
||||||
|
+ for gen_entry in os.scandir(generation_dir):
|
||||||
|
+ gen_name = gen_entry.name
|
||||||
|
+ if not (gen_name.startswith(profile_name + '-') and gen_name.endswith('-link')):
|
||||||
|
+ continue
|
||||||
|
+ gen_num = gen_name[len(profile_name+'-'):-len('-link')]
|
||||||
|
+ generations.append(int(gen_num))
|
||||||
|
+ generations.sort()
|
||||||
|
|
||||||
|
configurationLimit = @configurationLimit@
|
||||||
|
- return [ (profile, int(line.split()[0])) for line in gen_lines ][-configurationLimit:]
|
||||||
|
+ return [ (profile, gen_num) for gen_num in sorted(generations) ][-configurationLimit:]
|
||||||
|
|
||||||
|
def remove_old_entries(gens):
|
||||||
|
rex_profile = re.compile("^@efiSysMountPoint@/loader/entries/nixos-(.*)-generation-.*\.conf$")
|
||||||
|
diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix
|
||||||
|
--- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix
|
||||||
|
+++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix
|
||||||
|
@@ -16,8 +16,6 @@ let
|
||||||
|
|
||||||
|
systemd = config.systemd.package;
|
||||||
|
|
||||||
|
- nix = config.nix.package.out;
|
||||||
|
-
|
||||||
|
timeout = if config.boot.loader.timeout != null then config.boot.loader.timeout else "";
|
||||||
|
|
||||||
|
editor = if cfg.editor then "True" else "False";
|
Loading…
Reference in a new issue