* add direnv support

* elm format

* use flake-utils

* remove unused parts of the code

* only use one workflow to import things

* Build flake-info in separate job

* DEBUG

* Revert "DEBUG"

This reverts commit 6c335e6bd2ba450f1891efe70dfd9bb95f300b31.

* RUST_LOG is a runtime thing
This commit is contained in:
Rok Garbas 2022-03-17 23:00:10 +01:00 committed by GitHub
parent 6e2650b6d3
commit 26caeaf488
Failed to generate hash of commit
16 changed files with 544 additions and 479 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

View file

@ -1,51 +0,0 @@
name: "Flakes: Hourly import to Elasticsearch"
on:
workflow_dispatch:
schedule:
- cron: '0 * * * *'
jobs:
import-flakes:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
group:
- "manual"
env:
RUST_LOG: debug
FI_ES_EXISTS_STRATEGY: recreate
FI_ES_URL: ${{ secrets.ELASTICSEARCH_URL }}
steps:
- name: Checking out the repository
uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/common-setup
with:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
- name: Building flake-info
run: |
nix -vL build .#flake-info
- name: Import ${{ matrix.group }} group
run: |
./result/bin/flake-info --push --elastic-schema-version=$(< ./VERSION) group ./flakes/${{ matrix.group }}.toml ${{ matrix.group }}
if: github.repository_owner == 'NixOS'
- name: Warmup ${{ matrix.group }} group
run: |
for (( i = 0; i < 3; i++ )) do
curl -sS ${{ secrets.ELASTICSEARCH_URL }}/latest-$(< VERSION)-group-${{ matrix.group }}/_search | jq -c '.took // .'
done
if: github.repository_owner == 'NixOS'

View file

@ -1,58 +0,0 @@
name: "Nixpkgs: Hourly import to Elasticsearch"
on:
workflow_dispatch:
schedule:
- cron: '0 * * * *'
jobs:
import-nixpkgs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
channel:
- unstable
- 21.11
env:
RUST_LOG: debug
FI_ES_EXISTS_STRATEGY: abort
FI_ES_URL: ${{ secrets.ELASTICSEARCH_URL }}
steps:
- name: Increase swap space
uses: pierotofy/set-swap-space@v1.0
with:
swap-size-gb: 10
- name: Checking out the repository
uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/common-setup
with:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
- name: Building flake-info
run: |
nix -vL build .#flake-info
- name: Import ${{ matrix.channel }} channel
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./result/bin/flake-info --push --elastic-schema-version=$(< VERSION) nixpkgs ${{ matrix.channel }}
if: github.repository_owner == 'NixOS'
- name: Warmup ${{ matrix.channel }} channel
run: |
for (( i = 0; i < 3; i++ )) do
curl -sS ${{ secrets.ELASTICSEARCH_URL }}/latest-$(< VERSION)-nixos-${{ matrix.channel }}/_search | jq -c '.took // .'
done
if: github.repository_owner == 'NixOS'

View file

@ -0,0 +1,113 @@
name: "Hourly import to Elasticsearch"
on:
workflow_dispatch:
schedule:
- cron: '0 * * * *'
jobs:
build-flake-info:
runs-on: ubuntu-latest
steps:
- name: Checking out the repository
uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/common-setup
with:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
- name: Building flake-info
run: |
nix -vL build .#flake-info
import-nixpkgs:
needs: build-flake-info
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
channel:
- unstable
- 21.11
env:
RUST_LOG: debug
FI_ES_EXISTS_STRATEGY: abort
FI_ES_URL: ${{ secrets.ELASTICSEARCH_URL }}
steps:
- name: Increase swap space
uses: pierotofy/set-swap-space@v1.0
with:
swap-size-gb: 10
- name: Checking out the repository
uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/common-setup
with:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
- name: Import ${{ matrix.channel }} channel
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
nix run .#flake-info -- --push --elastic-schema-version=$(< VERSION) nixpkgs ${{ matrix.channel }}
if: github.repository_owner == 'NixOS'
- name: Warmup ${{ matrix.channel }} channel
run: |
for (( i = 0; i < 3; i++ )) do
curl -sS ${{ secrets.ELASTICSEARCH_URL }}/latest-$(< VERSION)-nixos-${{ matrix.channel }}/_search | jq -c '.took // .'
done
if: github.repository_owner == 'NixOS'
import-flakes:
needs: build-flake-info
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
group:
- "manual"
env:
RUST_LOG: debug
FI_ES_EXISTS_STRATEGY: recreate
FI_ES_URL: ${{ secrets.ELASTICSEARCH_URL }}
steps:
- name: Checking out the repository
uses: actions/checkout@v3
- name: Setup
uses: ./.github/actions/common-setup
with:
CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
- name: Import ${{ matrix.group }} group
run: |
nix run .#flake-info -- --push --elastic-schema-version=$(< ./VERSION) group ./flakes/${{ matrix.group }}.toml ${{ matrix.group }}
if: github.repository_owner == 'NixOS'
- name: Warmup ${{ matrix.group }} group
run: |
for (( i = 0; i < 3; i++ )) do
curl -sS ${{ secrets.ELASTICSEARCH_URL }}/latest-$(< VERSION)-group-${{ matrix.group }}/_search | jq -c '.took // .'
done
if: github.repository_owner == 'NixOS'

