2022-01-09 01:20:46 +01:00
{ depot , pkgs , lib , . . . }:
let
bins = depot . nix . getBins pkgs . stow [ " s t o w " ]
2022-01-30 17:06:58 +01:00
// depot . nix . getBins pkgs . coreutils [ " m k d i r " " l n " " p r i n t e n v " " r m " ]
// depot . nix . getBins pkgs . xe [ " x e " ]
// depot . nix . getBins pkgs . lr [ " l r " ]
// depot . nix . getBins pkgs . nix [ " n i x - s t o r e " ]
;
2022-01-09 01:20:46 +01:00
# run stow to populate the target directory with the given stow package, read from stowDir.
# Bear in mind that `stowDirOriginPath` should always be semantically bound to the given `stowDir`, otherwise stow might become rather confused.
2022-01-30 17:06:58 +01:00
runStow =
{
# “stow package” to stow (see manpage)
2022-02-28 13:53:28 +01:00
# TODO: allow this function to un-stow multiple packages!
2022-01-30 17:06:58 +01:00
stowPackage
, # “target directory” to stow in (see manpage)
targetDir
, # The “stow directory” (see manpage), containing “stow packages” (see manpage)
stowDir
, # representative directory for the stowDir in the file system, against which stow will create relative links.
# ATTN: this is always overwritten with the contents of `stowDir`! You shouldn’ t re-use the same `stowDirOriginPath` for different `stowDir`s, otherwise there might be surprises.
stowDirOriginPath
,
} : depot . nix . writeExecline " s t o w - ${ stowPackage } " { } [
# first, create a temporary stow directory to use as source
# (stow will use it to determine the origin of files)
" i f "
[ bins . mkdir " - p " stowDirOriginPath ]
# remove old symlinks
" i f "
[
" p i p e l i n e "
[
bins . lr
" - 0 "
" - t "
" d e p t h = = 1 & & t y p e = = l "
stowDirOriginPath
]
bins . xe
" - 0 "
bins . rm
2022-01-09 01:20:46 +01:00
]
2022-01-30 17:06:58 +01:00
# create an indirect gc root so our config is not cleaned under our asses by a garbage collect
" i f "
[
bins . nix-store
2022-01-09 10:24:22 +01:00
" - - r e a l i s e "
" - - i n d i r e c t "
2022-01-30 17:06:58 +01:00
" - - a d d - r o o t "
" ${ stowDirOriginPath } / . n i x - s t o w d i r - g c - r o o t "
2022-01-09 10:24:22 +01:00
stowDir
2022-01-30 17:06:58 +01:00
]
# populate with new stow targets
" i f "
[
" e l g l o b "
" - w 0 "
" s t o w P a c k a g e s "
" ${ stowDir } / * "
bins . ln
" - - f o r c e "
" - s t "
stowDirOriginPath
" $ s t o w P a c k a g e s "
]
# stow always looks for $HOME/.stowrc to read more arguments
" e x p o r t "
" H O M E "
" / h o m e l e s s - s h e l t e r "
bins . stow
2022-01-09 01:20:46 +01:00
# always run restow for now; this does more stat but will remove stale links
" - - r e s t o w "
2022-01-30 17:06:58 +01:00
" - - d i r "
stowDirOriginPath
" - - t a r g e t "
targetDir
2022-01-09 01:20:46 +01:00
stowPackage
2022-01-30 17:06:58 +01:00
] ;
2022-01-09 01:20:46 +01:00
# create a stow dir from a list of drv paths and a stow package name.
makeStowDir =
( with depot . nix . yants ;
2022-01-30 17:06:58 +01:00
defun
[
( list ( struct {
2022-01-09 01:20:46 +01:00
originalDir = drv ;
stowPackage = string ;
} ) )
drv
2022-01-30 17:06:58 +01:00
] )
( dirs :
depot . nix . runExecline " m a k e - s t o w - d i r "
{
stdin = lib . pipe dirs [
( map depot . users . Profpatsch . netencode . gen . dwim )
depot . users . Profpatsch . netstring . toNetstringList
] ;
} [
" i m p o r t a s "
" o u t "
" o u t "
" i f "
[ bins . mkdir " - p " " $ o u t " ]
" f o r s t d i n "
" - d "
" "
" - o "
" 0 "
" l i n e "
" p i p e l i n e "
[
depot . users . Profpatsch . execline . print-one-env
" l i n e "
]
depot . users . Profpatsch . netencode . record-splice-env
" i m p o r t a s "
" - u i "
" o r i g i n a l D i r "
" o r i g i n a l D i r "
" i m p o r t a s "
" - u i "
" s t o w P a c k a g e "
" s t o w P a c k a g e "
bins . ln
" - s T "
" $ o r i g i n a l D i r "
" \$ { o u t } / \$ { s t o w P a c k a g e } "
] ) ;
2022-01-09 01:20:46 +01:00
2022-01-09 17:08:13 +01:00
# this is a dumb way of generating a pure list of packages from a depot namespace.
readTreeNamespaceDrvs = namespace :
lib . pipe namespace [
( lib . filterAttrs ( _ : v : lib . isDerivation v ) )
( lib . mapAttrsToList ( k : v : {
name = k ;
drv = v ;
} ) )
] ;
2022-02-28 13:53:28 +01:00
scriptsStow =
lib . pipe { } [
( _ : makeStowDir [ {
stowPackage = " s c r i p t s " ;
originalDir = pkgs . linkFarm " s c r i p t s - f a r m "
( [
{
name = " s c r i p t s / y t e x t r " ;
path = depot . users . Profpatsch . ytextr ;
}
2022-06-29 22:18:51 +02:00
{
name = " s c r i p t s / l o r r i - w a i t - f o r - e v a l " ;
path = depot . users . Profpatsch . lorri-wait-for-eval ;
}
{
name = " s c r i p t s / l w " ;
path = depot . users . Profpatsch . lorri-wait-for-eval ;
}
2022-02-28 13:53:28 +01:00
]
++
( lib . pipe depot . users . Profpatsch . aliases [
readTreeNamespaceDrvs
( map ( { name , drv }: {
name = " s c r i p t s / ${ name } " ;
path = drv ;
} ) )
] ) ) ;
} ] )
( d : runStow {
stowDir = d ;
stowPackage = " s c r i p t s " ;
targetDir = " / h o m e / p h i l i p " ;
stowDirOriginPath = " / h o m e / p h i l i p / . l o c a l / s h a r e / n i x - h o m e / s t o w - o r i g i n " ;
} )
] ;
2022-01-09 01:20:46 +01:00
2022-01-09 17:08:13 +01:00
2022-02-28 13:53:28 +01:00
terminalEmulatorStow =
lib . pipe { } [
( _ : makeStowDir [ {
stowPackage = " t e r m i n a l - e m u l a t o r " ;
originalDir = pkgs . linkFarm " t e r m i n a l - e m u l a t o r - f a r m "
( [
{
name = " b i n / t e r m i n a l - e m u l a t o r " ;
path = depot . users . Profpatsch . alacritty ;
}
] ) ;
} ] )
( d : runStow {
stowDir = d ;
stowPackage = " t e r m i n a l - e m u l a t o r " ;
targetDir = " / h o m e / p h i l i p " ;
# TODO: this should only be done once, in a single runStow instead of multiple
stowDirOriginPath = " / h o m e / p h i l i p / . l o c a l / s h a r e / n i x - h o m e / s t o w - o r i g i n - t e r m i n a l - e m u l a t o r " ;
} )
] ;
in
# TODO: run multiple stows with runStow?
# TODO: temp setup
depot . nix . writeExecline " n i x - h o m e " { } [
" i f "
[ scriptsStow ]
terminalEmulatorStow
2022-01-09 01:20:46 +01:00
]