@ -127,10 +127,16 @@ let
name = " i n i t r d - e m e r g e n c y - e n v " ;
paths = map getBin cfg . initrdBin ;
pathsToLink = [ " / b i n " " / s b i n " ] ;
# Make recovery easier
postBuild = ''
ln - s $ { cfg . package . util-linux } /bin/mount $ out/bin /
ln - s $ { cfg . package . util-linux } /bin/umount $ out/bin /
'' ;
} ;
initialRamdisk = pkgs . makeInitrdNG {
contents = cfg . objects ;
contents = map ( path : { object = path ; symlink = " " ; } ) ( subtractLists cfg . suppressedStorePaths cfg . storePaths )
++ mapAttrsToList ( _ : v : { object = v . source ; symlink = v . target ; } ) ( filterAttrs ( _ : v : v . enable ) cfg . contents ) ;
} ;
in {
@ -142,31 +148,69 @@ in {
not yet supported by the intrd generated with this option .
'' ;
package = ( lib . mkPackageOption pkgs " s y s t e m d " {
package = ( mkPackageOption pkgs " s y s t e m d " {
default = " s y s t e m d M i n i m a l " ;
} ) // {
visible = false ;
} ;
objec ts = mkOption {
description = " L i s t o f o b j e c t s t o i n c l u d e i n t h e i n i t r d , a n d t h e i r s y m l i n k s " ;
conten ts = mkOption {
description = " S e t o f f i l e s t h a t h a v e t o b e l i n k e d i n t o t h e i n i t r d " ;
example = literalExpression ''
[ { object = " ' ' ${ systemd } / l i b / s y s t e m d / s y s t e m d " ; symlink = " / i n i t " ; } ]
{
" / e t c / h o s t n a m e " . text = " m y m a c h i n e " ;
}
'' ;
visible = false ;
type = types . listOf ( types . submodule {
default = { } ;
type = types . attrsOf ( types . submodule ( { config , options , name , . . . }: {
options = {
object = mkOption {
enable = mkEnableOption " c o p y i n g o f t h i s f i l e t o i n i t r d a n d s y m l i n k i n g i t " // { default = true ; } ;
target = mkOption {
type = types . path ;
description = " T h e o b j e c t t o i n c l u d e i n i n i t r d . " ;
description = ''
Path of the symlink .
'' ;
default = name ;
} ;
symlink = mkOption {
type = types . nullOr types . path ;
description = " A s y m l i n k t o c r e a t e i n i n i t r d p o i n t i n g t o t h e o b j e c t . " ;
text = mkOption {
default = null ;
type = types . nullOr types . lines ;
description = " T e x t o f t h e f i l e . " ;
} ;
source = mkOption {
type = types . path ;
description = " P a t h o f t h e s o u r c e f i l e . " ;
} ;
} ;
} ) ;
config = {
source = mkIf ( config . text != null ) (
let name' = " i n i t r d - " + baseNameOf name ;
in mkDerivedConfig options . text ( pkgs . writeText name' )
) ;
} ;
} ) ) ;
} ;
storePaths = mkOption {
description = ''
Store paths to copy into the initrd as well .
'' ;
type = types . listOf types . singleLineStr ;
default = [ ] ;
} ;
suppressedStorePaths = mkOption {
description = ''
Store paths specified in the storePaths option that
should not be copied .
'' ;
type = types . listOf types . singleLineStr ;
default = [ ] ;
} ;
emergencyAccess = mkOption {
@ -300,48 +344,42 @@ in {
boot . initrd . systemd = {
initrdBin = [ pkgs . bash pkgs . coreutils pkgs . kmod cfg . package ] ++ config . system . fsPackages ;
objects = [
{ object = " ${ cfg . package } / l i b / s y s t e m d / s y s t e m d " ; symlink = " / i n i t " ; }
{ object = stage1Units ; symlink = "/ e t c / s y s t e m d / s y s t e m " ; }
contents = {
" / i n i t " . source = " ${ cfg . package } / l i b / s y s t e m d / s y s t e m d " ;
"/ e t c / s y s t e m d / s y s t e m " . source = stage1Units ;
# TODO: Limit this to the bare necessities
{ object = " ${ cfg . package } / l i b " ; }
" / e t c / s y s t e m d / s y s t e m . c o n f " . text = ''
[ Manager ]
DefaultEnvironment = PATH = /bin : /sbin
'' ;
{ object = " ${ cfg . package . util-linux } / b i n / m o u n t " ; }
{ object = " ${ cfg . package . util-linux } / b i n / u m o u n t " ; }
{ object = " ${ cfg . package . util-linux } / b i n / s u l o g i n " ; }
" / e t c / i n i t r d - r e l e a s e " . source = config . environment . etc . os-release . source ;
" / e t c / o s - r e l e a s e " . source = config . environment . etc . os-release . source ;
" / e t c / f s t a b " . source = fstab ;
{
object = builtins . toFile " s y s t e m . c o n f " ''
[ Manager ]
DefaultEnvironment = PATH = /bin : /sbin
'' ;
symlink = " / e t c / s y s t e m d / s y s t e m . c o n f " ;
}
" / l i b / m o d u l e s " . source = " ${ modulesClosure } / l i b / m o d u l e s " ;
{ object = config . environment . etc . os-release . source ; symlink = " / e t c / i n i t r d - r e l e a s e " ; }
{ object = config . environment . etc . os-release . source ; symlink = " / e t c / o s - r e l e a s e " ; }
{ object = fstab ; symlink = " / e t c / f s t a b " ; }
{
object = " ${ modulesClosure } / l i b / m o d u l e s " ;
symlink = " / l i b / m o d u l e s " ;
}
{
symlink = " / e t c / m o d u l e s - l o a d . d / n i x o s . c o n f " ;
object = pkgs . writeText " n i x o s . c o n f "
( lib . concatStringsSep " \n " config . boot . initrd . kernelModules ) ;
}
" / e t c / m o d u l e s - l o a d . d / n i x o s . c o n f " . text = concatStringsSep " \n " config . boot . initrd . kernelModules ;
" / e t c / p a s s w d " . source = " ${ pkgs . fakeNss } / e t c / p a s s w d " ;
" / e t c / s h a d o w " . text = " r o o t : ${ if isBool cfg . emergencyAccess then " ! " else cfg . emergencyAccess } : : : : : : : " ;
" / b i n " . source = " ${ initrdBinEnv } / b i n " ;
" / s b i n " . source = " ${ initrdBinEnv } / s b i n " ;
" / e t c / s y s c t l . d / n i x o s . c o n f " . text = " k e r n e l . m o d p r o b e = / s b i n / m o d p r o b e " ;
} ;
storePaths = [
# TODO: Limit this to the bare necessities
" ${ cfg . package } / l i b "
" ${ cfg . package . util-linux } / b i n / m o u n t "
" ${ cfg . package . util-linux } / b i n / u m o u n t "
" ${ cfg . package . util-linux } / b i n / s u l o g i n "
{ object = " ${ pkgs . fakeNss } / e t c / p a s s w d " ; symlink = " / e t c / p a s s w d " ; }
# so NSS can look up usernames
{ object = " ${ pkgs . glibc } / l i b / l i b n s s _ f i l e s . s o " ; }
{
object = builtins . toFile " s h a d o w " " r o o t : ${ if isBool cfg . emergencyAccess then " ! " else cfg . emergencyAccess } : : : : : : : " ;
symlink = " / e t c / s h a d o w " ;
}
{ object = " ${ initrdBinEnv } / b i n " ; symlink = " / b i n " ; }
{ object = " ${ initrdBinEnv } / s b i n " ; symlink = " / s b i n " ; }
{ object = builtins . toFile " s y s c t l . c o n f " " k e r n e l . m o d p r o b e = / s b i n / m o d p r o b e " ; symlink = " / e t c / s y s c t l . d / n i x o s . c o n f " ; }
" ${ pkgs . glibc } / l i b / l i b n s s _ f i l e s . s o "
] ;
targets . initrd . aliases = [ " d e f a u l t . t a r g e t " ] ;