1
.gitignore vendored
View file

@ -20,3 +20,4 @@ package-lock.json
repl-temp-* repl-temp-*
result result
src-url src-url
.direnv/

View file

@ -1,5 +1,20 @@
{ {
"nodes": { "nodes": {
"flake-utils": {
"locked": {
"lastModified": 1644229661,
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1642903813, "lastModified": 1642903813,
@ -17,6 +32,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
} }

View file

@ -7,43 +7,42 @@
}; };
inputs = { inputs = {
nixpkgs = { url = "nixpkgs/nixos-unstable"; }; nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs }: outputs = { self
let , nixpkgs
systems = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" ]; , flake-utils
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system); }:
mkPackage = path: system: flake-utils.lib.eachSystem
(with flake-utils.lib.system; [
x86_64-linux
i686-linux
x86_64-darwin
aarch64-linux
])
(system:
let let
pkgs = import nixpkgs {
inherit system;
overlays = [ ];
};
in
import path { inherit pkgs; };
packages = system:
{
flake-info = mkPackage ./flake-info system;
frontend = mkPackage ./. system;
};
devShell = system:
let
packages_inst = (packages system);
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
in warnToUpgradeNix = pkgs.lib.warn "Please upgrade Nix to 2.7 or later.";
pkgs.mkShell { in rec {
inputsFrom = builtins.attrValues packages_inst;
shellHook = '' packages.default = packages.flake-info;
export RUST_SRC_PATH="${pkgs.rustPlatform.rustLibSrc}"; packages.flake-info = import ./flake-info { inherit pkgs; };
export NIXPKGS_PANDOC_FILTERS_PATH="${packages_inst.flake-info.NIXPKGS_PANDOC_FILTERS_PATH}"; packages.frontend = import ./. { inherit pkgs; };
'';
}; devShells.default = pkgs.mkShell {
in inputsFrom = builtins.attrValues packages;
{ shellHook = ''
defaultPackage = forAllSystems (mkPackage ./flake-info); export RUST_SRC_PATH="${pkgs.rustPlatform.rustLibSrc}";
packages = forAllSystems packages; export NIXPKGS_PANDOC_FILTERS_PATH="${packages.flake-info.NIXPKGS_PANDOC_FILTERS_PATH}";
devShell = forAllSystems devShell; '';
}; };
# XXX: for backwards compatibility
devShell = warnToUpgradeNix devShells.default;
defaultPackage = warnToUpgradeNix packages.default;
}
);
} }

View file

@ -6,7 +6,6 @@ import Html
exposing exposing
( Html ( Html
, a , a
, button
, div , div
, footer , footer
, header , header
@ -20,25 +19,20 @@ import Html
) )
import Html.Attributes import Html.Attributes
exposing exposing
( attribute ( class
, class
, classList , classList
, href , href
, id , id
, src , src
, type_
) )
import Page.Flakes exposing (Model(..)) import Page.Flakes exposing (Model(..))
import Page.Home import Page.Home
import Page.Options import Page.Options
import Page.Packages import Page.Packages
import RemoteData exposing (RemoteData(..))
import Route exposing (SearchType(..)) import Route exposing (SearchType(..))
import Search exposing (Msg(..), defaultFlakeId) import Search exposing (Msg(..), defaultFlakeId)
import Url import Url
import Search exposing (defaultFlakeId)
import Html exposing (sup)
import Html exposing (small)
import RemoteData exposing (RemoteData(..))
@ -196,13 +190,15 @@ pageMatch m1 m2 =
( Packages model_a, Packages model_b ) -> ( Packages model_a, Packages model_b ) ->
{ model_a | show = Nothing, showInstallDetails = Search.Unset, result = NotAsked } { model_a | show = Nothing, showInstallDetails = Search.Unset, result = NotAsked }
== { model_b | show = Nothing, showInstallDetails = Search.Unset, result = NotAsked } == { model_b | show = Nothing, showInstallDetails = Search.Unset, result = NotAsked }
( Options model_a, Options model_b ) -> ( Options model_a, Options model_b ) ->
{model_a | show = Nothing, result = NotAsked } == {model_b | show = Nothing, result = NotAsked} { model_a | show = Nothing, result = NotAsked } == { model_b | show = Nothing, result = NotAsked }
( Flakes (OptionModel model_a), Flakes (OptionModel model_b) ) -> ( Flakes (OptionModel model_a), Flakes (OptionModel model_b) ) ->
{model_a | show = Nothing, result = NotAsked } == {model_b | show = Nothing, result = NotAsked} { model_a | show = Nothing, result = NotAsked } == { model_b | show = Nothing, result = NotAsked }
( Flakes (PackagesModel model_a), Flakes (PackagesModel model_b) ) -> ( Flakes (PackagesModel model_a), Flakes (PackagesModel model_b) ) ->
{model_a | show = Nothing, result = NotAsked } == {model_b | show = Nothing, result = NotAsked} { model_a | show = Nothing, result = NotAsked } == { model_b | show = Nothing, result = NotAsked }
_ -> _ ->
False False

