1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00

add service module for system activation

This commit is contained in:
Daiderd Jordan 2016-12-04 10:38:21 +01:00
parent 9a5af2ee4a
commit 7b3ace08c5
No known key found for this signature in database
GPG key ID: D02435D05B810C96
4 changed files with 58 additions and 18 deletions

View file

@ -14,6 +14,7 @@ let
./modules/system/launchd.nix
./modules/environment
./modules/launchd
./modules/services/activate-system.nix
./modules/programs/tmux.nix
];
};
@ -36,10 +37,7 @@ let
pkgs.nox
];
launchd.daemons.activate-system =
{ serviceConfig.Program = "${config.system.build.activate}";
serviceConfig.RunAtLoad = true;
};
services.activate-system.enable = true;
launchd.daemons.nix-daemon =
{ serviceConfig.Program = "/nix/var/nix/profiles/default/bin/nix-daemon";
@ -121,7 +119,7 @@ let
'build') nix-build '<nixpkgs>' -A nixdarwin.toplevel "$@" ;;
'repl') nix-repl "$HOME/.nixpkgs/config.nix" "$@" ;;
'shell') nix-shell '<nixpkgs>' -p nixdarwin.toplevel --run '${pkgs.lnl.zsh}/bin/zsh -l' "$@" ;;
'switch') sudo nix-env --profile /nix/var/nix/profiles/system --set $(nix-build --no-out-link '<nixpkgs>' -A nixdarwin.toplevel) && nix-shell '<nixpkgs>' -A nixdarwin.toplevel --run 'sudo $out/activate' && exec ${pkgs.lnl.zsh}/bin/zsh -l ;;
'switch') sudo nix-env --profile ${config.system.profile} --set $(nix-build --no-out-link '<nixpkgs>' -A nixdarwin.toplevel) && nix-shell '<nixpkgs>' -A nixdarwin.toplevel --run 'sudo $out/activate' && exec ${pkgs.lnl.zsh}/bin/zsh -l ;;
esac
}

View file

@ -0,0 +1,47 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.activate-system;
activateScript = pkgs.writeScript "activate-system" ''
#! ${pkgs.stdenv.shell}
# Make this configuration the current configuration.
# The readlink is there to ensure that when $systemConfig = /system
# (which is a symlink to the store), /run/current-system is still
# used as a garbage collection root.
ln -sfn $(cat ${config.system.profile}/systemConfig) /run/current-system
# Prevent the current configuration from being garbage-collected.
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
'';
in
{
options = {
services.activate-system = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to activate system at boot time.
'';
};
};
};
config = {
launchd.daemons.activate-system = mkIf cfg.enable {
serviceConfig.Program = "${activateScript}";
serviceConfig.RunAtLoad = true;
};
};
}

View file

@ -34,19 +34,6 @@ in
config = {
system.build.activate = pkgs.writeScript "activate-system" ''
#! ${pkgs.stdenv.shell}
# Make this configuration the current configuration.
# The readlink is there to ensure that when $systemConfig = /system
# (which is a symlink to the store), /run/current-system is still
# used as a garbage collection root.
ln -sfn $(cat /nix/var/nix/profiles/system/systemConfig) /run/current-system
# Prevent the current configuration from being garbage-collected.
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
'';
system.activationScripts.script.text = ''
#! ${pkgs.stdenv.shell}

View file

@ -27,6 +27,14 @@ in
'';
};
system.profile = mkOption {
type = types.path;
default = "/nix/var/nix/profiles/system";
description = ''
Profile to use for the system.
'';
};
system.nixdarwinLabel = mkOption {
type = types.str;
default = "16.09";