diff --git a/home/laptop.nix b/home/laptop.nix index 464d4108..464ce1e4 100644 --- a/home/laptop.nix +++ b/home/laptop.nix @@ -1,12 +1,13 @@ { pkgs, lib, ... }: let - inherit (import ../lib) unfreePkgs; + inherit (import ../lib) unfreePkgs writeHaskellScript; inherit (import ../pkgs) my-ssh-add; modes = pkgs.lib.attrNames (import ./modes.nix).apollo; autostart-script = pkgs.writeShellScriptBin "home-manager-autostart" '' ${my-ssh-add}/bin/my-ssh-add ${pkgs.xorg.xrdb}/bin/xrdb ${builtins.toFile "Xresources" "Xft.dpi: 96"} ''; + configPath = "/home/maralorn/git/config"; in { xdg.configFile."autostart/home-manager-autostart.desktop".source = "${ @@ -16,29 +17,40 @@ in { exec = "${autostart-script}/bin/home-manager-autostart"; } }/share/applications/home-manager-autostart.desktop"; - home.packages = builtins.attrValues { + home.packages = builtins.attrValues rec { maintenance = pkgs.writeShellScriptBin "maintenance" '' + set -e git -C ~/git/config pull update-modes sudo -A update-system sudo -A nix-collect-garbage -d sudo -A nix optimise-store ''; - activateMode = pkgs.writeShellScriptBin "activate-mode" '' - ~/.modes/$(cat ~/tmp/mode)/activate - random-wallpaper + activateMode = writeHaskellScript { name = "activate-mode"; } '' + getMode :: IO Text + getMode = decodeUtf8 <$> (cat "/home/maralorn/tmp/mode" |> captureTrim) + + main = do + mode <- getMode + say [i|Switching to mode #{mode}...|] + exe ([i|/home/maralorn/.modes/#{mode}/activate|] :: String) + exe "random-wallpaper" ''; - updateModes = pkgs.writeShellScriptBin "update-modes" '' - set -e - nix build -f ~/git/config/home/target.nix apollo -o ~/.modes - activate-mode + updateModes = writeHaskellScript { + name = "update-modes"; + bins = [ activateMode ]; + } '' + main = do + say "Building ~/.modes for apollo" + nixPath <- myNixPath "${configPath}/nix/sources.nix" + nix_build nixPath "${configPath}/home/target.nix" "-A" "apollo" "-o" "/home/maralorn/.modes" + activate_mode ''; selectMode = pkgs.writeShellScriptBin "select-mode" '' ${pkgs.dialog}/bin/dialog --menu "Select Mode" 20 80 5 ${ lib.concatStrings (map (mode: "${mode} '' ") modes) } 2> ~/tmp/mode clear - echo "Switching to mode $(cat ~/tmp/mode)..." activate-mode > /dev/null ''; diff --git a/home/mail.nix b/home/mail.nix index b1da0e96..1c76e08c 100644 --- a/home/mail.nix +++ b/home/mail.nix @@ -47,7 +47,7 @@ let executeFilterMail :: (LByteString, Text, Text) -> IO () executeFilterMail (files, filter, target) = do - putTextLn [i|Sorting "#{filter}" into #{target}|] + say [i|Sorting "#{filter}" into #{target}|] writeOutput files |> mscan mmkdir ([i|${archive}/#{target}|] :: String) writeOutput files |> mrefile ([i|${archive}/#{target}|] :: String) diff --git a/lib/default.nix b/lib/default.nix index fd026993..d1c907df 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -57,6 +57,9 @@ rec { pkgs.haskellPackages.string-interpolate pkgs.haskellPackages.relude pkgs.haskellPackages.async + pkgs.haskellPackages.say + pkgs.haskellPackages.cmdargs + pkgs.haskellPackages.text ]) }/bin/ghc ${name}.hs -threaded mv ${name} $out @@ -77,6 +80,7 @@ rec { import Shh import Relude + import Say import qualified Relude.Unsafe as Unsafe import qualified Data.ByteString.Lazy as LBS import qualified Data.ByteString as BS @@ -90,25 +94,29 @@ rec { -- Load binaries from Nix packages. The dependencies will be captured -- in the closure. loadFromBins (${ - haskellList (builtins.map toString (bins ++ [ pkgs.coreutils ])) + haskellList + (builtins.map toString (bins ++ [ pkgs.coreutils pkgs.nix ])) } :: [String]) + getNivPath :: Text -> Text -> IO Text + getNivPath sources channel = do + let expr = [i|(import #{sources}).#{channel}|] :: String + nix_build ["-Q", "-E", expr, "--no-out-link"] &> devNull + escaped <- nix_instantiate ["--eval" :: String, "-E", [i|toString #{expr}|]] |> captureTrim + pure . Text.dropAround ('"' ==) . decodeUtf8 . trim $ escaped + + myNixPath path = concat <$> mapM getNivAssign ["home-manager", "nixpkgs", "unstable"] + where + tag name str = ["-I", [i|#{name :: Text}=#{str :: Text}|]] :: [String] + getNivAssign name = tag name <$> getNivPath path name + ${code} ''; - get-niv-path = writeHaskellScript { - name = "get-niv-path"; - bins = [ pkgs.nix ]; - imports = [ "System.Console.CmdArgs.Implicit" ]; - libraries = [ pkgs.haskellPackages.cmdargs pkgs.haskellPackages.text ]; - } '' - - trimQuotation = pureProc $ encodeUtf8 . Text.dropAround ('"' ==) . decodeUtf8 . trim - + get-niv-path = writeHaskellScript { name = "get-niv-path"; } '' main = do - [sources, channel] <- getArgs - let expr = [i|(import #{sources}).#{channel}|] :: String - nix_build ["-Q", "-E", expr, "--no-out-link"] &> devNull - nix_instantiate ["--eval" :: String, "-E", [i|toString #{expr}|]] |> trimQuotation + [sources, channel] <- fmap toText <$> getArgs + path <- getNivPath sources channel + say path ''; home-manager = pkgs.callPackage { }; gcRetentionDays = 5; diff --git a/lib/test.nix b/lib/test.nix index a4c18fe0..b58858c3 100644 --- a/lib/test.nix +++ b/lib/test.nix @@ -1,33 +1,28 @@ let inherit (import ../lib) - pkgs writeHaskellScript get-niv-path home-manager unstable haskellList; + pkgs writeHaskellScript home-manager unstable haskellList; in rec { haskellBody = name: commandline: '' - getNivPath dir name = get_niv_path ([i|#{dir :: String}/nix/sources.nix|] :: String) name |> captureTrim - - getNivAssign dir name = process <$> getNivPath dir name - where process str = ["-I" :: String, [i|#{name :: String}=#{str :: LByteString}|]] - main = do - (configDir:hostname:args) <- getArgs - paths <- concat <$> mapM (getNivAssign $ toString configDir) ["nixpkgs", "unstable", "home-manager"] - putStrLn [i|Trying to build ${name} config for #{hostname}|] + (configDir:hostname:args) <- getArgs + paths <- myNixPath $ toText configDir + say [i|Trying to build ${name} config for #{hostname}|] ${commandline} ''; - bins = [ get-niv-path pkgs.nix ]; + bins = [ pkgs.nix ]; test-system-config = writeHaskellScript { name = "test-system-config"; inherit bins; } (haskellBody "system" '' - nix $ ["build", "-f", "", "system"] ++ paths ++ ["-I", [i|nixos-config=#{configDir}/hosts/#{hostname}/configuration.nix|], "-o", [i|result-system-#{hostname}|]] ++ fmap toString args + nix_build $ ["", "-A", "system"] ++ paths ++ ["-I", [i|nixos-config=#{configDir}/hosts/#{hostname}/configuration.nix|], "-o", [i|result-system-#{hostname}|]] ++ fmap toString args ''); test-home-config = writeHaskellScript { name = "test-home-config"; inherit bins; } (haskellBody "home" '' - nix $ ["build", "-f", ""] ++ paths ++ ["--argstr", "confPath", [i|#{configDir}/home.nix|], "--argstr", "confAttr", hostname, "--out-link", [i|result-home-manager-#{hostname}|], "activationPackage"] ++ fmap toString args + nix_build $ [""] ++ paths ++ ["--argstr", "confPath", [i|#{configDir}/home.nix|], "--argstr", "confAttr", hostname, "--out-link", [i|result-home-manager-#{hostname}|], "-A", "activationPackage"] ++ fmap toString args ''); repoSrc = "git@hera.m-0.eu:nixos-config"; diff --git a/lib/update-home.nix b/lib/update-home.nix index 74d2ead5..00ef2aa8 100644 --- a/lib/update-home.nix +++ b/lib/update-home.nix @@ -1,19 +1,13 @@ -let inherit (import ./.) home-manager writeHaskellScript get-niv-path; +let inherit (import ./.) home-manager writeHaskellScript; in { update-home = configPath: writeHaskellScript { name = "update-home"; - bins = [ get-niv-path home-manager ]; + bins = [ home-manager ]; } '' - - getNivPath name = get_niv_path "${configPath}/nix/sources.nix" name |> captureTrim - - getNivAssign name = tag <$> getNivPath name - where tag str = ["-I", [i|#{name :: String}=#{str :: LByteString}|]] :: [String] - main = do args <- getArgs - paths <- concat <$> mapM getNivAssign ["home-manager", "nixpkgs", "unstable"] + paths <- myNixPath "${configPath}/nix/sources.nix" home_manager $ paths ++ ["switch"] ++ fmap toString args ''; } diff --git a/lib/update-system.nix b/lib/update-system.nix index 5ca6effd..1c40a1cd 100644 --- a/lib/update-system.nix +++ b/lib/update-system.nix @@ -1,20 +1,13 @@ nixos-rebuild: -let - inherit (import ../lib) - writeHaskellScript get-niv-path home-manager gcRetentionDays pkgs; +let inherit (import ../lib) writeHaskellScript; in rec { configPath = "/etc/nixos"; update-system = writeHaskellScript { name = "update-system"; - bins = [ get-niv-path nixos-rebuild ]; + bins = [ nixos-rebuild ]; } '' - getNivPath name = get_niv_path "${configPath}/nix/sources.nix" name |> captureTrim - - getNivAssign name = tag <$> getNivPath name - where tag str = ["-I" :: String, [i|#{name :: String}=#{str :: LByteString}|]] - main = do - paths <- fmap concat . mapM getNivAssign $ ["nixpkgs", "unstable", "home-manager"] + paths <- myNixPath "${configPath}/nix/sources.nix" args <- getArgs nixos_rebuild (paths ++ ["switch"] ++ fmap toString args) ''; diff --git a/system/git.nix b/system/git.nix index 3dfe014c..c2ee7285 100644 --- a/system/git.nix +++ b/system/git.nix @@ -26,18 +26,18 @@ let main = do mirror <- lookupEnv "GL_OPTION_MIRROR" whenJust mirror $ \mirror -> do - echo ([i|Forwarding push to #{mirror}|] :: String) + say [i|Forwarding push to #{mirror}|] git "push" "--all" "-f" mirror deploy <- lookupEnv "GL_OPTION_WEB_DEPLOY" whenJust deploy $ \deploy -> do (maybe [] (\x -> ["-f","default.nix",x]) -> target) <- lookupEnv "GL_OPTION_WEB_DEPLOY_NIX_TARGET" (decodeUtf8 -> path) <- pwd |> captureTrim - echo ([i|Deploying build to /var/www/#{deploy}|] :: String) - bracket (checkout path) (rm "-rf") $ \dir -> withCurrentDirectory dir $ nix "build" "-o" ([i|/var/www/#{deploy}|] :: String) target - echo "Done" + say [i|Deploying build to /var/www/#{deploy}|] + bracket (checkout path) (rm "-rf") $ \dir -> withCurrentDirectory dir $ nix_build "-o" ([i|/var/www/#{deploy}|] :: String) target + say "Done" test <- lookupEnv "GL_OPTION_TEST" whenJust test $ \_ -> do - echo "Triggering (an async) system update." + say "Triggering (an async) system update." exe "sudo" ${haskellList update-command}; ''; in { diff --git a/system/modules/laptop.nix b/system/modules/laptop.nix index fcbf25d5..c5b1ca1c 100644 --- a/system/modules/laptop.nix +++ b/system/modules/laptop.nix @@ -30,7 +30,6 @@ in { anonymousClients.allowedIpRanges = [ "127.0.0.1" "::1" ]; }; }; - security.pam.services.swaylock = { }; programs.dconf.enable = true; services = {