View file

@ -1,16 +1,29 @@
module Page.Flakes exposing (Model(..), Msg(..), init, makeRequest, update, view) module Page.Flakes exposing
( Model(..)
, Msg(..)
, init
, makeRequest
, update
, view
)
import Browser.Navigation import Browser.Navigation
import Html exposing (Html, a, code, div, li, nav, pre, strong, text, ul) import Html
import Html.Attributes exposing (class, classList, href, target) exposing
import Html.Events exposing (onClick) ( Html
import Html.Parser , a
import Html.Parser.Util , strong
, text
)
import Html.Attributes exposing (href)
import Http exposing (Body) import Http exposing (Body)
import Json.Decode exposing (Decoder)
import Page.Options exposing (Msg(..)) import Page.Options exposing (Msg(..))
import Page.Packages exposing (Msg(..)) import Page.Packages exposing (Msg(..))
import Route exposing (Route(..), SearchArgs, SearchType(..)) import Route
exposing
( Route(..)
, SearchType(..)
)
import Search import Search
import View.Components import View.Components
@ -27,8 +40,6 @@ type Model
init : Route.SearchArgs -> Maybe Model -> ( Model, Cmd Msg ) init : Route.SearchArgs -> Maybe Model -> ( Model, Cmd Msg )
init searchArgs model = init searchArgs model =
let let
-- _ =
-- Debug.log "Flakes" "init"
-- init with respective module or with packages by default -- init with respective module or with packages by default
searchType = searchType =
Maybe.withDefault PackageSearch searchArgs.type_ Maybe.withDefault PackageSearch searchArgs.type_
@ -54,9 +65,6 @@ init searchArgs model =
( newModel, newCmd ) = ( newModel, newCmd ) =
Maybe.withDefault default <| Maybe.map mapEitherModel model Maybe.withDefault default <| Maybe.map mapEitherModel model
-- _ =
-- Debug.log "mapped Model" <| Maybe.map mapEitherModel model
in in
( newModel ( newModel
, newCmd , newCmd
@ -78,17 +86,11 @@ update :
-> Model -> Model
-> ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
update navKey msg model = update navKey msg model =
-- let
-- _ =
-- Debug.log "Flake update" ( msg, model )
-- in
case ( msg, model ) of case ( msg, model ) of
( OptionsMsg msg_, OptionModel model_ ) -> ( OptionsMsg msg_, OptionModel model_ ) ->
case msg_ of case msg_ of
Page.Options.SearchMsg subMsg -> Page.Options.SearchMsg subMsg ->
let let
-- _ =
-- Debug.log "update - options"
( newModel, newCmd ) = ( newModel, newCmd ) =
Search.update Search.update
Route.Flakes Route.Flakes
@ -102,8 +104,6 @@ update navKey msg model =
case msg_ of case msg_ of
Page.Packages.SearchMsg subMsg -> Page.Packages.SearchMsg subMsg ->
let let
-- _ =
-- Debug.log "Flakes" "update - packages"
( newModel, newCmd ) = ( newModel, newCmd ) =
Search.update Search.update
Route.Flakes Route.Flakes
@ -186,9 +186,6 @@ makeRequest options searchType index_id query from size maybeBuckets sort =
(Just "query-options") (Just "query-options")
|> Cmd.map Page.Options.SearchMsg |> Cmd.map Page.Options.SearchMsg
|> Cmd.map OptionsMsg |> Cmd.map OptionsMsg
-- FlakeSearch ->
-- Debug.todo "branch 'FlakeSearch' not implemented"
in in
cmd cmd
@ -201,8 +198,3 @@ makeRequestBody searchType query from size maybeBuckets sort =
PackageSearch -> PackageSearch ->
Page.Packages.makeRequestBody query from size maybeBuckets sort Page.Packages.makeRequestBody query from size maybeBuckets sort
-- FlakeSearch ->
-- Debug.todo "branch 'FlakeSearch' not implemented"

View file

@ -23,7 +23,6 @@ import Html
, div , div
, li , li
, pre , pre
, source
, span , span
, strong , strong
, text , text
@ -45,10 +44,8 @@ import Html.Parser.Util
import Http exposing (Body) import Http exposing (Body)
import Json.Decode import Json.Decode
import Json.Decode.Pipeline import Json.Decode.Pipeline
import List exposing (sort)
import Route exposing (SearchType) import Route exposing (SearchType)
import Search exposing (Details, decodeResolvedFlake) import Search exposing (Details, decodeResolvedFlake)
import Url.Parser exposing (query)
@ -248,31 +245,6 @@ viewResultItem channel _ show item =
isOpen = isOpen =
Just item.source.name == show Just item.source.name == show
githubUrlPrefix branch =
"https://github.com/NixOS/nixpkgs/blob/" ++ branch ++ "/"
cleanPosition value =
if String.startsWith "source/" value then
String.dropLeft 7 value
else
value
asGithubLink value =
case Search.channelDetailsFromId channel of
Just channelDetails ->
a
[ href <| githubUrlPrefix channelDetails.branch ++ (value |> String.replace ":" "#L")
, target "_blank"
]
[ text value ]
Nothing ->
text <| cleanPosition value
sourceFile =
Maybe.map asGithubLink item.source.source
flakeOrNixpkgs = flakeOrNixpkgs =
let let
mkLink flake url = mkLink flake url =

View file

@ -20,7 +20,6 @@ import Html
exposing exposing
( Html ( Html
, a , a
, br
, code , code
, div , div
, em , em
@ -40,19 +39,22 @@ import Html.Attributes
, href , href
, id , id
, target , target
, type_
) )
import Html.Events exposing (onClick) import Html.Events exposing (onClick)
import Http exposing (Body) import Http exposing (Body)
import Json.Decode exposing (Decoder) import Json.Decode
import Json.Decode.Pipeline import Json.Decode.Pipeline
import Json.Encode import Json.Encode
import Maybe import Maybe
import Regex import Regex
import Route exposing (Route(..), SearchType) import Route exposing (Route(..), SearchType)
import Search exposing (Details(..), channelDetailsFromId, decodeResolvedFlake) import Search
exposing
( Details(..)
, decodeResolvedFlake
)
import Utils import Utils
import View.Components.SearchInput exposing (closeButton, viewBucket) import View.Components.SearchInput exposing (viewBucket)
@ -303,7 +305,12 @@ viewResultItem :
-> Html Msg -> Html Msg
viewResultItem channel showInstallDetails show item = viewResultItem channel showInstallDetails show item =
let let
optionals b l = if b then l else [] optionals b l =
if b then
l
else
[]
cleanPosition = cleanPosition =
Regex.fromString "^[0-9a-f]+\\.tar\\.gz\\/" Regex.fromString "^[0-9a-f]+\\.tar\\.gz\\/"
@ -327,88 +334,109 @@ viewResultItem channel showInstallDetails show item =
[ text title ] [ text title ]
shortPackageDetails = shortPackageDetails =
ul [] ( ul []
[ li [] (li []
[ text "Name: " [ text "Name: "
, code [] [ text item.source.pname ] , code [] [ text item.source.pname ]
] ]
] :: (optionals (item.source.pversion /= "")
++ optionals (item.source.pversion /= "") [ li []
[ li [] [ text "Version: "
[ text "Version: " , strong [] [ text item.source.pversion ]
, strong [] [ text item.source.pversion ] ]
]
]
++ optionals (List.length item.source.outputs > 1)
[ li [] (
text "Outputs: "
:: (item.source.outputs
|> List.sort
|> List.map (\o -> code [] [ text o ])
|> List.intersperse (text " "))
)
]
++ (
item.source.homepage
|> List.head
|> Maybe.map
(\x ->
[ li [ trapClick ]
[ createShortDetailsItem "🌐 Homepage" x ]
] ]
) ++ optionals (List.length item.source.outputs > 1)
|> Maybe.withDefault [] [ li []
(text "Outputs: "
:: (item.source.outputs
|> List.sort
|> List.map (\o -> code [] [ text o ])
|> List.intersperse (text " ")
)
)
]
++ (item.source.homepage
|> List.head
|> Maybe.map
(\x ->
[ li [ trapClick ]
[ createShortDetailsItem "🌐 Homepage" x ]
]
)
|> Maybe.withDefault []
)
++ renderSource item channel trapClick createShortDetailsItem createGithubUrl
++ (let
licenses =
item.source.licenses
|> List.filterMap
(\license ->
case ( license.fullName, license.url ) of
( Nothing, Nothing ) ->
Nothing
( Just fullName, Nothing ) ->
Just (text fullName)
( Nothing, Just url ) ->
Just (createShortDetailsItem "Unknown" url)
( Just fullName, Just url ) ->
Just (createShortDetailsItem fullName url)
)
in
optionals (licenses /= [])
[ li []
(text
("License"
++ (if List.length licenses == 1 then
""
else
"s"
)
++ ": "
)
:: List.intersperse (text " ") licenses
)
]
)
)
) )
++ renderSource item channel trapClick createShortDetailsItem createGithubUrl
++ (
let
licenses = item.source.licenses |> List.filterMap
(\license ->
case ( license.fullName, license.url ) of
( Nothing, Nothing ) ->
Nothing
( Just fullName, Nothing ) ->
Just (text fullName)
( Nothing, Just url ) ->
Just (createShortDetailsItem "Unknown" url)
( Just fullName, Just url ) ->
Just (createShortDetailsItem fullName url)
)
in
optionals (licenses /= [])
[ li [] (
text ("License" ++ (if List.length licenses == 1 then "" else "s") ++ ": ")
:: List.intersperse (text " ") licenses
) ]
)
)
showMaintainer maintainer = showMaintainer maintainer =
let let
optionalLink url node = case url of optionalLink url node =
Just u -> a [ href u] [ node ] case url of
Nothing -> node Just u ->
a [ href u ] [ node ]
maybe m d = Maybe.withDefault d m Nothing ->
node
maybe m d =
Maybe.withDefault d m
in in
li [] ( li []
optionalLink (optionalLink
(Maybe.map (String.append "https://github.com/") maintainer.github) (Maybe.map (String.append "https://github.com/") maintainer.github)
(text <| maybe maintainer.name <| maybe maintainer.github "Unknown") (text <| maybe maintainer.name <| maybe maintainer.github "Unknown")
:: case maintainer.email of :: (case maintainer.email of
Just email -> Just email ->
[ text " <" [ text " <"
, a [ href ("mailto:" ++ email) ] [ text email ] , a [ href ("mailto:" ++ email) ] [ text email ]
, text ">" ] , text ">"
Nothing -> [] ]
Nothing ->
[]
)
) )
mailtoAllMaintainers maintainers = mailtoAllMaintainers maintainers =
let let
maintainerMails = List.filterMap (\m -> m.email) maintainers maintainerMails =
List.filterMap (\m -> m.email) maintainers
in in
optionals (List.length maintainerMails > 1) optionals (List.length maintainerMails > 1)
[ li [] [ li []
@ -422,7 +450,8 @@ viewResultItem channel showInstallDetails show item =
case Search.channelDetailsFromId channel of case Search.channelDetailsFromId channel of
Just channelDetails -> Just channelDetails ->
let let
url = "https://hydra.nixos.org/job/" ++ channelDetails.jobset ++ "/nixpkgs." ++ item.source.attr_name ++ "." ++ platform url =
"https://hydra.nixos.org/job/" ++ channelDetails.jobset ++ "/nixpkgs." ++ item.source.attr_name ++ "." ++ platform
in in
li [] [ a [ href url ] [ text platform ] ] li [] [ a [ href url ] [ text platform ] ]
@ -437,10 +466,11 @@ viewResultItem channel showInstallDetails show item =
[ p [] [ text "This package has no maintainers." ] ] [ p [] [ text "This package has no maintainers." ] ]
else else
[ ul [] ( [ ul []
List.map showMaintainer item.source.maintainers (List.map showMaintainer item.source.maintainers
++ mailtoAllMaintainers item.source.maintainers ++ mailtoAllMaintainers item.source.maintainers
) ] )
]
) )
) )
, div [] , div []
@ -458,120 +488,118 @@ viewResultItem channel showInstallDetails show item =
longerPackageDetails = longerPackageDetails =
optionals (Just item.source.attr_name == show) optionals (Just item.source.attr_name == show)
[ div [ trapClick ] [ div [ trapClick ]
( (div []
[ div [] [ h4 []
[ h4 [] [ text "How to install "
[ text "How to install " , em [] [ text item.source.attr_name ]
, em [] [ text item.source.attr_name ] , text "?"
, text "?"
]
, ul [ class "nav nav-tabs" ] <|
Maybe.withDefault
[ li
[ classList
[ ( "active", List.member showInstallDetails [ Search.Unset, Search.FromNixOS, Search.FromFlake ] )
, ( "pull-right", True )
]
]
[ a
[ href "#"
, Search.onClickStop <|
SearchMsg <|
Search.ShowInstallDetails Search.FromNixOS
]
[ text "On NixOS" ]
]
, li
[ classList
[ ( "active", showInstallDetails == Search.FromNixpkgs )
, ( "pull-right", True )
]
]
[ a
[ href "#"
, Search.onClickStop <|
SearchMsg <|
Search.ShowInstallDetails Search.FromNixpkgs
]
[ text "On non-NixOS" ]
]
]
<|
Maybe.map
(\_ ->
[ li
[ classList
[ ( "active", True )
, ( "pull-right", True )
]
]
[ a
[ href "#"
, Search.onClickStop <|
SearchMsg <|
Search.ShowInstallDetails Search.FromFlake
]
[ text "Install from flake" ]
]
]
)
item.source.flakeUrl
, div
[ class "tab-content" ]
<|
Maybe.withDefault
[ div
[ classList
[ ( "active", showInstallDetails == Search.FromNixpkgs )
]
, class "tab-pane"
, id "package-details-nixpkgs"
]
[ pre [ class "code-block" ]
[ text "nix-env -iA nixpkgs."
, strong [] [ text item.source.attr_name ]
]
]
, div
[ classList
[ ( "tab-pane", True )
, ( "active", List.member showInstallDetails [ Search.Unset, Search.FromNixOS, Search.FromFlake ] )
]
]
[ pre [ class "code-block" ]
[ text <| "nix-env -iA nixos."
, strong [] [ text item.source.attr_name ]
]
]
]
<|
Maybe.map
(\url ->
[ div
[ classList
[ ( "tab-pane", True )
, ( "active", True )
]
]
[ pre [ class "code-block" ]
[ text "nix build "
, strong [] [ text url ]
, text "#"
, em [] [ text item.source.attr_name ]
]
]
]
)
<|
Maybe.map Tuple.first item.source.flakeUrl
] ]
, ul [ class "nav nav-tabs" ] <|
Maybe.withDefault
[ li
[ classList
[ ( "active", List.member showInstallDetails [ Search.Unset, Search.FromNixOS, Search.FromFlake ] )
, ( "pull-right", True )
]
]
[ a
[ href "#"
, Search.onClickStop <|
SearchMsg <|
Search.ShowInstallDetails Search.FromNixOS
]
[ text "On NixOS" ]
]
, li
[ classList
[ ( "active", showInstallDetails == Search.FromNixpkgs )
, ( "pull-right", True )
]
]
[ a
[ href "#"
, Search.onClickStop <|
SearchMsg <|
Search.ShowInstallDetails Search.FromNixpkgs
]
[ text "On non-NixOS" ]
]
]
<|
Maybe.map
(\_ ->
[ li
[ classList
[ ( "active", True )
, ( "pull-right", True )
]
]
[ a
[ href "#"
, Search.onClickStop <|
SearchMsg <|
Search.ShowInstallDetails Search.FromFlake
]
[ text "Install from flake" ]
]
]
)
item.source.flakeUrl
, div
[ class "tab-content" ]
<|
Maybe.withDefault
[ div
[ classList
[ ( "active", showInstallDetails == Search.FromNixpkgs )
]
, class "tab-pane"
, id "package-details-nixpkgs"
]
[ pre [ class "code-block" ]
[ text "nix-env -iA nixpkgs."
, strong [] [ text item.source.attr_name ]
]
]
, div
[ classList
[ ( "tab-pane", True )
, ( "active", List.member showInstallDetails [ Search.Unset, Search.FromNixOS, Search.FromFlake ] )
]
]
[ pre [ class "code-block" ]
[ text <| "nix-env -iA nixos."
, strong [] [ text item.source.attr_name ]
]
]
]
<|
Maybe.map
(\url ->
[ div
[ classList
[ ( "tab-pane", True )
, ( "active", True )
]
]
[ pre [ class "code-block" ]
[ text "nix build "
, strong [] [ text url ]
, text "#"
, em [] [ text item.source.attr_name ]
]
]
]
)
<|
Maybe.map Tuple.first item.source.flakeUrl
] ]
++ ( :: ((item.source.longDescription
item.source.longDescription |> Maybe.map (\desc -> [ p [] [ text desc ] ])
|> Maybe.map (\desc -> [ p [] [ text desc ] ]) |> Maybe.withDefault []
|> Maybe.withDefault [] )
) ++ maintainersAndPlatforms
++ maintainersAndPlatforms )
) )
] ]
@ -587,15 +615,15 @@ viewResultItem channel showInstallDetails show item =
flakeOrNixpkgs = flakeOrNixpkgs =
case ( item.source.flakeName, item.source.flakeUrl ) of case ( item.source.flakeName, item.source.flakeUrl ) of
-- its a flake -- its a flake
( Just name, Just ( flakeIdent, flakeUrl ) ) -> ( Just _, Just ( flakeIdent, flakeUrl ) ) ->
[ a [ href flakeUrl ] [ text flakeIdent ] [ a [ href flakeUrl ] [ text flakeIdent ]
, text "#" , text "#"
, a , a
[ onClick toggle [ onClick toggle
, href "" , href ""
] ]
[ text item.source.attr_name ] [ text item.source.attr_name ]
] ]
_ -> _ ->
[ a [ a
@ -610,19 +638,20 @@ viewResultItem channel showInstallDetails show item =
, classList [ ( "opened", isOpen ) ] , classList [ ( "opened", isOpen ) ]
, Search.elementId item.source.attr_name , Search.elementId item.source.attr_name
] ]
( ([ span [] flakeOrNixpkgs
[ span [] flakeOrNixpkgs , div [] [ text <| Maybe.withDefault "" item.source.description ]
, div [] [ text <| Maybe.withDefault "" item.source.description ] , shortPackageDetails
, shortPackageDetails , Search.showMoreButton toggle isOpen
, Search.showMoreButton toggle isOpen ]
] ++ longerPackageDetails ++ longerPackageDetails
) )
renderSource : Search.ResultItem ResultItemSource -> String -> Html.Attribute Msg -> (String -> String -> Html Msg) -> (String -> String -> String) -> List (Html Msg) renderSource : Search.ResultItem ResultItemSource -> String -> Html.Attribute Msg -> (String -> String -> Html Msg) -> (String -> String -> String) -> List (Html Msg)
renderSource item channel trapClick createShortDetailsItem createGithubUrl = renderSource item channel trapClick createShortDetailsItem createGithubUrl =
let let
makeLink text url = [ li [ trapClick ] [ createShortDetailsItem text url ] ] makeLink text url =
[ li [ trapClick ] [ createShortDetailsItem text url ] ]
position = position =
item.source.position item.source.position
@ -631,6 +660,7 @@ renderSource item channel trapClick createShortDetailsItem createGithubUrl =
case Search.channelDetailsFromId channel of case Search.channelDetailsFromId channel of
Nothing -> Nothing ->
[] []
Just channelDetails -> Just channelDetails ->
makeLink "📦 Source" (createGithubUrl channelDetails.branch pos) makeLink "📦 Source" (createGithubUrl channelDetails.branch pos)
) )
@ -791,7 +821,11 @@ decodeResultItemSource =
type alias ResolvedFlake = type alias ResolvedFlake =
{ type_ : String, owner : Maybe String, repo : Maybe String, url : Maybe String } { type_ : String
, owner : Maybe String
, repo : Maybe String
, url : Maybe String
}
decodeResolvedFlake : Json.Decode.Decoder ( String, String ) decodeResolvedFlake : Json.Decode.Decoder ( String, String )

