|
|
|
local utils = require 'utils'
|
|
|
|
local silo = require 'silo'
|
|
|
|
local log = require 'log'
|
|
|
|
local path = require 'path'
|
|
|
|
|
|
|
|
local exports = {}
|
|
|
|
|
|
|
|
local shasum = utils.ext_piped "shasum"
|
|
|
|
local ha_checksum = ""
|
|
|
|
|
|
|
|
local homenix = path.join { silo.dirs.config, "home-manager/home.nix" }
|
|
|
|
|
|
|
|
if path.exists(homenix) then
|
|
|
|
ha_checksum = (shasum {homenix}).stdout
|
|
|
|
log.debug(ha_checksum)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function clear_invalid_links()
|
|
|
|
utils.nu [[
|
|
|
|
( glob /home/jri/.local/share/applications/*.desktop
|
|
|
|
| each { ls -l $in }
|
|
|
|
| flatten
|
|
|
|
| where target? != null
|
|
|
|
| par-each {|entry| get target
|
|
|
|
| open $in
|
|
|
|
| parse -r '\nTryExec\s?=\s?(?<bin>[^\n]+)'
|
|
|
|
| get -i 0
|
|
|
|
| default {}
|
|
|
|
| merge $entry }
|
|
|
|
| where bin? != null
|
|
|
|
| where {|e| which $e.bin | is-empty }
|
|
|
|
| each {|e| rm $e.name; print $"Cleared ($e.name)" }
|
|
|
|
)
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
local function link_apps()
|
|
|
|
utils.nu [[
|
|
|
|
( glob ~/.nix-profile/share/applications/*.desktop
|
|
|
|
| par-each { try { ln -s $in ~/.local/share/applications/; print $"Linked ($in)" } } )
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
exports.after_apply_all = function()
|
|
|
|
if utils.which "home-manager"~= nil and (shasum {homenix}).stdout ~= ha_checksum then
|
|
|
|
local hm = utils.ext "home-manager"
|
|
|
|
|
|
|
|
log.info("Applying home-manager config")
|
|
|
|
hm { "switch" }
|
|
|
|
|
|
|
|
log.info "Expiring old home manager configurations"
|
|
|
|
hm { "expire-generations", "-1 days" }
|
|
|
|
|
|
|
|
log.info "Clear invalid links"
|
|
|
|
clear_invalid_links()
|
|
|
|
|
|
|
|
log.info "Linking applications"
|
|
|
|
link_apps()
|
|
|
|
else
|
|
|
|
log.info "Home manager does not need to be updated"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return exports
|