mirror of
https://github.com/nix-community/nix-on-droid.git
synced 2025-11-08 11:36:07 +01:00
Add modules
This commit is contained in:
parent
5cc656fffc
commit
f40362898a
19 changed files with 1045 additions and 0 deletions
112
modules/build/activation.nix
Normal file
112
modules/build/activation.nix
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
# Licensed under GNU Lesser General Public License v3 or later, see COPYING.
|
||||
# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS.
|
||||
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.build;
|
||||
|
||||
# Programs that always should be available on the activation
|
||||
# script's PATH.
|
||||
activationBinPaths = lib.makeBinPath [
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
pkgs.findutils
|
||||
pkgs.gnused
|
||||
pkgs.ncurses # For `tput`.
|
||||
pkgs.nix
|
||||
];
|
||||
|
||||
activationCmds = concatStringsSep "\n" (
|
||||
mapAttrsToList (name: value: ''
|
||||
noteEcho "Activating ${name}"
|
||||
${value}
|
||||
'') cfg.activation
|
||||
);
|
||||
|
||||
activationScript = pkgs.writeScript "activation-script" ''
|
||||
#!${pkgs.runtimeShell}
|
||||
|
||||
set -eu
|
||||
set -o pipefail
|
||||
|
||||
cd $HOME
|
||||
|
||||
export PATH="${activationBinPaths}"
|
||||
|
||||
${builtins.readFile ../lib-bash/color-echo.sh}
|
||||
${builtins.readFile ../lib-bash/activation-init.sh}
|
||||
|
||||
${activationCmds}
|
||||
'';
|
||||
in
|
||||
|
||||
{
|
||||
|
||||
###### interface
|
||||
|
||||
options = {
|
||||
|
||||
build = {
|
||||
activation = mkOption {
|
||||
default = {};
|
||||
type = types.attrs;
|
||||
description = ''
|
||||
Activation scripts for the nix-on-droid environment.
|
||||
</para><para>
|
||||
Any script should respect the <varname>DRY_RUN</varname>
|
||||
variable, if it is set then no actual action should be taken.
|
||||
The variable <varname>DRY_RUN_CMD</varname> is set to
|
||||
<code>echo</code> if dry run is enabled. Thus, many cases you
|
||||
can use the idiom <code>$DRY_RUN_CMD rm -rf /</code>.
|
||||
'';
|
||||
};
|
||||
|
||||
activationPackage = mkOption {
|
||||
type = types.package;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
description = "Derivation with activation script.";
|
||||
};
|
||||
|
||||
etc = mkOption {
|
||||
type = types.package;
|
||||
internal = true;
|
||||
description = "Package containing /etc files.";
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
###### implementation
|
||||
|
||||
config = {
|
||||
|
||||
build.activationPackage =
|
||||
pkgs.runCommand
|
||||
"nix-on-droid-generation"
|
||||
{
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
}
|
||||
''
|
||||
mkdir --parents $out/filesystem/{bin,usr/{bin,lib}}
|
||||
|
||||
cp ${activationScript} $out/activate
|
||||
|
||||
ln --symbolic ${config.build.etc}/etc $out/etc
|
||||
ln --symbolic ${config.environment.path} $out/nix-on-droid-path
|
||||
|
||||
ln --symbolic ${config.environment.files.login} $out/filesystem/bin/login
|
||||
ln --symbolic ${config.environment.files.loginInner} $out/filesystem/usr/lib/login-inner
|
||||
|
||||
ln --symbolic ${config.environment.binSh} $out/filesystem/bin/sh
|
||||
ln --symbolic ${config.environment.usrBinEnv} $out/filesystem/usr/bin/env
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue