fix typos, moved nixos-checkout code into its own file
following some other suggestions made by niksnut added further PATH hint in repos description of options.nix svn path=/nixos/trunk/; revision=12730
This commit is contained in:
parent
b0b4c0e2b3
commit
4eceb15830
@ -7,55 +7,11 @@ let
|
|||||||
isExecutable = true;
|
isExecutable = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
inherit (pkgs.lib) id all whatis escapeShellArg concatMapStrings concatMap
|
|
||||||
mapAttrs concatLists flattenAttrs filter;
|
|
||||||
|
|
||||||
# f adds svn defaults
|
nixosCheckout = (import ./nixosCheckout.nix){
|
||||||
# returns in any case:
|
inherit pkgs config makeProg;
|
||||||
# { 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
|
in
|
||||||
|
|
||||||
@ -76,7 +32,8 @@ in
|
|||||||
"cp refs $out";
|
"cp refs $out";
|
||||||
};
|
};
|
||||||
|
|
||||||
nixosRebuild = makeProg {
|
nixosRebuild = let inherit (nixosCheckout) repos defaultRepo;
|
||||||
|
in makeProg {
|
||||||
defaultNIXOS = (defaultRepo repos.nixos ).target;
|
defaultNIXOS = (defaultRepo repos.nixos ).target;
|
||||||
defaultNIXPKGS = (defaultRepo repos.nixpkgs).target;
|
defaultNIXPKGS = (defaultRepo repos.nixpkgs).target;
|
||||||
name = "nixos-rebuild";
|
name = "nixos-rebuild";
|
||||||
@ -88,37 +45,7 @@ in
|
|||||||
src = ./nixos-gen-seccure-keys.sh;
|
src = ./nixos-gen-seccure-keys.sh;
|
||||||
};
|
};
|
||||||
|
|
||||||
nixosCheckout =
|
inherit (nixosCheckout) 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 {
|
nixosHardwareScan = makeProg {
|
||||||
name = "nixos-hardware-scan";
|
name = "nixos-hardware-scan";
|
||||||
|
91
installer/nixosCheckout.nix
Normal file
91
installer/nixosCheckout.nix
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
args : with args;
|
||||||
|
let
|
||||||
|
inherit (pkgs.lib) id all whatis escapeShellArg concatMapStrings concatMap
|
||||||
|
mapAttrs concatLists flattenAttrs filter;
|
||||||
|
inherit (builtins) getAttr hasAttr head isAttrs;
|
||||||
|
in
|
||||||
|
|
||||||
|
rec {
|
||||||
|
# prepareRepoAttrs adds svn defaults and preparse the repo attribute sets so that they
|
||||||
|
# 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;
|
||||||
|
# }
|
||||||
|
prepareRepoAttrs = repo : attrs :
|
||||||
|
assert (isAttrs attrs);
|
||||||
|
assert (repo + "" == repo); # assert repo is a string
|
||||||
|
if (! (attrs ? type)) then
|
||||||
|
throw "repo type is missing of : ${whatis attrs}"
|
||||||
|
# prepare svn repo
|
||||||
|
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
|
||||||
|
}
|
||||||
|
# prepare git repo
|
||||||
|
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}";
|
||||||
|
|
||||||
|
# apply prepareRepoAttrs on each repo definition
|
||||||
|
repos = mapAttrs ( repo : list : map (x : (prepareRepoAttrs repo x) // { inherit repo; } ) list ) config.installer.repos;
|
||||||
|
|
||||||
|
# function returning the default repo (first one having attribute default or head of list)
|
||||||
|
defaultRepo = list : head ( (filter ( attrs : attrs ? default && attrs.default == true ) list)
|
||||||
|
++ list );
|
||||||
|
|
||||||
|
# creates the nixos-checkout script
|
||||||
|
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) )
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
@ -2440,11 +2440,11 @@ in
|
|||||||
example = [ { type = "svn"; url = "https://svn.nixos.org/repos/nix/nixos/branches/stdenv-updates"; target = "/etc/nixos/nixos-stdenv-updates"; }
|
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"; }
|
{ 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.
|
description = "The NixOS repository from which the system will be build.
|
||||||
nixos-checkout will update all defined repositories,
|
nixos-checkout will update all working copies of the given repositories,
|
||||||
nixos-rebuild will use the the first item which has
|
nixos-rebuild will use the first item which has
|
||||||
the attribute default = true falling back to the
|
the attribute default = true falling back to the
|
||||||
first item. the type defines the repository tool added
|
first item. The type defines the repository tool added
|
||||||
to the path. It also defines a \"valid\" repository.
|
to the path. It also defines a \"valid\" repository.
|
||||||
If the target directory already exists and it's not
|
If the target directory already exists and it's not
|
||||||
valid it will be moved to the backup location
|
valid it will be moved to the backup location
|
||||||
@ -2457,6 +2457,7 @@ in
|
|||||||
The initialize code is run from working directory
|
The initialize code is run from working directory
|
||||||
dirname \$target and should create the directory
|
dirname \$target and should create the directory
|
||||||
<filename>\$target<filename>. (<command>git clone url nixos/nixpkgs/services</command> should do)
|
<filename>\$target<filename>. (<command>git clone url nixos/nixpkgs/services</command> should do)
|
||||||
|
For the executables beeing used see <option>repoTypes</option>
|
||||||
";
|
";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user