Add lua hooks for new hook syntax

main
Julius Riegel 8 months ago
parent 632b2fe4d7
commit 5227f66656

@ -25,10 +25,6 @@
librewolf
spotify
# other dev tools
insomnia
# fonts
fontconfig
(nerdfonts.override {

@ -0,0 +1,66 @@
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"
local nix_store = utils.ext "nix-store"
log.info("Applying home-manager config")
ha { "switch" }
log.info "Expiring old home manager configurations"
ha { "expire-generations", "-1 days" }
log.info "Running nix gc"
nix_store { "--gc" }
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
Loading…
Cancel
Save