2008-06-05 15:33:17 +00:00
|
|
|
{pkgs, config, nix, nixpkgsPath}:
|
2008-02-08 15:59:15 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
makeProg = args: pkgs.substituteAll (args // {
|
|
|
|
dir = "bin";
|
|
|
|
isExecutable = true;
|
|
|
|
});
|
|
|
|
|
2008-08-17 01:11:57 +00:00
|
|
|
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 );
|
|
|
|
|
2008-02-08 15:59:15 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nixosInstall = makeProg {
|
|
|
|
name = "nixos-install";
|
|
|
|
src = ./nixos-install.sh;
|
|
|
|
|
|
|
|
inherit (pkgs) perl;
|
|
|
|
inherit nix;
|
|
|
|
nixpkgsURL = config.installer.nixpkgsURL;
|
|
|
|
|
2008-06-05 15:33:17 +00:00
|
|
|
pathsFromGraph = "${nixpkgsPath}/pkgs/build-support/kernel/paths-from-graph.pl";
|
2008-02-08 15:59:15 +00:00
|
|
|
|
|
|
|
nixClosure = pkgs.runCommand "closure"
|
|
|
|
{exportReferencesGraph = ["refs" nix];}
|
|
|
|
"cp refs $out";
|
|
|
|
};
|
|
|
|
|
|
|
|
nixosRebuild = makeProg {
|
2008-08-17 01:11:57 +00:00
|
|
|
defaultNIXOS = (defaultRepo repos.nixos ).target;
|
|
|
|
defaultNIXPKGS = (defaultRepo repos.nixpkgs).target;
|
2008-02-08 15:59:15 +00:00
|
|
|
name = "nixos-rebuild";
|
|
|
|
src = ./nixos-rebuild.sh;
|
|
|
|
};
|
|
|
|
|
2008-03-03 23:31:48 +00:00
|
|
|
nixosGenSeccureKeys = makeProg {
|
|
|
|
name = "nixos-gen-seccure-keys";
|
|
|
|
src = ./nixos-gen-seccure-keys.sh;
|
|
|
|
};
|
|
|
|
|
2008-08-17 01:11:57 +00:00
|
|
|
nixosCheckout =
|
|
|
|
makeProg {
|
2008-02-08 15:59:15 +00:00
|
|
|
name = "nixos-checkout";
|
2008-08-17 01:11:57 +00:00
|
|
|
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) )
|
|
|
|
);
|
2008-02-08 15:59:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nixosHardwareScan = makeProg {
|
|
|
|
name = "nixos-hardware-scan";
|
|
|
|
src = ./nixos-hardware-scan.pl;
|
|
|
|
inherit (pkgs) perl;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|