View file

@ -8,11 +8,11 @@ module Route exposing
, href , href
, replaceUrl , replaceUrl
, routeToString , routeToString
, searchTypeToString, searchTypeToTitle , searchTypeToString
, searchTypeToTitle
) )
import Browser.Navigation import Browser.Navigation
import Dict
import Html import Html
import Html.Attributes import Html.Attributes
import Route.SearchQuery exposing (SearchQuery) import Route.SearchQuery exposing (SearchQuery)
@ -33,8 +33,6 @@ type alias SearchArgs =
, from : Maybe Int , from : Maybe Int
, size : Maybe Int , size : Maybe Int
, buckets : Maybe String , buckets : Maybe String
-- TODO: embed sort type
, sort : Maybe String , sort : Maybe String
, type_ : Maybe SearchType , type_ : Maybe SearchType
} }
@ -43,7 +41,10 @@ type alias SearchArgs =
type SearchType type SearchType
= OptionSearch = OptionSearch
| PackageSearch | PackageSearch
-- | FlakeSearch
-- | FlakeSearch
allTypes : List SearchType allTypes : List SearchType
@ -62,7 +63,6 @@ searchTypeFromString string =
-- "flakes" -> -- "flakes" ->
-- Just FlakeSearch -- Just FlakeSearch
_ -> _ ->
Nothing Nothing
@ -76,8 +76,11 @@ searchTypeToString stype =
PackageSearch -> PackageSearch ->
"packages" "packages"
-- FlakeSearch ->
-- "flakes"
-- FlakeSearch ->
-- "flakes"
searchTypeToTitle : SearchType -> String searchTypeToTitle : SearchType -> String
searchTypeToTitle stype = searchTypeToTitle stype =
@ -88,8 +91,11 @@ searchTypeToTitle stype =
PackageSearch -> PackageSearch ->
"Packages" "Packages"
-- FlakeSearch ->
-- "flakes"
-- FlakeSearch ->
-- "flakes"
type alias SearchRoute = type alias SearchRoute =
SearchArgs -> Route SearchArgs -> Route

