You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.7 KiB
Lua
63 lines
1.7 KiB
Lua
local utils = require 'utils'
|
|
local silo = require 'silo'
|
|
local log = require 'log'
|
|
|
|
local exports = {}
|
|
|
|
local shasum = utils.ext_piped "shasum"
|
|
local ha_checksum = ""
|
|
|
|
|
|
if utils.nu("'" .. silo.dirs.config .. "/home-manager/home.nix' | path exists") == "true\n" then
|
|
ha_checksum = (shasum { silo.dirs.config .. "/home-manager/home.nix" }).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.nu "which home-manager | is-empty" == "false\n" and (shasum { silo.dirs.config .. "/home-manager/home.nix" }).stdout ~= ha_checksum then
|
|
local ha = utils.ext "home-manager"
|
|
|
|
log.info("Applying home-manager config")
|
|
ha { "switch" }
|
|
|
|
log.info "Expiring old home manager configurations"
|
|
ha { "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
|