1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-15 17:51:01 +00:00
nix-darwin/modules/system/default.nix

121 lines
3.4 KiB
Nix
Raw Normal View History

2016-10-18 21:14:18 +00:00
{ config, lib, pkgs, ... }:
with lib;
let
2016-12-07 22:06:18 +00:00
inherit (pkgs) stdenvNoCC;
2016-10-18 21:14:18 +00:00
cfg = config.system;
failedAssertions = map (x: x.message) (filter (x: !x.assertion) config.assertions);
throwAssertions = res: if (failedAssertions != []) then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}" else res;
showWarnings = res: fold (w: x: builtins.trace "warning: ${w}" x) res config.warnings;
in
2016-11-01 20:25:22 +00:00
{
2016-10-18 21:14:18 +00:00
options = {
system.build = mkOption {
internal = true;
type = types.attrsOf types.unspecified;
2016-10-18 21:14:18 +00:00
default = {};
description = lib.mdDoc ''
2016-10-18 21:14:18 +00:00
Attribute set of derivation used to setup the system.
'';
};
2016-10-19 18:03:17 +00:00
system.path = mkOption {
2016-10-18 21:14:18 +00:00
internal = true;
2016-10-19 18:03:17 +00:00
type = types.package;
description = lib.mdDoc ''
2016-10-19 18:03:17 +00:00
The packages you want in the system environment.
'';
2016-10-18 21:14:18 +00:00
};
system.profile = mkOption {
type = types.path;
default = "/nix/var/nix/profiles/system";
description = lib.mdDoc ''
Profile to use for the system.
'';
};
assertions = mkOption {
type = types.listOf types.unspecified;
internal = true;
default = [];
example = [ { assertion = false; message = "you can't enable this for that reason"; } ];
description = lib.mdDoc ''
This option allows modules to express conditions that must
hold for the evaluation of the system configuration to
succeed, along with associated error messages for the user.
'';
};
warnings = mkOption {
internal = true;
default = [];
type = types.listOf types.str;
example = [ "The `foo' service is deprecated and will go away soon!" ];
description = lib.mdDoc ''
This option allows modules to show warnings to users during
the evaluation of the system configuration.
'';
};
2016-10-18 21:14:18 +00:00
};
config = {
system.build.toplevel = throwAssertions (showWarnings (stdenvNoCC.mkDerivation {
name = "darwin-system-${cfg.darwinLabel}";
2016-10-29 20:40:55 +00:00
preferLocalBuild = true;
2016-11-01 20:25:22 +00:00
activationScript = cfg.activationScripts.script.text;
2016-12-14 11:32:20 +00:00
activationUserScript = cfg.activationScripts.userScript.text;
inherit (cfg) darwinLabel;
2016-10-29 20:40:55 +00:00
buildCommand = ''
mkdir $out
2016-12-02 22:54:46 +00:00
systemConfig=$out
mkdir -p $out/darwin
cp -f ${../../CHANGELOG} $out/darwin-changes
2020-05-26 21:15:07 +00:00
ln -s ${cfg.build.patches}/patches $out/patches
2016-10-29 20:40:55 +00:00
ln -s ${cfg.build.etc}/etc $out/etc
ln -s ${cfg.path} $out/sw
2016-11-07 20:00:23 +00:00
mkdir -p $out/Library
ln -s ${cfg.build.applications}/Applications $out/Applications
ln -s ${cfg.build.fonts}/Library/Fonts $out/Library/Fonts
2017-01-25 21:35:06 +00:00
ln -s ${cfg.build.launchd}/Library/LaunchAgents $out/Library/LaunchAgents
2016-11-07 20:00:23 +00:00
ln -s ${cfg.build.launchd}/Library/LaunchDaemons $out/Library/LaunchDaemons
2017-05-11 21:43:05 +00:00
mkdir -p $out/user/Library
ln -s ${cfg.build.launchd}/user/Library/LaunchAgents $out/user/Library/LaunchAgents
2016-10-29 20:40:55 +00:00
echo "$activationScript" > $out/activate
substituteInPlace $out/activate --subst-var out
chmod u+x $out/activate
unset activationScript
2016-12-14 11:32:20 +00:00
echo "$activationUserScript" > $out/activate-user
substituteInPlace $out/activate-user --subst-var out
chmod u+x $out/activate-user
unset activationUserScript
2016-12-02 22:54:46 +00:00
echo -n "$systemConfig" > $out/systemConfig
echo -n "$darwinLabel" > $out/darwin-version
2016-10-29 20:40:55 +00:00
echo -n "$system" > $out/system
'';
}));
2016-10-18 21:14:18 +00:00
};
}