aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2020-06-13 07:10:12 +0200
committerKatharina Fey <kookie@spacekookie.de>2020-06-13 07:10:12 +0200
commitde94c6c62e2f86b3667386a42690d6bb376a2f58 (patch)
tree2b4bc87db0d46095a7aff46635227a0d7d4b9e06 /nixpkgs/nixos
parent880bc0f8c1c70c65fd97d722a81d834ce43fbcd4 (diff)
parent029a5de08390bb03c3f44230b064fd1850c6658a (diff)
Merge commit '029a5de08390bb03c3f44230b064fd1850c6658a'
Diffstat (limited to 'nixpkgs/nixos')
-rw-r--r--nixpkgs/nixos/doc/manual/release-notes/rl-2009.xml14
-rw-r--r--nixpkgs/nixos/modules/config/system-path.nix4
-rw-r--r--nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix8
-rw-r--r--nixpkgs/nixos/modules/module-list.nix1
-rw-r--r--nixpkgs/nixos/modules/programs/bash/bash.nix3
-rw-r--r--nixpkgs/nixos/modules/rename.nix1
-rw-r--r--nixpkgs/nixos/modules/services/continuous-integration/buildbot/master.nix22
-rw-r--r--nixpkgs/nixos/modules/services/misc/freeswitch.nix4
-rw-r--r--nixpkgs/nixos/modules/services/misc/gitlab.nix3
-rw-r--r--nixpkgs/nixos/modules/services/misc/home-assistant.nix10
-rw-r--r--nixpkgs/nixos/modules/services/misc/nix-daemon.nix6
-rw-r--r--nixpkgs/nixos/modules/services/system/cgmanager.nix26
-rw-r--r--nixpkgs/nixos/modules/system/boot/loader/grub/grub.nix35
-rw-r--r--nixpkgs/nixos/modules/system/boot/loader/grub/install-grub.pl36
-rw-r--r--nixpkgs/nixos/modules/system/boot/stage-1.nix3
-rw-r--r--nixpkgs/nixos/modules/tasks/network-interfaces.nix2
-rw-r--r--nixpkgs/nixos/tests/mysql/mysql.nix92
17 files changed, 178 insertions, 92 deletions
diff --git a/nixpkgs/nixos/doc/manual/release-notes/rl-2009.xml b/nixpkgs/nixos/doc/manual/release-notes/rl-2009.xml
index e17e8ac24d1..115f9ebc565 100644
--- a/nixpkgs/nixos/doc/manual/release-notes/rl-2009.xml
+++ b/nixpkgs/nixos/doc/manual/release-notes/rl-2009.xml
@@ -441,6 +441,20 @@ systemd.services.nginx.serviceConfig.ReadWritePaths = [ "/var/www" ];
recommended to only use lower-case characters.
</para>
</listitem>
+ <listitem>
+ <para>
+ The GRUB specific option <option>boot.loader.grub.extraInitrd</option>
+ has been replaced with the generic option
+ <option>boot.initrd.secrets</option>. This option creates a secondary
+ initrd from the specified files, rather than using a manually created
+ initrd file.
+
+ Due to an existing bug with <option>boot.loader.grub.extraInitrd</option>,
+ it is not possible to directly boot an older generation that used that
+ option. It is still possible to rollback to that generation if the required
+ initrd file has not been deleted.
+ </para>
+ </listitem>
</itemizedlist>
</section>
diff --git a/nixpkgs/nixos/modules/config/system-path.nix b/nixpkgs/nixos/modules/config/system-path.nix
index 4100ec89701..cba357171d7 100644
--- a/nixpkgs/nixos/modules/config/system-path.nix
+++ b/nixpkgs/nixos/modules/config/system-path.nix
@@ -8,8 +8,7 @@ with lib;
let
requiredPackages = map (pkg: setPrio ((pkg.meta.priority or 5) + 3) pkg)
- [ config.nix.package
- pkgs.acl
+ [ pkgs.acl
pkgs.attr
pkgs.bashInteractive # bash with ncurses support
pkgs.bzip2
@@ -33,7 +32,6 @@ let
pkgs.nano
pkgs.ncurses
pkgs.netcat
- pkgs.nix-info
config.programs.ssh.package
pkgs.perl
pkgs.procps
diff --git a/nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix b/nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix
index bfd8970d2b2..35a7b382b7c 100644
--- a/nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix
+++ b/nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix
@@ -1,6 +1,6 @@
{
- x86_64-linux = "/nix/store/xb0nl3z356n0sfrhswfli2g19a19slys-nix-2.3.5";
- i686-linux = "/nix/store/k8kdd4yy1yap6lai5idyhmzcwsjh1fik-nix-2.3.5";
- aarch64-linux = "/nix/store/dr86cbipxqjcb8pf2k0v8wvw0h0adfpz-nix-2.3.5";
- x86_64-darwin = "/nix/store/n6dqdndkv9kac66kdr988kaiyavl44x8-nix-2.3.5";
+ x86_64-linux = "/nix/store/j8dbv5w6jl34caywh2ygdy88knx1mdf7-nix-2.3.6";
+ i686-linux = "/nix/store/9fqvbdisahqp0238vrs7wn5anpri0a65-nix-2.3.6";
+ aarch64-linux = "/nix/store/72pwn0nm9bjqx9vpi8sgh4bl6g5wh814-nix-2.3.6";
+ x86_64-darwin = "/nix/store/g37vk77m90p5zcl5nixjlzp3vqpisfn5-nix-2.3.6";
}
diff --git a/nixpkgs/nixos/modules/module-list.nix b/nixpkgs/nixos/modules/module-list.nix
index ccbee0a56cf..42491c1a9e9 100644
--- a/nixpkgs/nixos/modules/module-list.nix
+++ b/nixpkgs/nixos/modules/module-list.nix
@@ -807,7 +807,6 @@
./services/security/torsocks.nix
./services/security/usbguard.nix
./services/security/vault.nix
- ./services/system/cgmanager.nix
./services/system/cloud-init.nix
./services/system/dbus.nix
./services/system/earlyoom.nix
diff --git a/nixpkgs/nixos/modules/programs/bash/bash.nix b/nixpkgs/nixos/modules/programs/bash/bash.nix
index be964ce7f3f..1b3254b54a5 100644
--- a/nixpkgs/nixos/modules/programs/bash/bash.nix
+++ b/nixpkgs/nixos/modules/programs/bash/bash.nix
@@ -238,9 +238,6 @@ in
"/share/bash-completion"
];
- environment.systemPackages = optional cfg.enableCompletion
- pkgs.nix-bash-completions;
-
environment.shells =
[ "/run/current-system/sw/bin/bash"
"/run/current-system/sw/bin/sh"
diff --git a/nixpkgs/nixos/modules/rename.nix b/nixpkgs/nixos/modules/rename.nix
index 7776c648af8..c91febdb710 100644
--- a/nixpkgs/nixos/modules/rename.nix
+++ b/nixpkgs/nixos/modules/rename.nix
@@ -24,6 +24,7 @@ with lib;
(mkRemovedOptionModule [ "environment" "blcr" "enable" ] "The BLCR module has been removed")
(mkRemovedOptionModule [ "services" "beegfsEnable" ] "The BeeGFS module has been removed")
(mkRemovedOptionModule [ "services" "beegfs" ] "The BeeGFS module has been removed")
+ (mkRemovedOptionModule ["services" "cgmanager" "enable"] "cgmanager was deprecated by lxc and therefore removed from nixpkgs.")
(mkRemovedOptionModule [ "services" "osquery" ] "The osquery module has been removed")
(mkRemovedOptionModule [ "services" "fourStore" ] "The fourStore module has been removed")
(mkRemovedOptionModule [ "services" "fourStoreEndpoint" ] "The fourStoreEndpoint module has been removed")
diff --git a/nixpkgs/nixos/modules/services/continuous-integration/buildbot/master.nix b/nixpkgs/nixos/modules/services/continuous-integration/buildbot/master.nix
index e3da3092d45..0185f490b0c 100644
--- a/nixpkgs/nixos/modules/services/continuous-integration/buildbot/master.nix
+++ b/nixpkgs/nixos/modules/services/continuous-integration/buildbot/master.nix
@@ -16,7 +16,7 @@ let
factory = util.BuildFactory()
c = BuildmasterConfig = dict(
workers = [${concatStringsSep "," cfg.workers}],
- protocols = { 'pb': {'port': ${toString cfg.bpPort} } },
+ protocols = { 'pb': {'port': ${toString cfg.pbPort} } },
title = '${escapeStr cfg.title}',
titleURL = '${escapeStr cfg.titleUrl}',
buildbotURL = '${escapeStr cfg.buildbotUrl}',
@@ -155,10 +155,20 @@ in {
description = "Specifies the Buildbot directory.";
};
- bpPort = mkOption {
+ pbPort = mkOption {
default = 9989;
- type = types.int;
- description = "Port where the master will listen to Buildbot Worker.";
+ type = types.either types.str types.int;
+ example = "'tcp:9990:interface=127.0.0.1'";
+ description = ''
+ The buildmaster will listen on a TCP port of your choosing
+ for connections from workers.
+ It can also use this port for connections from remote Change Sources,
+ status clients, and debug tools.
+ This port should be visible to the outside world, and you’ll need to tell
+ your worker admins about your choice.
+ If put in (single) quotes, this can also be used as a connection string,
+ as defined in the <link xlink:href="https://twistedmatrix.com/documents/current/core/howto/endpoints.html">ConnectionStrings guide</link>.
+ '';
};
listenAddress = mkOption {
@@ -264,5 +274,9 @@ in {
};
};
+ imports = [
+ (mkRenamedOptionModule [ "services" "buildbot-master" "bpPort" ] [ "services" "buildbot-master" "pbPort" ])
+ ];
+
meta.maintainers = with lib.maintainers; [ nand0p mic92 ];
}
diff --git a/nixpkgs/nixos/modules/services/misc/freeswitch.nix b/nixpkgs/nixos/modules/services/misc/freeswitch.nix
index d27dbe220d3..b42f36e8663 100644
--- a/nixpkgs/nixos/modules/services/misc/freeswitch.nix
+++ b/nixpkgs/nixos/modules/services/misc/freeswitch.nix
@@ -95,9 +95,11 @@ in {
-conf ${configPath} \\
-base /var/lib/freeswitch";
ExecReload = "${pkg}/bin/fs_cli -x reloadxml";
- Restart = "always";
+ Restart = "on-failure";
RestartSec = "5s";
+ CPUSchedulingPolicy = "fifo";
};
};
+ environment.systemPackages = [ pkg ];
};
}
diff --git a/nixpkgs/nixos/modules/services/misc/gitlab.nix b/nixpkgs/nixos/modules/services/misc/gitlab.nix
index 7b2bbf89a44..1ada131bd7b 100644
--- a/nixpkgs/nixos/modules/services/misc/gitlab.nix
+++ b/nixpkgs/nixos/modules/services/misc/gitlab.nix
@@ -43,6 +43,9 @@ let
[gitlab-shell]
dir = "${cfg.packages.gitlab-shell}"
+ secret_file = "${cfg.statePath}/gitlab_shell_secret"
+ gitlab_url = "http+unix://${pathUrlQuote gitlabSocket}"
+ http_settings = { self_signed_cert = false }
${concatStringsSep "\n" (attrValues (mapAttrs (k: v: ''
[[storage]]
diff --git a/nixpkgs/nixos/modules/services/misc/home-assistant.nix b/nixpkgs/nixos/modules/services/misc/home-assistant.nix
index 86033d02bf3..8ce2437841b 100644
--- a/nixpkgs/nixos/modules/services/misc/home-assistant.nix
+++ b/nixpkgs/nixos/modules/services/misc/home-assistant.nix
@@ -11,9 +11,9 @@ let
(recursiveUpdate defaultConfig cfg.config) else cfg.config));
configFile = pkgs.runCommand "configuration.yaml" { preferLocalBuild = true; } ''
${pkgs.remarshal}/bin/json2yaml -i ${configJSON} -o $out
- # Hack to support secrets, that are encoded as custom yaml objects,
- # https://www.home-assistant.io/docs/configuration/secrets/
- sed -i -e "s/'\!secret \(.*\)'/\!secret \1/" $out
+ # Hack to support custom yaml objects,
+ # i.e. secrets: https://www.home-assistant.io/docs/configuration/secrets/
+ sed -i -e "s/'\!\([a-z_]\+\) \(.*\)'/\!\1 \2/;s/^\!\!/\!/;" $out
'';
lovelaceConfigJSON = pkgs.writeText "ui-lovelace.json"
@@ -120,7 +120,9 @@ in {
unit_system = "metric";
time_zone = "UTC";
};
- frontend = { };
+ frontend = {
+ themes = "!include_dir_merge_named themes";
+ };
http = { };
feedreader.urls = [ "https://nixos.org/blogs.xml" ];
}
diff --git a/nixpkgs/nixos/modules/services/misc/nix-daemon.nix b/nixpkgs/nixos/modules/services/misc/nix-daemon.nix
index 2577cb78e96..0b3d7f3f03c 100644
--- a/nixpkgs/nixos/modules/services/misc/nix-daemon.nix
+++ b/nixpkgs/nixos/modules/services/misc/nix-daemon.nix
@@ -442,6 +442,12 @@ in
nix.binaryCachePublicKeys = [ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" ];
nix.binaryCaches = [ "https://cache.nixos.org/" ];
+ environment.systemPackages =
+ [ nix
+ pkgs.nix-info
+ ]
+ ++ optional (config.programs.bash.enableCompletion && !versionAtLeast nixVersion "2.4pre") pkgs.nix-bash-completions;
+
environment.etc."nix/nix.conf".source = nixConf;
environment.etc."nix/registry.json".text = builtins.toJSON {
diff --git a/nixpkgs/nixos/modules/services/system/cgmanager.nix b/nixpkgs/nixos/modules/services/system/cgmanager.nix
deleted file mode 100644
index d3d57aa7692..00000000000
--- a/nixpkgs/nixos/modules/services/system/cgmanager.nix
+++ /dev/null
@@ -1,26 +0,0 @@
-{ config, lib, pkgs, ... }:
-
-with lib;
-
-let
- cfg = config.services.cgmanager;
-in {
- meta.maintainers = [ maintainers.mic92 ];
-
- ###### interface
- options.services.cgmanager.enable = mkEnableOption "cgmanager";
-
- ###### implementation
- config = mkIf cfg.enable {
- systemd.services.cgmanager = {
- wantedBy = [ "multi-user.target" ];
- description = "Cgroup management daemon";
- restartIfChanged = false;
- serviceConfig = {
- ExecStart = "${pkgs.cgmanager}/bin/cgmanager -m name=systemd";
- KillMode = "process";
- Restart = "on-failure";
- };
- };
- };
-}
diff --git a/nixpkgs/nixos/modules/system/boot/loader/grub/grub.nix b/nixpkgs/nixos/modules/system/boot/loader/grub/grub.nix
index c775632a4aa..67e8bf6fd65 100644
--- a/nixpkgs/nixos/modules/system/boot/loader/grub/grub.nix
+++ b/nixpkgs/nixos/modules/system/boot/loader/grub/grub.nix
@@ -60,7 +60,7 @@ let
inherit (efi) canTouchEfiVariables;
inherit (cfg)
version extraConfig extraPerEntryConfig extraEntries forceInstall useOSProber
- extraEntriesBeforeNixOS extraPrepareConfig extraInitrd configurationLimit copyKernels
+ extraEntriesBeforeNixOS extraPrepareConfig configurationLimit copyKernels
default fsIdentifier efiSupport efiInstallAsRemovable gfxmodeEfi gfxmodeBios gfxpayloadEfi gfxpayloadBios;
path = with pkgs; makeBinPath (
[ coreutils gnused gnugrep findutils diffutils btrfs-progs utillinux mdadm ]
@@ -292,19 +292,6 @@ in
'';
};
- extraInitrd = mkOption {
- type = types.nullOr types.path;
- default = null;
- example = "/boot/extra_initramfs.gz";
- description = ''
- The path to a second initramfs to be supplied to the kernel.
- This ramfs will not be copied to the store, so that it can
- contain secrets such as LUKS keyfiles or ssh keys.
- This implies that rolling back to a previous configuration
- won't rollback the state of this file.
- '';
- };
-
useOSProber = mkOption {
default = false;
type = types.bool;
@@ -608,6 +595,8 @@ in
{ path = "/boot"; inherit (cfg) devices; inherit (efi) efiSysMountPoint; }
];
+ boot.loader.supportsInitrdSecrets = true;
+
system.build.installBootLoader =
let
install-grub-pl = pkgs.substituteAll {
@@ -705,6 +694,24 @@ in
(mkRenamedOptionModule [ "boot" "grubDevice" ] [ "boot" "loader" "grub" "device" ])
(mkRenamedOptionModule [ "boot" "bootMount" ] [ "boot" "loader" "grub" "bootDevice" ])
(mkRenamedOptionModule [ "boot" "grubSplashImage" ] [ "boot" "loader" "grub" "splashImage" ])
+ (mkRemovedOptionModule [ "boot" "loader" "grub" "extraInitrd" ] ''
+ This option has been replaced with the bootloader agnostic
+ boot.initrd.secrets option. To migrate to the initrd secrets system,
+ extract the extraInitrd archive into your main filesystem:
+
+ # zcat /boot/extra_initramfs.gz | cpio -idvmD /etc/secrets/initrd
+ /path/to/secret1
+ /path/to/secret2
+
+ then replace boot.loader.grub.extraInitrd with boot.initrd.secrets:
+
+ boot.initrd.secrets = {
+ "/path/to/secret1" = "/etc/secrets/initrd/path/to/secret1";
+ "/path/to/secret2" = "/etc/secrets/initrd/path/to/secret2";
+ };
+
+ See the boot.initrd.secrets option documentation for more information.
+ '')
];
}
diff --git a/nixpkgs/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixpkgs/nixos/modules/system/boot/loader/grub/install-grub.pl
index 8df18cbd901..e469b18abd0 100644
--- a/nixpkgs/nixos/modules/system/boot/loader/grub/install-grub.pl
+++ b/nixpkgs/nixos/modules/system/boot/loader/grub/install-grub.pl
@@ -49,7 +49,6 @@ my $extraPrepareConfig = get("extraPrepareConfig");
my $extraPerEntryConfig = get("extraPerEntryConfig");
my $extraEntries = get("extraEntries");
my $extraEntriesBeforeNixOS = get("extraEntriesBeforeNixOS") eq "true";
-my $extraInitrd = get("extraInitrd");
my $splashImage = get("splashImage");
my $splashMode = get("splashMode");
my $backgroundColor = get("backgroundColor");
@@ -232,13 +231,6 @@ my $grubStore;
if ($copyKernels == 0) {
$grubStore = GrubFs($storePath);
}
-my $extraInitrdPath;
-if ($extraInitrd) {
- if (! -f $extraInitrd) {
- print STDERR "Warning: the specified extraInitrd " . $extraInitrd . " doesn't exist. Your system won't boot without it.\n";
- }
- $extraInitrdPath = GrubFs($extraInitrd);
-}
# Generate the header.
my $conf .= "# Automatically generated. DO NOT EDIT THIS FILE!\n";
@@ -363,9 +355,30 @@ sub addEntry {
my $kernel = copyToKernelsDir(Cwd::abs_path("$path/kernel"));
my $initrd = copyToKernelsDir(Cwd::abs_path("$path/initrd"));
- if ($extraInitrd) {
- $initrd .= " " .$extraInitrdPath->path;
+
+ # Include second initrd with secrets
+ if (-e -x "$path/append-initrd-secrets") {
+ my $initrdName = basename($initrd);
+ my $initrdSecretsPath = "$bootPath/kernels/$initrdName-secrets";
+
+ mkpath(dirname($initrdSecretsPath), 0, 0755);
+ my $oldUmask = umask;
+ # Make sure initrd is not world readable (won't work if /boot is FAT)
+ umask 0137;
+ my $initrdSecretsPathTemp = File::Temp::mktemp("$initrdSecretsPath.XXXXXXXX");
+ system("$path/append-initrd-secrets", $initrdSecretsPathTemp) == 0 or die "failed to create initrd secrets\n";
+ # Check whether any secrets were actually added
+ if (-e $initrdSecretsPathTemp && ! -z _) {
+ rename $initrdSecretsPathTemp, $initrdSecretsPath or die "failed to move initrd secrets into place\n";
+ $copied{$initrdSecretsPath} = 1;
+ $initrd .= " " . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/kernels/$initrdName-secrets";
+ } else {
+ unlink $initrdSecretsPathTemp;
+ rmdir dirname($initrdSecretsPathTemp);
+ }
+ umask $oldUmask;
}
+
my $xen = -e "$path/xen.gz" ? copyToKernelsDir(Cwd::abs_path("$path/xen.gz")) : undef;
# FIXME: $confName
@@ -388,9 +401,6 @@ sub addEntry {
if ($copyKernels == 0) {
$conf .= $grubStore->search . "\n";
}
- if ($extraInitrd) {
- $conf .= $extraInitrdPath->search . "\n";
- }
$conf .= " $extraPerEntryConfig\n" if $extraPerEntryConfig;
$conf .= " multiboot $xen $xenParams\n" if $xen;
$conf .= " " . ($xen ? "module" : "linux") . " $kernel $kernelParams\n";
diff --git a/nixpkgs/nixos/modules/system/boot/stage-1.nix b/nixpkgs/nixos/modules/system/boot/stage-1.nix
index dfd158e2d75..9bf3228d1ad 100644
--- a/nixpkgs/nixos/modules/system/boot/stage-1.nix
+++ b/nixpkgs/nixos/modules/system/boot/stage-1.nix
@@ -517,8 +517,7 @@ in
};
boot.initrd.secrets = mkOption
- { internal = true;
- default = {};
+ { default = {};
type = types.attrsOf (types.nullOr types.path);
description =
''
diff --git a/nixpkgs/nixos/modules/tasks/network-interfaces.nix b/nixpkgs/nixos/modules/tasks/network-interfaces.nix
index a2811104944..78d66966949 100644
--- a/nixpkgs/nixos/modules/tasks/network-interfaces.nix
+++ b/nixpkgs/nixos/modules/tasks/network-interfaces.nix
@@ -381,7 +381,7 @@ in
# syntax). Note: We also allow underscores for compatibility/legacy
# reasons (as undocumented feature):
type = types.strMatching
- "^[[:alpha:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$";
+ "^$|^[[:alpha:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$";
description = ''
The name of the machine. Leave it empty if you want to obtain it from a
DHCP server (if using DHCP). The hostname must be a valid DNS label (see
diff --git a/nixpkgs/nixos/tests/mysql/mysql.nix b/nixpkgs/nixos/tests/mysql/mysql.nix
index d236ce94632..50e1c76e9fd 100644
--- a/nixpkgs/nixos/tests/mysql/mysql.nix
+++ b/nixpkgs/nixos/tests/mysql/mysql.nix
@@ -5,20 +5,34 @@ import ./../make-test-python.nix ({ pkgs, ...} : {
};
nodes = {
- mysql =
+ mysql57 =
{ pkgs, ... }:
{
+ users.users.testuser = { };
+ users.users.testuser2 = { };
services.mysql.enable = true;
services.mysql.initialDatabases = [
- { name = "testdb"; schema = ./testdb.sql; }
- { name = "empty_testdb"; }
+ { name = "testdb3"; schema = ./testdb.sql; }
];
# note that using pkgs.writeText here is generally not a good idea,
# as it will store the password in world-readable /nix/store ;)
services.mysql.initialScript = pkgs.writeText "mysql-init.sql" ''
- CREATE USER 'passworduser'@'localhost' IDENTIFIED BY 'password123';
+ CREATE USER 'testuser3'@'localhost' IDENTIFIED BY 'secure';
+ GRANT ALL PRIVILEGES ON testdb3.* TO 'testuser3'@'localhost';
'';
+ services.mysql.ensureDatabases = [ "testdb" "testdb2" ];
+ services.mysql.ensureUsers = [{
+ name = "testuser";
+ ensurePermissions = {
+ "testdb.*" = "ALL PRIVILEGES";
+ };
+ } {
+ name = "testuser2";
+ ensurePermissions = {
+ "testdb2.*" = "ALL PRIVILEGES";
+ };
+ }];
services.mysql.package = pkgs.mysql57;
};
@@ -30,16 +44,30 @@ import ./../make-test-python.nix ({ pkgs, ...} : {
# Kernel panic - not syncing: Out of memory: compulsory panic_on_oom is enabled
virtualisation.memorySize = 1024;
+ users.users.testuser = { };
+ users.users.testuser2 = { };
services.mysql.enable = true;
services.mysql.initialDatabases = [
- { name = "testdb"; schema = ./testdb.sql; }
- { name = "empty_testdb"; }
+ { name = "testdb3"; schema = ./testdb.sql; }
];
# note that using pkgs.writeText here is generally not a good idea,
# as it will store the password in world-readable /nix/store ;)
services.mysql.initialScript = pkgs.writeText "mysql-init.sql" ''
- CREATE USER 'passworduser'@'localhost' IDENTIFIED BY 'password123';
+ CREATE USER 'testuser3'@'localhost' IDENTIFIED BY 'secure';
+ GRANT ALL PRIVILEGES ON testdb3.* TO 'testuser3'@'localhost';
'';
+ services.mysql.ensureDatabases = [ "testdb" "testdb2" ];
+ services.mysql.ensureUsers = [{
+ name = "testuser";
+ ensurePermissions = {
+ "testdb.*" = "ALL PRIVILEGES";
+ };
+ } {
+ name = "testuser2";
+ ensurePermissions = {
+ "testdb2.*" = "ALL PRIVILEGES";
+ };
+ }];
services.mysql.package = pkgs.mysql80;
};
@@ -81,17 +109,49 @@ import ./../make-test-python.nix ({ pkgs, ...} : {
testScript = ''
start_all()
- mysql.wait_for_unit("mysql")
- mysql.succeed("echo 'use empty_testdb;' | mysql -u root")
- mysql.succeed("echo 'use testdb; select * from tests;' | mysql -u root -N | grep 4")
- # ';' acts as no-op, just check whether login succeeds with the user created from the initialScript
- mysql.succeed("echo ';' | mysql -u passworduser --password=password123")
+ mysql57.wait_for_unit("mysql")
+ mysql57.succeed(
+ "echo 'use testdb; create table tests (test_id INT, PRIMARY KEY (test_id));' | sudo -u testuser mysql -u testuser"
+ )
+ mysql57.succeed(
+ "echo 'use testdb; insert into tests values (41);' | sudo -u testuser mysql -u testuser"
+ )
+ # Ensure testuser2 is not able to insert into testdb as mysql testuser2
+ mysql57.fail(
+ "echo 'use testdb; insert into tests values (22);' | sudo -u testuser2 mysql -u testuser2"
+ )
+ # Ensure testuser2 is not able to authenticate as mysql testuser
+ mysql57.fail(
+ "echo 'use testdb; insert into tests values (22);' | sudo -u testuser2 mysql -u testuser"
+ )
+ mysql57.succeed(
+ "echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 41"
+ )
+ mysql57.succeed(
+ "echo 'use testdb3; select * from tests;' | mysql -u testuser3 --password=secure -N | grep 4"
+ )
mysql80.wait_for_unit("mysql")
- mysql80.succeed("echo 'use empty_testdb;' | mysql -u root")
- mysql80.succeed("echo 'use testdb; select * from tests;' | mysql -u root -N | grep 4")
- # ';' acts as no-op, just check whether login succeeds with the user created from the initialScript
- mysql80.succeed("echo ';' | mysql -u passworduser --password=password123")
+ mysql80.succeed(
+ "echo 'use testdb; create table tests (test_id INT, PRIMARY KEY (test_id));' | sudo -u testuser mysql -u testuser"
+ )
+ mysql80.succeed(
+ "echo 'use testdb; insert into tests values (41);' | sudo -u testuser mysql -u testuser"
+ )
+ # Ensure testuser2 is not able to insert into testdb as mysql testuser2
+ mysql80.fail(
+ "echo 'use testdb; insert into tests values (22);' | sudo -u testuser2 mysql -u testuser2"
+ )
+ # Ensure testuser2 is not able to authenticate as mysql testuser
+ mysql80.fail(
+ "echo 'use testdb; insert into tests values (22);' | sudo -u testuser2 mysql -u testuser"
+ )
+ mysql80.succeed(
+ "echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 41"
+ )
+ mysql80.succeed(
+ "echo 'use testdb3; select * from tests;' | mysql -u testuser3 --password=secure -N | grep 4"
+ )
mariadb.wait_for_unit("mysql")
mariadb.succeed(