8.nix-darwin/modules/system/default.nix
Emily e65131e69c treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]; thanks
to @pennae for writing this tool! It automatically checks that the
resulting documentation doesn't change, although my fork loosens
this a little to ignore some irrelevant whitespace and typographical
differences.

As of this commit there is no DocBook remaining in the options
documentation.

You can play along at home if you want to reproduce this commit:

    $ NIX_PATH=nixpkgs=flake:nixpkgs/c1bca7fe84c646cfd4ebf3482c0e6317a0b13f22 \
      nix shell nixpkgs#coreutils \
      -c find . -name '*.nix' \
      -exec nix run github:emilazy/nix-doc-munge/0a7190f600027bf7baf6cb7139e4d69ac2f51062 \
      {} +

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge
2023-06-24 10:48:55 +01:00

120 lines
3.4 KiB
Nix
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{ config, lib, pkgs, ... }:
with lib;
let
inherit (pkgs) stdenvNoCC;
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
{
options = {
system.build = mkOption {
internal = true;
type = types.attrsOf types.unspecified;
default = {};
description = lib.mdDoc ''
Attribute set of derivation used to setup the system.
'';
};
system.path = mkOption {
internal = true;
type = types.package;
description = lib.mdDoc ''
The packages you want in the system environment.
'';
};
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.
'';
};
};
config = {
system.build.toplevel = throwAssertions (showWarnings (stdenvNoCC.mkDerivation {
name = "darwin-system-${cfg.darwinLabel}";
preferLocalBuild = true;
activationScript = cfg.activationScripts.script.text;
activationUserScript = cfg.activationScripts.userScript.text;
inherit (cfg) darwinLabel;
buildCommand = ''
mkdir $out
systemConfig=$out
mkdir -p $out/darwin
cp -f ${../../CHANGELOG} $out/darwin-changes
ln -s ${cfg.build.patches}/patches $out/patches
ln -s ${cfg.build.etc}/etc $out/etc
ln -s ${cfg.path} $out/sw
mkdir -p $out/Library
ln -s ${cfg.build.applications}/Applications $out/Applications
ln -s ${cfg.build.fonts}/Library/Fonts $out/Library/Fonts
ln -s ${cfg.build.launchd}/Library/LaunchAgents $out/Library/LaunchAgents
ln -s ${cfg.build.launchd}/Library/LaunchDaemons $out/Library/LaunchDaemons
mkdir -p $out/user/Library
ln -s ${cfg.build.launchd}/user/Library/LaunchAgents $out/user/Library/LaunchAgents
echo "$activationScript" > $out/activate
substituteInPlace $out/activate --subst-var out
chmod u+x $out/activate
unset activationScript
echo "$activationUserScript" > $out/activate-user
substituteInPlace $out/activate-user --subst-var out
chmod u+x $out/activate-user
unset activationUserScript
echo -n "$systemConfig" > $out/systemConfig
echo -n "$darwinLabel" > $out/darwin-version
echo -n "$system" > $out/system
'';
}));
};
}