* 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-*
result
src-url
.direnv/

View file

@ -1,5 +1,20 @@
{
"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": {
"locked": {
"lastModified": 1642903813,
@ -17,6 +32,7 @@
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}

View file

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

View file

@ -6,7 +6,6 @@ import Html
exposing
( Html
, a
, button
, div
, footer
, header
@ -20,25 +19,20 @@ import Html
)
import Html.Attributes
exposing
( attribute
, class
( class
, classList
, href
, id
, src
, type_
)
import Page.Flakes exposing (Model(..))
import Page.Home
import Page.Options
import Page.Packages
import RemoteData exposing (RemoteData(..))
import Route exposing (SearchType(..))
import Search exposing (Msg(..), defaultFlakeId)
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 ) ->
{ model_a | show = Nothing, showInstallDetails = Search.Unset, result = NotAsked }
== { model_b | show = Nothing, showInstallDetails = Search.Unset, result = NotAsked }
( 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) ) ->
{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) ) ->
{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

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

View file

@ -23,7 +23,6 @@ import Html
, div
, li
, pre
, source
, span
, strong
, text
@ -45,10 +44,8 @@ import Html.Parser.Util
import Http exposing (Body)
import Json.Decode
import Json.Decode.Pipeline
import List exposing (sort)
import Route exposing (SearchType)
import Search exposing (Details, decodeResolvedFlake)
import Url.Parser exposing (query)
@ -248,31 +245,6 @@ viewResultItem channel _ show item =
isOpen =
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 =
let
mkLink flake url =

View file

@ -20,7 +20,6 @@ import Html
exposing
( Html
, a
, br
, code
, div
, em
@ -40,19 +39,22 @@ import Html.Attributes
, href
, id
, target
, type_
)
import Html.Events exposing (onClick)
import Http exposing (Body)
import Json.Decode exposing (Decoder)
import Json.Decode
import Json.Decode.Pipeline
import Json.Encode
import Maybe
import Regex
import Route exposing (Route(..), SearchType)
import Search exposing (Details(..), channelDetailsFromId, decodeResolvedFlake)
import Search
exposing
( Details(..)
, decodeResolvedFlake
)
import Utils
import View.Components.SearchInput exposing (closeButton, viewBucket)
import View.Components.SearchInput exposing (viewBucket)
@ -303,7 +305,12 @@ viewResultItem :
-> Html Msg
viewResultItem channel showInstallDetails show item =
let
optionals b l = if b then l else []
optionals b l =
if b then
l
else
[]
cleanPosition =
Regex.fromString "^[0-9a-f]+\\.tar\\.gz\\/"
@ -327,88 +334,109 @@ viewResultItem channel showInstallDetails show item =
[ text title ]
shortPackageDetails =
ul [] (
[ li []
ul []
(li []
[ text "Name: "
, code [] [ text item.source.pname ]
]
]
++ optionals (item.source.pversion /= "")
[ li []
[ text "Version: "
, 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 (item.source.pversion /= "")
[ li []
[ text "Version: "
, strong [] [ text item.source.pversion ]
]
]
)
|> Maybe.withDefault []
++ 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 ]
]
)
|> 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 =
let
optionalLink url node = case url of
Just u -> a [ href u] [ node ]
Nothing -> node
optionalLink url node =
case url of
Just u ->
a [ href u ] [ node ]
maybe m d = Maybe.withDefault d m
Nothing ->
node
maybe m d =
Maybe.withDefault d m
in
li [] (
optionalLink
li []
(optionalLink
(Maybe.map (String.append "https://github.com/") maintainer.github)
(text <| maybe maintainer.name <| maybe maintainer.github "Unknown")
:: case maintainer.email of
Just email ->
[ text " <"
, a [ href ("mailto:" ++ email) ] [ text email ]
, text ">" ]
Nothing -> []
:: (case maintainer.email of
Just email ->
[ text " <"
, a [ href ("mailto:" ++ email) ] [ text email ]
, text ">"
]
Nothing ->
[]
)
)
mailtoAllMaintainers maintainers =
let
maintainerMails = List.filterMap (\m -> m.email) maintainers
maintainerMails =
List.filterMap (\m -> m.email) maintainers
in
optionals (List.length maintainerMails > 1)
[ li []
@ -422,7 +450,8 @@ viewResultItem channel showInstallDetails show item =
case Search.channelDetailsFromId channel of
Just channelDetails ->
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
li [] [ a [ href url ] [ text platform ] ]
@ -437,10 +466,11 @@ viewResultItem channel showInstallDetails show item =
[ p [] [ text "This package has no maintainers." ] ]
else
[ ul [] (
List.map showMaintainer item.source.maintainers
++ mailtoAllMaintainers item.source.maintainers
) ]
[ ul []
(List.map showMaintainer item.source.maintainers
++ mailtoAllMaintainers item.source.maintainers
)
]
)
)
, div []
@ -458,120 +488,118 @@ viewResultItem channel showInstallDetails show item =
longerPackageDetails =
optionals (Just item.source.attr_name == show)
[ div [ trapClick ]
(
[ div []
[ h4 []
[ text "How to install "
, em [] [ text item.source.attr_name ]
, 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
(div []
[ h4 []
[ text "How to install "
, em [] [ text item.source.attr_name ]
, 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
]
++ (
item.source.longDescription
|> Maybe.map (\desc -> [ p [] [ text desc ] ])
|> Maybe.withDefault []
)
++ maintainersAndPlatforms
:: ((item.source.longDescription
|> Maybe.map (\desc -> [ p [] [ text desc ] ])
|> Maybe.withDefault []
)
++ maintainersAndPlatforms
)
)
]
@ -587,15 +615,15 @@ viewResultItem channel showInstallDetails show item =
flakeOrNixpkgs =
case ( item.source.flakeName, item.source.flakeUrl ) of
-- its a flake
( Just name, Just ( flakeIdent, flakeUrl ) ) ->
[ a [ href flakeUrl ] [ text flakeIdent ]
, text "#"
, a
[ onClick toggle
, href ""
]
[ text item.source.attr_name ]
]
( Just _, Just ( flakeIdent, flakeUrl ) ) ->
[ a [ href flakeUrl ] [ text flakeIdent ]
, text "#"
, a
[ onClick toggle
, href ""
]
[ text item.source.attr_name ]
]
_ ->
[ a
@ -610,19 +638,20 @@ viewResultItem channel showInstallDetails show item =
, classList [ ( "opened", isOpen ) ]
, Search.elementId item.source.attr_name
]
(
[ span [] flakeOrNixpkgs
, div [] [ text <| Maybe.withDefault "" item.source.description ]
, shortPackageDetails
, Search.showMoreButton toggle isOpen
] ++ longerPackageDetails
([ span [] flakeOrNixpkgs
, div [] [ text <| Maybe.withDefault "" item.source.description ]
, shortPackageDetails
, Search.showMoreButton toggle isOpen
]
++ longerPackageDetails
)
renderSource : Search.ResultItem ResultItemSource -> String -> Html.Attribute Msg -> (String -> String -> Html Msg) -> (String -> String -> String) -> List (Html Msg)
renderSource item channel trapClick createShortDetailsItem createGithubUrl =
let
makeLink text url = [ li [ trapClick ] [ createShortDetailsItem text url ] ]
makeLink text url =
[ li [ trapClick ] [ createShortDetailsItem text url ] ]
position =
item.source.position
@ -631,6 +660,7 @@ renderSource item channel trapClick createShortDetailsItem createGithubUrl =
case Search.channelDetailsFromId channel of
Nothing ->
[]
Just channelDetails ->
makeLink "📦 Source" (createGithubUrl channelDetails.branch pos)
)
@ -791,7 +821,11 @@ decodeResultItemSource =
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 )

View file

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

View file

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

View file

@ -1,10 +1,16 @@
module View.Components exposing (..)
module View.Components exposing (body)
import Html exposing (Html)
import Route exposing (SearchRoute)
import Search exposing (Model, Msg, ResultItem, SearchResult)
import Search
exposing
( Details
, Model
, Msg
, ResultItem
, SearchResult
)
import View.Components.Body
import Search exposing (Details)
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.Events exposing (onClick)
import RemoteData exposing (RemoteData(..))
import Route
import Search exposing (Model, Msg(..), ResultItem, SearchResult, viewResult)
import View.Components.SearchInput exposing (viewSearchInput)
import View.Components.SearchInput exposing (viewFlakes)
import Html exposing (details)
import Search exposing (Details)
import Search
exposing
( Details
, Model
, Msg(..)
, ResultItem
, SearchResult
, viewResult
)
import View.Components.SearchInput
exposing
( viewFlakes
, viewSearchInput
)
view :
@ -47,7 +61,6 @@ view { toRoute, categoryName } title model viewSuccess viewBuckets outMsg =
RemoteData.Failure _ ->
"failure"
in
div
(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.Attributes exposing (attribute, autofocus, class, classList, href, id, placeholder, selected, type_, value)
import Html.Events exposing (onClick, onInput, onSubmit)
import Route exposing (SearchType, allTypes, searchTypeToString, searchTypeToTitle)
import Html
exposing
( Html
, 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(..))
@ -40,7 +78,7 @@ viewSearchInput outMsg category searchQuery =
viewFlakes : (Msg a b -> msg) -> String -> SearchType -> List (Html msg)
viewFlakes outMsg selectedFlake selectedCategory =
viewFlakes outMsg _ selectedCategory =
[ li []
[ ul []
(List.map