67b1b9af80
You can now define multiple repositories. See options.nix svn path=/nixos/trunk/; revision=12645
129 lines
4.5 KiB
Nix
129 lines
4.5 KiB
Nix
{pkgs, config, nix, nixpkgsPath}:
|
|
|
|
let
|
|
|
|
makeProg = args: pkgs.substituteAll (args // {
|
|
dir = "bin";
|
|
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
|
|
|
|
{
|
|
|
|
nixosInstall = makeProg {
|
|
name = "nixos-install";
|
|
src = ./nixos-install.sh;
|
|
|
|
inherit (pkgs) perl;
|
|
inherit nix;
|
|
nixpkgsURL = config.installer.nixpkgsURL;
|
|
|
|
pathsFromGraph = "${nixpkgsPath}/pkgs/build-support/kernel/paths-from-graph.pl";
|
|
|
|
nixClosure = pkgs.runCommand "closure"
|
|
{exportReferencesGraph = ["refs" nix];}
|
|
"cp refs $out";
|
|
};
|
|
|
|
nixosRebuild = makeProg {
|
|
defaultNIXOS = (defaultRepo repos.nixos ).target;
|
|
defaultNIXPKGS = (defaultRepo repos.nixpkgs).target;
|
|
name = "nixos-rebuild";
|
|
src = ./nixos-rebuild.sh;
|
|
};
|
|
|
|
nixosGenSeccureKeys = makeProg {
|
|
name = "nixos-gen-seccure-keys";
|
|
src = ./nixos-gen-seccure-keys.sh;
|
|
};
|
|
|
|
nixosCheckout =
|
|
makeProg {
|
|
name = "nixos-checkout";
|
|
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 {
|
|
name = "nixos-hardware-scan";
|
|
src = ./nixos-hardware-scan.pl;
|
|
inherit (pkgs) perl;
|
|
};
|
|
|
|
}
|