rewritten nixos-checkout code.

You can now define multiple repositories. See options.nix

svn path=/nixos/trunk/; revision=12645
This commit is contained in:
Marc Weber 2008-08-17 01:11:57 +00:00
parent f1be382d71
commit 67b1b9af80
4 changed files with 129 additions and 66 deletions

View File

@ -7,6 +7,56 @@ let
isExecutable = true;
});
inherit (pkgs.lib) id all whatis escapeShellArg concatMapStrings concatMap
mapAttrs concatLists flattenAttrs filter;
# f adds svn defaults
# returns in any case:
# { type = git/svn;
# target = path;
# initialize = cmd; # must create target dir, dirname target will exist
# update = cmd; # pwd will be target
# default = true/false;
# }
f = repo : attrs :
assert (__isAttrs attrs);
assert (repo + "" == repo);
if (! (attrs ? type)) then
throw "repo type is missing of : ${whatis attrs}"
else if attrs.type == "svn" then
let a = { # add svn defaults
url = "https://svn.nixos.org/repos/nix/${repo}/trunk";
target = "/etc/nixos/${repo}";
} // attrs; in
rec {
inherit (a) type target;
default = if a ? default then a.default else false;
initialize = "svn co ${a.url} ${a.target}";
update = initialize; # co is just as fine as svn update
}
else if attrs.type == "git" then # sanity check for existing attrs
assert (all id (map ( attr : if __hasAttr attr attrs then true
else throw "git repository item is missing attribute ${attr}")
[ "target" "initialize" "update" ]
));
let t = escapeShellArg attrs.target; in
rec {
inherit (attrs) type target;
default = if attrs ? default then attrs.default else false;
update = "cd ${t}; ${attrs.update}";
initialize = ''
cd $(dirname ${t}); ${attrs.initialize}
[ -d ${t} ] || { echo "git initialize failed to create target directory ${t}"; exit 1; }
${update}'';
}
else throw "unkown repo type ${attrs.type}"; in
# apply f on each repo definition
let repos = mapAttrs ( repo : list : map (x : (f repo x) // { inherit repo; } ) list ) config.installer.repos;
defaultRepo = list : __head ( (filter ( attrs : attrs ? default && attrs.default == true ) list)
++ list );
in
{
@ -27,6 +77,8 @@ in
};
nixosRebuild = makeProg {
defaultNIXOS = (defaultRepo repos.nixos ).target;
defaultNIXPKGS = (defaultRepo repos.nixpkgs).target;
name = "nixos-rebuild";
src = ./nixos-rebuild.sh;
};
@ -36,9 +88,36 @@ in
src = ./nixos-gen-seccure-keys.sh;
};
nixosCheckout = makeProg {
nixosCheckout =
makeProg {
name = "nixos-checkout";
src = ./nixos-checkout.sh;
src = pkgs.writeScript "nixos-checkout" (''
#! @shell@ -e
# this file is automatically generated from nixos configuration file settings (installer.repos)
backupTimestamp=$(date "+%Y%m%d%H%M%S")
'' + concatMapStrings ( attrs :
let repoType = __getAttr attrs.type config.installer.repoTypes;
target = escapeShellArg attrs.target; in
''
# ${attrs.type} repo ${target}
PATH=
for path in ${builtins.toString repoType.env}; do
PATH=$PATH:$path/bin:$path/sbin
done
if [ -d ${target} ] && { cd ${target} && { ${ repoType.valid}; }; }; then
echo; echo '>> ' updating ${attrs.type} repo ${target}
set -x; ${attrs.update}; set +x
else # [ make backup and ] initialize
[ -e ${target} ] && mv ${target} ${target}-$backupTimestamp
target=${target}
[ -d "$(dirname ${target})" ] || mkdir -p "$(dirname ${target})"
echo; echo '>> 'initializing ${attrs.type} repo ${target}
set -x; ${attrs.initialize}; set +x
fi
''
) # flatten all repo definition to one list adding the repository
( concatLists (flattenAttrs repos) )
);
};
nixosHardwareScan = makeProg {

View File

@ -1,62 +0,0 @@
#! @shell@ -e
set -x
# Pull the manifests defined in the configuration (the "manifests"
# attribute). Wonderfully hacky *and* cut&pasted from nixos-installer.sh!!!
if test -z "$NIXOS"; then NIXOS=/etc/nixos/nixos; fi
if test -z "$NIXOS_NO_PULL"; then
manifests=$(nix-instantiate --eval-only --xml --strict $NIXOS -A manifests \
| grep '<string' | sed 's^.*"\(.*\)".*^\1^g')
mkdir -p /nix/var/nix/channel-cache
for i in $manifests; do
NIX_DOWNLOAD_CACHE=/nix/var/nix/channel-cache nix-pull $i || true
done
fi
# Obtain Subversion.
if test -z "$(type -tp svn)"; then
#nix-channel --add http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable
#nix-channel --update
nix-env -i subversion
fi
cd /etc/nixos
if test -n "$NIXOS" && test "$NIXOS_BRANCH" = 1 && test -z "$CHECKOUT_BRANCH" && ! test "$NIXOS" = "/etc/nixos/nixos"; then
CHECKOUT_BRANCH=${NIXOS##*/}
CHECKOUT_BRANCH=${CHECKOUT_BRANCH#nixos-}
CHECKOUT_BRANCH=branches/${CHECKOUT_BRANCH}
CHECKOUT_SUFFIX=-${CHECKOUT_BRANCH##*/}
fi
if test -n "${CHECKOUT_BRANCH}" && test -z "${CHECKOUT_SUFFIX}" ; then
CHECKOUT_SUFFIX=-${CHECKOUT_BRANCH##*/}
fi;
# Move any old nixos or nixpkgs directories out of the way.
backupTimestamp=$(date "+%Y%m%d%H%M%S")
if test -e nixos -a ! -e nixos/.svn; then
mv nixos${CHECKOUT_SUFFIX} nixos-$backupTimestamp
fi
if test -e nixpkgs -a ! -e nixpkgs/.svn; then
mv nixpkgs${CHECKOUT_SUFFIX} nixpkgs-$backupTimestamp
fi
if test -e services -a ! -e services/.svn; then
mv nixos/services services-$backupTimestamp
fi
# Check out the NixOS and Nixpkgs sources.
svn co https://svn.nixos.org/repos/nix/nixos/trunk nixos${CHECKOUT_SUFFIX}
svn co https://svn.nixos.org/repos/nix/nixpkgs/${CHECKOUT_BRANCH:-trunk} nixpkgs${CHECKOUT_SUFFIX}
svn co https://svn.nixos.org/repos/nix/services/trunk services
# Add a few required symlink.
ln -sfn ../services nixos${CHECKOUT_SUFFIX}/services
REVISION=$(svn info nixpkgs${CHECKOUT_SUFFIX} | egrep '^Revision: ');
REVISION=${REVISION#Revision: };
echo "\"$REVISION\"" > version.nix

View File

@ -42,8 +42,8 @@ fi
# Allow the location of NixOS sources and the system configuration
# file to be overridden.
NIXOS=${NIXOS:-/etc/nixos/nixos}
NIXPKGS=${NIXPKGS:-$NIXOS/pkgs}
NIXOS=${NIXOS:-@defaultNIXOS@}
NIXPKGS=${NIXPKGS:-@defaultNIXPKGS@}
NIXOS_CONFIG=${NIXOS_CONFIG:-/etc/nixos/configuration.nix}

View File

@ -2424,6 +2424,52 @@ in
";
};
repos = {
nixos = mkOption {
default = [ { type = "svn"; } ];
example = [ { type = "svn"; url = "https://svn.nixos.org/repos/nix/nixos/branches/stdenv-updates"; target = "/etc/nixos/nixos-stdenv-updates"; }
{ type = "git"; initialize = ''git clone git://mawercer.de/nixos $target''; update = "git pull origin"; target = "/etc/nixos/nixos-git"; }
];
description = "The nixos repository from which the system will be build.
nixos-checkout will update all defined repositories,
nixos-rebuild will use the the first item which has
the attribute default = true falling back to the
first item. the type defines the repository tool added
to the path. It also defines a \"valid\" repository.
If the target directory already exists and it's not
valid it will be moved to the backup location
<filename>\${dir}-date</filename>.
For svn the default target and repositories are
<filename>/etc/nixos/nixos</filename> and
<filename>https://svn.nixos.org/repos/nix/nixos/trunk</filename>.
For git repositories update is called after
initialization when the repo is initialized.
The initialize code is run from working directory
dirname \$target and should create the directory
<filename>\$target<filename>. (<command>git clone url nixos/nixpkgs/services</command> should do)
";
};
nixpkgs = mkOption {
default = [ { type = "svn"; } ];
description = "same as <option>repos.nixos</option>";
};
services = mkOption {
default = [ { type = "svn"; } ];
description = "same as <option>repos.nixos</option>";
};
};
repoTypes = mkOption {
default = {
svn = { valid = "[ -d .svn ]"; env = [ pkgs.coreutils pkgs.subversion ]; };
git = { valid = "[ -d .git ]"; env = [ pkgs.coreutils pkgs.git pkgs.gnused /* FIXME: use full path to sed in nix-pull */ ]; };
};
description = "defines PATH environment and when directory is considered beeing a valid repository.
If it's not it's moved to a backup directory";
};
manifests = mkOption {
default = [http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable/MANIFEST];
example =