diff --git a/lib/combinators.nix b/lib/combinators.nix index c775af1..b796632 100644 --- a/lib/combinators.nix +++ b/lib/combinators.nix @@ -1122,6 +1122,24 @@ in rec { ; }; + open-urls-in-browser = { + sig = "Combinator"; + doc = '' + Allows access to open URLs in `$BROWSER`. + + This works by creating a pipe that is mounted into the jail that forwards + all URLs to the `$BROWSER` outside of the jail. This way the jailed + program can launch your browser, even if it has a subset of the + permissions your browser has. + ''; + __functor = _: + compose [ + (jail-to-host-channel "browserchannel" ''"$BROWSER" "$1"'') + (set-env "BROWSER" "browserchannel") + ] + ; + }; + ############################################ # deprecated persisthome = { diff --git a/tests/spec/CombinatorsSpec.hs b/tests/spec/CombinatorsSpec.hs index daa5961..32cf99c 100644 --- a/tests/spec/CombinatorsSpec.hs +++ b/tests/spec/CombinatorsSpec.hs @@ -111,6 +111,25 @@ spec = parallel $ inTestM $ do |] liftIO $ (read out :: Int) `shouldSatisfy` (< 100) + describe "open-urls-in-browser" $ do + it "exposes a $BROWSER in the jail that calls $BROWSER outside of the jail" $ do + tmpDir <- getTestDir + void $ + runNixDrv + [i| + let + fakeBrowser = sh '' + echo "got url: $1" >> #{tmpDir "fake-browser"} + ''; + jailed = jail "test" (sh ''$BROWSER https://example.org'') (c: [ + c.open-urls-in-browser + ]); + in sh '' + BROWSER=${lib.getExe fakeBrowser} ${lib.getExe jailed} + '' + |] + liftIO $ readFile (tmpDir "fake-browser") `shouldReturn` "got url: https://example.org\n" + describe "readonly-from-path-var" $ do forM_ [":", " "] $ \separator -> describe ("with separator \"" <> separator <> "\"") $ do