2010-09-03 21:10:50 +02:00
|
|
|
#! @shell@ -e
|
|
|
|
|
|
|
|
# Allow the location of NixOS sources and the system configuration
|
|
|
|
# file to be overridden.
|
2010-09-26 00:29:50 +02:00
|
|
|
|
|
|
|
: ${mountPoint=/mnt}
|
2010-09-03 21:10:50 +02:00
|
|
|
: ${NIXOS_CONFIG=/etc/nixos/configuration.nix}
|
2012-03-13 10:36:41 +01:00
|
|
|
export NIXOS_CONFIG
|
2010-09-03 21:10:50 +02:00
|
|
|
|
|
|
|
usage () {
|
|
|
|
echo 1>&2 "
|
2012-05-14 03:56:42 +02:00
|
|
|
Usage: $0 [-v] [-d] [-l] [--xml] OPTION_NAME
|
|
|
|
$0 --install
|
2010-09-03 21:10:50 +02:00
|
|
|
|
2012-05-14 03:56:42 +02:00
|
|
|
This program allows you to inspect the current value of NixOS
|
|
|
|
configuration options. It can also generate a basic NixOS
|
|
|
|
configuration file.
|
2010-09-03 21:10:50 +02:00
|
|
|
|
|
|
|
Options:
|
|
|
|
|
2012-05-14 03:56:42 +02:00
|
|
|
-i | --install Write a template NixOS configuration file to
|
|
|
|
${mountPoint:+$mountPoint/}$NIXOS_CONFIG.
|
2010-09-03 21:10:50 +02:00
|
|
|
-v | --value Display the current value, based on your
|
|
|
|
configuration.
|
2010-09-26 10:43:55 +02:00
|
|
|
-d | --description Display the default value, the example and the
|
2010-09-03 21:10:50 +02:00
|
|
|
description.
|
|
|
|
-l | --lookup Display where the option is defined and where it
|
|
|
|
is declared.
|
2011-04-24 17:30:25 +02:00
|
|
|
--xml Print an XML representation of the result.
|
|
|
|
Implies -vdl options.
|
2010-09-03 21:10:50 +02:00
|
|
|
--help Show this message.
|
|
|
|
|
2010-09-26 00:29:50 +02:00
|
|
|
Environment variables affecting $0:
|
2010-09-03 21:10:50 +02:00
|
|
|
|
2010-09-26 00:29:50 +02:00
|
|
|
\$mountPoint Path to the target file system.
|
2010-09-03 21:10:50 +02:00
|
|
|
\$NIXOS_CONFIG Path to your configuration file.
|
|
|
|
|
|
|
|
"
|
|
|
|
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# Process Arguments #
|
|
|
|
#####################
|
|
|
|
|
|
|
|
desc=false
|
|
|
|
defs=false
|
|
|
|
value=false
|
2011-04-24 17:30:25 +02:00
|
|
|
xml=false
|
2010-09-26 00:29:50 +02:00
|
|
|
install=false
|
2010-09-03 21:10:50 +02:00
|
|
|
verbose=false
|
|
|
|
|
|
|
|
option=""
|
|
|
|
|
|
|
|
argfun=""
|
|
|
|
for arg; do
|
|
|
|
if test -z "$argfun"; then
|
|
|
|
case $arg in
|
2010-09-26 00:29:50 +02:00
|
|
|
-*)
|
|
|
|
longarg=""
|
|
|
|
sarg="$arg"
|
|
|
|
while test "$sarg" != "-"; do
|
|
|
|
case $sarg in
|
2010-11-09 19:42:59 +01:00
|
|
|
--*) longarg=$arg; sarg="--";;
|
2010-09-26 00:29:50 +02:00
|
|
|
-d*) longarg="$longarg --description";;
|
|
|
|
-v*) longarg="$longarg --value";;
|
|
|
|
-l*) longarg="$longarg --lookup";;
|
|
|
|
-i*) longarg="$longarg --install";;
|
|
|
|
-*) usage;;
|
|
|
|
esac
|
2010-11-09 19:42:59 +01:00
|
|
|
# remove the first letter option
|
2010-09-26 00:29:50 +02:00
|
|
|
sarg="-${sarg#??}"
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*) longarg=$arg;;
|
2010-09-03 21:10:50 +02:00
|
|
|
esac
|
2010-09-26 00:29:50 +02:00
|
|
|
for larg in $longarg; do
|
|
|
|
case $larg in
|
|
|
|
--description) desc=true;;
|
|
|
|
--value) value=true;;
|
|
|
|
--lookup) defs=true;;
|
2011-04-24 17:30:25 +02:00
|
|
|
--xml) xml=true;;
|
2010-09-26 00:29:50 +02:00
|
|
|
--install) install=true;;
|
|
|
|
--verbose) verbose=true;;
|
|
|
|
--help) usage;;
|
|
|
|
-*) usage;;
|
|
|
|
*) if test -z "$option"; then
|
|
|
|
option="$larg"
|
|
|
|
else
|
|
|
|
usage
|
|
|
|
fi;;
|
|
|
|
esac
|
|
|
|
done
|
2010-09-03 21:10:50 +02:00
|
|
|
else
|
|
|
|
case $argfun in
|
|
|
|
set_*)
|
|
|
|
var=$(echo $argfun | sed 's,^set_,,')
|
|
|
|
eval $var=$arg
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
argfun=""
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2011-04-24 17:30:25 +02:00
|
|
|
if $xml; then
|
|
|
|
value=true
|
|
|
|
desc=true
|
|
|
|
defs=true
|
|
|
|
fi
|
|
|
|
|
2010-09-26 00:29:50 +02:00
|
|
|
# --install cannot be used with -d -v -l without option name.
|
|
|
|
if $value || $desc || $defs && $install && test -z "$option"; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
|
|
|
generate=false
|
|
|
|
if ! $defs && ! $desc && ! $value && $install && test -z "$option"; then
|
|
|
|
generate=true
|
|
|
|
fi
|
|
|
|
|
2010-09-03 21:10:50 +02:00
|
|
|
if ! $defs && ! $desc; then
|
|
|
|
value=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
if $verbose; then
|
|
|
|
set -x
|
|
|
|
else
|
|
|
|
set +x
|
|
|
|
fi
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# Process the configuration #
|
|
|
|
#############################
|
|
|
|
|
2011-04-24 17:30:25 +02:00
|
|
|
evalNix(){
|
|
|
|
nix-instantiate - --eval-only "$@"
|
|
|
|
}
|
|
|
|
|
2010-09-03 21:10:50 +02:00
|
|
|
evalAttr(){
|
|
|
|
local prefix=$1
|
|
|
|
local suffix=$2
|
|
|
|
local strict=$3
|
2012-03-13 10:36:41 +01:00
|
|
|
echo "(import <nixos> {}).$prefix${option:+.$option}${suffix:+.$suffix}" |
|
2011-04-24 17:30:25 +02:00
|
|
|
evalNix ${strict:+--strict}
|
2010-09-03 21:10:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
evalOpt(){
|
|
|
|
evalAttr "eval.options" "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
evalCfg(){
|
|
|
|
evalAttr "config" "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
findSources(){
|
|
|
|
local suffix=$1
|
2012-03-13 10:36:41 +01:00
|
|
|
echo "builtins.map (f: f.source) (import <nixos> {}).eval.options${option:+.$option}.$suffix" |
|
2011-04-24 17:30:25 +02:00
|
|
|
evalNix --strict
|
2010-09-03 21:10:50 +02:00
|
|
|
}
|
|
|
|
|
2011-12-29 07:33:34 +01:00
|
|
|
# Given a result from nix-instantiate, recover the list of attributes it
|
|
|
|
# contains.
|
|
|
|
attrNames() {
|
|
|
|
local attributeset=$1
|
|
|
|
# sed is used to replace un-printable subset by 0s, and to remove most of
|
|
|
|
# the inner-attribute set, which reduce the likelyhood to encounter badly
|
|
|
|
# pre-processed input.
|
|
|
|
echo "builtins.attrNames $attributeset" | \
|
|
|
|
sed 's,<[A-Z]*>,0,g; :inner; s/{[^\{\}]*};/0;/g; t inner;' | \
|
|
|
|
evalNix --strict
|
|
|
|
}
|
|
|
|
|
|
|
|
# map a simple list which contains strings or paths.
|
|
|
|
nixMap() {
|
|
|
|
local fun="$1"
|
|
|
|
local list="$2"
|
|
|
|
local elem
|
|
|
|
for elem in $list; do
|
|
|
|
test $elem = '[' -o $elem = ']' && continue;
|
|
|
|
$fun $elem
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2010-09-26 00:29:50 +02:00
|
|
|
if $install; then
|
2012-03-13 10:36:41 +01:00
|
|
|
NIXOS_CONFIG="$mountPoint$NIXOS_CONFIG"
|
2010-09-26 00:29:50 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if $generate; then
|
|
|
|
mkdir -p $(dirname "$NIXOS_CONFIG")
|
|
|
|
|
|
|
|
# Scan the hardware and add the result to /etc/nixos/hardware-scan.nix.
|
|
|
|
hardware_config="${NIXOS_CONFIG%/configuration.nix}/hardware-configuration.nix"
|
|
|
|
if test -e "$hardware_config"; then
|
|
|
|
echo "A hardware configuration file exists, generation skipped."
|
|
|
|
else
|
2012-05-14 03:56:42 +02:00
|
|
|
echo "Generating a hardware configuration file in $hardware_config..."
|
2010-09-26 00:29:50 +02:00
|
|
|
nixos-hardware-scan > "$hardware_config"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test -e "$NIXOS_CONFIG"; then
|
|
|
|
echo 1>&2 "error: Cannot generate a template configuration because a configuration file exists."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-10-09 21:34:27 +02:00
|
|
|
nl="
|
|
|
|
"
|
|
|
|
if test -e /sys/firmware/efi/efivars; then
|
|
|
|
l1=" # Use the gummiboot efi boot loader."
|
|
|
|
l2=" boot.loader.grub.enable = false;"
|
|
|
|
l3=" boot.loader.gummiboot.enable = true;"
|
|
|
|
l4=" boot.loader.efi.canTouchEfiVariables = true;"
|
|
|
|
# !!! Remove me when nixos is on 3.10 or greater by default
|
|
|
|
l5=" # EFI booting requires kernel >= 3.10"
|
|
|
|
l6=" boot.kernelPackages = pkgs.linuxPackages_3_10;"
|
|
|
|
bootloader_config="$l1$nl$l2$nl$l3$nl$l4$nl$nl$l5$nl$l6"
|
|
|
|
else
|
|
|
|
l1=" # Use the Grub2 boot loader."
|
|
|
|
l2=" boot.loader.grub.enable = true;"
|
|
|
|
l3=" boot.loader.grub.version = 2;"
|
|
|
|
l4=" # Define on which hard drive you want to install Grub."
|
|
|
|
l5=' # boot.loader.grub.device = "/dev/sda";'
|
|
|
|
bootloader_config="$l1$nl$l2$nl$l3$nl$nl$l4$nl$l5"
|
|
|
|
fi
|
|
|
|
|
2012-05-14 03:56:42 +02:00
|
|
|
echo "Generating a basic configuration file in $NIXOS_CONFIG..."
|
2010-09-26 00:29:50 +02:00
|
|
|
|
|
|
|
# Generate a template configuration file where the user has to
|
|
|
|
# fill the gaps.
|
2013-04-16 19:34:37 +02:00
|
|
|
cat <<EOF > "$NIXOS_CONFIG"
|
2012-05-14 03:56:42 +02:00
|
|
|
# Edit this configuration file to define what should be installed on
|
|
|
|
# the system. Help is available in the configuration.nix(5) man page
|
|
|
|
# or the NixOS manual available on virtual console 8 (Alt+F8).
|
2010-09-26 00:29:50 +02:00
|
|
|
|
2012-05-14 03:56:42 +02:00
|
|
|
{ config, pkgs, ... }:
|
2010-09-26 00:29:50 +02:00
|
|
|
|
|
|
|
{
|
2013-09-04 13:05:09 +02:00
|
|
|
imports =
|
2012-05-14 03:56:42 +02:00
|
|
|
[ # Include the results of the hardware scan.
|
|
|
|
./hardware-configuration.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
boot.initrd.kernelModules =
|
|
|
|
[ # Specify all kernel modules that are necessary for mounting the root
|
|
|
|
# filesystem.
|
|
|
|
# "xfs" "ata_piix"
|
2013-10-09 21:34:27 +02:00
|
|
|
# fbcon # Uncomment this when EFI booting to see the console before the root partition is mounted
|
2012-05-14 03:56:42 +02:00
|
|
|
];
|
|
|
|
|
2013-10-09 21:34:27 +02:00
|
|
|
$bootloader_config
|
2012-05-14 03:56:42 +02:00
|
|
|
|
|
|
|
# networking.hostName = "nixos"; # Define your hostname.
|
|
|
|
# networking.wireless.enable = true; # Enables Wireless.
|
|
|
|
|
|
|
|
# Add filesystem entries for each partition that you want to see
|
|
|
|
# mounted at boot time. This should include at least the root
|
|
|
|
# filesystem.
|
2012-11-02 18:02:12 +01:00
|
|
|
|
|
|
|
# fileSystems."/".device = "/dev/disk/by-label/nixos";
|
|
|
|
|
|
|
|
# fileSystems."/data" = # where you want to mount the device
|
|
|
|
# { device = "/dev/sdb"; # the device
|
|
|
|
# fsType = "ext3"; # the type of the partition
|
|
|
|
# options = "data=journal";
|
|
|
|
# };
|
2012-05-14 03:56:42 +02:00
|
|
|
|
|
|
|
# List swap partitions activated at boot time.
|
|
|
|
swapDevices =
|
|
|
|
[ # { device = "/dev/disk/by-label/swap"; }
|
|
|
|
];
|
2010-09-26 00:29:50 +02:00
|
|
|
|
|
|
|
# Select internationalisation properties.
|
|
|
|
# i18n = {
|
|
|
|
# consoleFont = "lat9w-16";
|
|
|
|
# consoleKeyMap = "us";
|
|
|
|
# defaultLocale = "en_US.UTF-8";
|
|
|
|
# };
|
|
|
|
|
|
|
|
# List services that you want to enable:
|
|
|
|
|
2012-05-14 03:56:42 +02:00
|
|
|
# Enable the OpenSSH daemon.
|
2010-09-26 00:29:50 +02:00
|
|
|
# services.openssh.enable = true;
|
|
|
|
|
2012-05-14 03:56:42 +02:00
|
|
|
# Enable CUPS to print documents.
|
2010-09-26 00:29:50 +02:00
|
|
|
# services.printing.enable = true;
|
|
|
|
|
2012-05-14 03:56:42 +02:00
|
|
|
# Enable the X11 windowing system.
|
|
|
|
# services.xserver.enable = true;
|
|
|
|
# services.xserver.layout = "us";
|
|
|
|
# services.xserver.xkbOptions = "eurosign:e";
|
2010-09-26 00:29:50 +02:00
|
|
|
|
2012-05-14 03:56:42 +02:00
|
|
|
# Enable the KDE Desktop Environment.
|
|
|
|
# services.xserver.displayManager.kdm.enable = true;
|
|
|
|
# services.xserver.desktopManager.kde4.enable = true;
|
2010-09-26 00:29:50 +02:00
|
|
|
}
|
2012-05-14 03:56:42 +02:00
|
|
|
EOF
|
2010-09-03 21:10:50 +02:00
|
|
|
|
2010-09-26 00:29:50 +02:00
|
|
|
exit 0
|
|
|
|
fi;
|
2010-09-03 21:10:50 +02:00
|
|
|
|
2012-05-14 03:56:42 +02:00
|
|
|
# This duplicates the work made below, but it is useful for processing
|
|
|
|
# the output of nixos-option with other tools such as nixos-gui.
|
2011-04-24 17:30:25 +02:00
|
|
|
if $xml; then
|
|
|
|
evalNix --xml --no-location <<EOF
|
|
|
|
let
|
|
|
|
reach = attrs: attrs${option:+.$option};
|
2012-03-13 10:36:41 +01:00
|
|
|
nixos = import <nixos> {};
|
|
|
|
nixpkgs = import <nixpkgs> {};
|
2011-04-24 17:30:25 +02:00
|
|
|
sources = builtins.map (f: f.source);
|
|
|
|
opt = reach nixos.eval.options;
|
|
|
|
cfg = reach nixos.config;
|
|
|
|
in
|
|
|
|
|
|
|
|
with nixpkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
optStrict = v:
|
|
|
|
let
|
|
|
|
traverse = x :
|
|
|
|
if isAttrs x then
|
|
|
|
if x ? outPath then true
|
|
|
|
else all id (mapAttrsFlatten (n: traverseNoAttrs) x)
|
|
|
|
else traverseNoAttrs x;
|
|
|
|
traverseNoAttrs = x:
|
|
|
|
# do not continue in attribute sets
|
|
|
|
if isAttrs x then true
|
|
|
|
else if isList x then all id (map traverse x)
|
|
|
|
else true;
|
|
|
|
in assert traverse v; v;
|
|
|
|
in
|
|
|
|
|
|
|
|
if isOption opt then
|
|
|
|
optStrict ({}
|
|
|
|
// optionalAttrs (opt ? default) { inherit (opt) default; }
|
|
|
|
// optionalAttrs (opt ? example) { inherit (opt) example; }
|
|
|
|
// optionalAttrs (opt ? description) { inherit (opt) description; }
|
|
|
|
// optionalAttrs (opt ? type) { typename = opt.type.name; }
|
|
|
|
// optionalAttrs (opt ? options) { inherit (opt) options; }
|
|
|
|
// {
|
|
|
|
# to disambiguate the xml output.
|
|
|
|
_isOption = true;
|
|
|
|
declarations = sources opt.declarations;
|
|
|
|
definitions = sources opt.definitions;
|
|
|
|
value = cfg;
|
|
|
|
})
|
|
|
|
else
|
|
|
|
opt
|
|
|
|
EOF
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
2010-09-03 21:10:50 +02:00
|
|
|
if test "$(evalOpt "_type" 2> /dev/null)" = '"option"'; then
|
|
|
|
$value && evalCfg;
|
|
|
|
|
|
|
|
if $desc; then
|
|
|
|
$value && echo;
|
|
|
|
|
|
|
|
if default=$(evalOpt "default" - 2> /dev/null); then
|
|
|
|
echo "Default: $default"
|
|
|
|
else
|
|
|
|
echo "Default: <None>"
|
|
|
|
fi
|
|
|
|
if example=$(evalOpt "example" - 2> /dev/null); then
|
|
|
|
echo "Example: $example"
|
|
|
|
fi
|
|
|
|
echo "Description:"
|
|
|
|
eval printf $(evalOpt "description")
|
|
|
|
fi
|
|
|
|
|
|
|
|
if $defs; then
|
|
|
|
$desc || $value && echo;
|
|
|
|
|
2011-12-29 07:33:34 +01:00
|
|
|
printPath () { echo " $1"; }
|
|
|
|
|
2010-09-03 21:10:50 +02:00
|
|
|
echo "Declared by:"
|
2011-12-29 07:33:34 +01:00
|
|
|
nixMap printPath "$(findSources "declarations")"
|
2010-09-03 21:10:50 +02:00
|
|
|
echo ""
|
|
|
|
echo "Defined by:"
|
2011-12-29 07:33:34 +01:00
|
|
|
nixMap printPath "$(findSources "definitions")"
|
2010-09-03 21:10:50 +02:00
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
# echo 1>&2 "Warning: This value is not an option."
|
|
|
|
|
|
|
|
result=$(evalCfg)
|
2011-12-29 07:33:34 +01:00
|
|
|
if names=$(attrNames "$result" 2> /dev/null); then
|
|
|
|
echo 1>&2 "This attribute set contains:"
|
|
|
|
escapeQuotes () { eval echo "$1"; }
|
|
|
|
nixMap escapeQuotes "$names"
|
2010-09-03 21:10:50 +02:00
|
|
|
else
|
2011-12-29 07:33:34 +01:00
|
|
|
echo 1>&2 "An error occured while looking for attribute names."
|
2010-09-03 21:10:50 +02:00
|
|
|
echo $result
|
|
|
|
fi
|
|
|
|
fi
|