View file

@ -1,6 +1,7 @@
module Search exposing module Search exposing
( Aggregation ( Aggregation
, AggregationsBucketItem , AggregationsBucketItem
, Details(..)
, Model , Model
, Msg(..) , Msg(..)
, Options , Options
@ -15,8 +16,6 @@ module Search exposing
, decodeResult , decodeResult
, defaultFlakeId , defaultFlakeId
, elementId , elementId
-- , flakeFromId
-- , flakes
, fromSortId , fromSortId
, init , init
, makeRequest , makeRequest
@ -27,11 +26,12 @@ module Search exposing
, trapClick , trapClick
, update , update
, view , view
, viewResult, Details(..) , viewResult
) )
import Base64 import Base64
import Browser.Dom import Browser.Dom
import Browser.Events exposing (Visibility(..))
import Browser.Navigation import Browser.Navigation
import Html import Html
exposing exposing
@ -74,11 +74,10 @@ import Json.Decode
import Json.Decode.Pipeline import Json.Decode.Pipeline
import Json.Encode import Json.Encode
import RemoteData import RemoteData
import Route exposing (SearchArgs, SearchType) import Route exposing (SearchType)
import Route.SearchQuery import Route.SearchQuery
import Set import Set
import Task import Task
import Browser.Events exposing (Visibility(..))
type alias Model a b = type alias Model a b =
@ -146,7 +145,11 @@ type Sort
type alias ResolvedFlake = type alias ResolvedFlake =
{ type_ : String, owner : Maybe String, repo : Maybe String, url : Maybe String } { type_ : String
, owner : Maybe String
, repo : Maybe String
, url : Maybe String
}
decodeResolvedFlake : Json.Decode.Decoder String decodeResolvedFlake : Json.Decode.Decoder String
@ -198,22 +201,6 @@ init :
-> ( Model a b, Cmd (Msg a b) ) -> ( Model a b, Cmd (Msg a b) )
init args maybeModel = init args maybeModel =
let let
emptyRoute : Route.SearchArgs
emptyRoute =
{ query = Nothing
, channel = Nothing
, show = Nothing
, from = Nothing
, size = Nothing
, buckets = Nothing
-- TODO= Nothing type
, sort = Nothing
, type_ = Nothing
}
-- args =
-- Maybe.withDefault emptyRoute maybeArgs
getField getFn default = getField getFn default =
maybeModel maybeModel
|> Maybe.map getFn |> Maybe.map getFn
@ -302,11 +289,14 @@ type Msg a b
| ChangePage Int | ChangePage Int
| ShowInstallDetails Details | ShowInstallDetails Details
type Details type Details
= FromNixpkgs = FromNixpkgs
| FromNixOS | FromNixOS
| FromFlake | FromFlake
| Unset | Unset
scrollToEntry : scrollToEntry :
Maybe String Maybe String
-> Cmd (Msg a b) -> Cmd (Msg a b)
@ -532,19 +522,12 @@ channels =
] ]
type alias Flake =
{ id : String
, isNixpkgs : Bool
, title : String
, source : String
}
defaultFlakeId : String defaultFlakeId : String
defaultFlakeId = defaultFlakeId =
"group-manual" "group-manual"
-- flakeFromId : String -> Maybe Flake -- flakeFromId : String -> Maybe Flake
-- flakeFromId flake_id = -- flakeFromId flake_id =
-- let -- let
@ -812,7 +795,7 @@ viewResult :
viewResult outMsg toRoute categoryName model viewSuccess viewBuckets searchBuckets = viewResult outMsg toRoute categoryName model viewSuccess viewBuckets searchBuckets =
case model.result of case model.result of
RemoteData.NotAsked -> RemoteData.NotAsked ->
div [] [ ] div [] []
RemoteData.Loading -> RemoteData.Loading ->
div [ class "loader-wrapper" ] div [ class "loader-wrapper" ]
@ -976,7 +959,7 @@ viewResults :
-> (Msg a b -> c) -> (Msg a b -> c)
-> String -> String
-> List (Html c) -> List (Html c)
viewResults model result viewSuccess toRoute outMsg categoryName = viewResults model result viewSuccess _ outMsg categoryName =
let let
from = from =
String.fromInt (model.from + 1) String.fromInt (model.from + 1)
@ -1313,8 +1296,12 @@ makeRequest :
-> Maybe String -> Maybe String
-> Cmd (Msg a b) -> Cmd (Msg a b)
makeRequest body channel decodeResultItemSource decodeResultAggregations options responseMsg tracker = makeRequest body channel decodeResultItemSource decodeResultAggregations options responseMsg tracker =
let branch = Maybe.map (\details -> details.branch) (channelDetailsFromId channel) |> Maybe.withDefault channel let
index = "latest-" ++ String.fromInt options.mappingSchemaVersion ++ "-" ++ branch branch =
Maybe.map (\details -> details.branch) (channelDetailsFromId channel) |> Maybe.withDefault channel
index =
"latest-" ++ String.fromInt options.mappingSchemaVersion ++ "-" ++ branch
in in
Http.riskyRequest Http.riskyRequest
{ method = "POST" { method = "POST"

View file

@ -1,10 +1,16 @@
module View.Components exposing (..) module View.Components exposing (body)
import Html exposing (Html) import Html exposing (Html)
import Route exposing (SearchRoute) import Route exposing (SearchRoute)
import Search exposing (Model, Msg, ResultItem, SearchResult) import Search
exposing
( Details
, Model
, Msg
, ResultItem
, SearchResult
)
import View.Components.Body import View.Components.Body
import Search exposing (Details)
body : body :

View file

@ -1,15 +1,29 @@
module View.Components.Body exposing (..) module View.Components.Body exposing (view)
import Html exposing (Html, div, h1) import Html
exposing
( Html
, div
, h1
)
import Html.Attributes exposing (class) import Html.Attributes exposing (class)
import Html.Events exposing (onClick) import Html.Events exposing (onClick)
import RemoteData exposing (RemoteData(..)) import RemoteData exposing (RemoteData(..))
import Route import Route
import Search exposing (Model, Msg(..), ResultItem, SearchResult, viewResult) import Search
import View.Components.SearchInput exposing (viewSearchInput) exposing
import View.Components.SearchInput exposing (viewFlakes) ( Details
import Html exposing (details) , Model
import Search exposing (Details) , Msg(..)
, ResultItem
, SearchResult
, viewResult
)
import View.Components.SearchInput
exposing
( viewFlakes
, viewSearchInput
)
view : view :
@ -47,7 +61,6 @@ view { toRoute, categoryName } title model viewSuccess viewBuckets outMsg =
RemoteData.Failure _ -> RemoteData.Failure _ ->
"failure" "failure"
in in
div div
(List.append (List.append

View file

@ -1,9 +1,47 @@
module View.Components.SearchInput exposing (..) module View.Components.SearchInput exposing
( closeButton
, viewBucket
, viewFlakes
, viewSearchInput
)
import Html exposing (Html, a, button, div, form, h4, input, li, p, span, text, th, ul) import Html
import Html.Attributes exposing (attribute, autofocus, class, classList, href, id, placeholder, selected, type_, value) exposing
import Html.Events exposing (onClick, onInput, onSubmit) ( Html
import Route exposing (SearchType, allTypes, searchTypeToString, searchTypeToTitle) , a
, button
, div
, form
, input
, li
, span
, text
, ul
)
import Html.Attributes
exposing
( autofocus
, class
, classList
, href
, id
, placeholder
, type_
, value
)
import Html.Events
exposing
( onClick
, onInput
, onSubmit
)
import Route
exposing
( SearchType
, allTypes
, searchTypeToString
, searchTypeToTitle
)
import Search exposing (Msg(..)) import Search exposing (Msg(..))
@ -40,7 +78,7 @@ viewSearchInput outMsg category searchQuery =
viewFlakes : (Msg a b -> msg) -> String -> SearchType -> List (Html msg) viewFlakes : (Msg a b -> msg) -> String -> SearchType -> List (Html msg)
viewFlakes outMsg selectedFlake selectedCategory = viewFlakes outMsg _ selectedCategory =
[ li [] [ li []
[ ul [] [ ul []
(List.map (List.map