From a90859fb75a4e77ef98dbb21110ef2afe833b6a2 Mon Sep 17 00:00:00 2001 From: Norbert Melzer Date: Mon, 13 Mar 2023 22:08:30 +0100 Subject: [PATCH] feature move sudo-activation to switcher module --- nixos/configurations/mimas.nix | 23 ----------------------- nixos/modules/switcher.nix | 32 +++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/nixos/configurations/mimas.nix b/nixos/configurations/mimas.nix index d23ed049..02236a45 100644 --- a/nixos/configurations/mimas.nix +++ b/nixos/configurations/mimas.nix @@ -221,29 +221,6 @@ in { }; security.sudo.extraConfig = "Defaults passwd_timeout=0"; - security.sudo.extraRules = let - storePrefix = "/nix/store/*"; - systemName = "nixos-system-${config.networking.hostName}-*"; - in [ - { - commands = [ - { - command = "${storePrefix}-nix-*/bin/nix-env -p /nix/var/nix/profiles/system --set ${storePrefix}-${systemName}"; - options = ["NOPASSWD"]; - } - ]; - groups = ["wheel"]; - } - { - commands = [ - { - command = "${storePrefix}-${systemName}/bin/switch-to-configuration"; - options = ["NOPASSWD"]; - } - ]; - groups = ["wheel"]; - } - ]; # services.wakeonlan.interfaces = [ # { diff --git a/nixos/modules/switcher.nix b/nixos/modules/switcher.nix index 6745241b..7f24afe8 100644 --- a/nixos/modules/switcher.nix +++ b/nixos/modules/switcher.nix @@ -1,3 +1,33 @@ -{self, ...}: {pkgs, ...}: { +{self, ...}: { + pkgs, + config, + ... +}: { + _file = ./switcher.nix; + environment.systemPackages = [self.packages."${pkgs.system}".switcher]; + + security.sudo.extraRules = let + storePrefix = "/nix/store/*"; + systemName = "nixos-system-${config.networking.hostName}-*"; + in [ + { + commands = [ + { + command = "${storePrefix}-nix-*/bin/nix-env -p /nix/var/nix/profiles/system --set ${storePrefix}-${systemName}"; + options = ["NOPASSWD"]; + } + ]; + groups = ["wheel"]; + } + { + commands = [ + { + command = "${storePrefix}-${systemName}/bin/switch-to-configuration"; + options = ["NOPASSWD"]; + } + ]; + groups = ["wheel"]; + } + ]; } -- 2.51.2