Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the channel importer versions dynamic #455

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
39d768c
Make the channel importer versions dynamic
dasJ Mar 29, 2022
e48ea62
Merge remote-tracking branch 'origin/main' into feat/dynamic-import
garbas Apr 7, 2022
02f2db1
few things fromt he list
garbas Apr 7, 2022
e3d3fc1
Decode nixosChannels in Elm
garbas Apr 7, 2022
de30398
Use nixosChannels that came via application flag
garbas Apr 12, 2022
72748d8
Merge remote-tracking branch 'origin/main' into feat/dynamic-import
garbas Apr 12, 2022
28a2d4d
read nixos channels in github action
garbas Apr 12, 2022
6a50ea0
defaultNixOSChannel should be calculated
garbas Apr 14, 2022
b45ccc0
add two pointers where the check should be added
garbas Apr 14, 2022
5ce774b
pass nixosChannels to flake-info and remove title, rather calculate it
garbas Apr 15, 2022
898cf31
Add NixosChannels struct validation and validation Error
ysndr Apr 15, 2022
b23fc2d
Read NIXOS_CHANNEL variable
ysndr Apr 15, 2022
a631802
Check channel
ysndr Apr 15, 2022
f14ff5f
Add channel struct to fix parsing NIXOS_CHANNELS
ysndr Apr 15, 2022
ecce987
Use `eachDefaultSystem` instead of listing them manually
ysndr Apr 17, 2022
638da42
Add individual dev shells for frontend and backend
ysndr Apr 17, 2022
893d01c
Update .github/workflows/import-to-elasticsearch.yml
garbas Apr 20, 2022
687cc09
use both development environments by default (as it was)
garbas Apr 20, 2022
ebb94a3
pkgs.lib → lib everywhere
garbas Apr 20, 2022
a7645ae
Update flake.nix
garbas Apr 20, 2022
50c4eb7
Merge remote-tracking branch 'origin/main' into feat/dynamic-import
garbas Apr 20, 2022
9fd5827
Merge branch 'feat/dynamic-import' of github.com:dasJ/nixos-search in…
garbas Apr 20, 2022
82bbcd3
typo
garbas Apr 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions .github/workflows/import-to-elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,34 @@ on:

jobs:

nixos-channels:
runs-on: ubuntu-latest

outputs:
 nixos-channels: "${{ steps.nixos-channels.outputs.nixos-channels }}"

steps:
 - name: Setup
 uses: ./.github/actions/common-setup
 with:
 CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }}
 - name: NixOS Channels
 id: nixos-channels
run: |
nix build -L .#nixosChannels
 channels="$(cat ./result)"
 echo ::set-output name=nixos-channels::${channels}
garbas marked this conversation as resolved.
Show resolved Hide resolved

import-nixpkgs:
needs: nixos-channels
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
channel:
- unstable
- 21.11
channel: ${{ fromJSON(needs.nixos-channels.outputs.nixos-channels}}

env:
RUST_LOG: debug
Expand Down Expand Up @@ -50,7 +69,6 @@ jobs:
if: github.repository_owner == 'NixOS'



import-flakes:
runs-on: ubuntu-latest

Expand Down
22 changes: 15 additions & 7 deletions flake-info/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ pkgs ? import <nixpkgs> { } }: with pkgs;
rustPlatform.buildRustPackage rec {
{ pkgs ? import <nixpkgs> { }
}:
pkgs.rustPlatform.buildRustPackage rec {
name = "flake-info";
src = ./.;
cargoLock = {
Expand All @@ -8,11 +9,18 @@ rustPlatform.buildRustPackage rec {
"elasticsearch-8.0.0-alpha.1" = "sha256-gjmk3Q3LTAvLhzQ+k1knSp1HBwtqNiubjXNnLy/cS5M=";
};
};
nativeBuildInputs = [ pkg-config ];
buildInputs = [ openssl openssl.dev makeWrapper ]
++ lib.optional pkgs.stdenv.isDarwin [ libiconv darwin.apple_sdk.frameworks.Security ];
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs =
with pkgs; [
openssl
openssl.dev
makeWrapper
] ++ lib.optional pkgs.stdenv.isDarwin [
libiconv
darwin.apple_sdk.frameworks.Security
];

checkInputs = [ pandoc ];
checkInputs = with pkgs; [ pandoc ];

NIXPKGS_PANDOC_FILTERS_PATH = "${pkgs.path + "/doc/build-aux/pandoc-filters"}";

Expand All @@ -24,6 +32,6 @@ rustPlatform.buildRustPackage rec {
postInstall = ''
wrapProgram $out/bin/flake-info \
--set NIXPKGS_PANDOC_FILTERS_PATH "${NIXPKGS_PANDOC_FILTERS_PATH}" \
--prefix PATH : ${pandoc}/bin
--prefix PATH : ${pkgs.pandoc}/bin
'';
}
6 changes: 6 additions & 0 deletions flake-info/src/bin/flake-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ async fn run_command(
Ok((exports, ident))
}
Command::Nixpkgs { channel } => {
// TODO: if NIXOS_CHANNELS environment variable is present check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karantan @ysndr This is where step number 7 should be implemented. I've also added the instructions

// that channel passed here is one of the channels in
// NIXOS_CHANNELS
let nixpkgs = Source::nixpkgs(channel)
.await
.map_err(FlakeInfoError::Nixpkgs)?;
Expand All @@ -251,6 +254,9 @@ async fn run_command(
Ok((exports, ident))
}
Command::NixpkgsArchive { source, channel } => {
// TODO: if NIXOS_CHANNELS environment variable is present check
ysndr marked this conversation as resolved.
Show resolved Hide resolved
// that channel passed here is one of the channels in
// NIXOS_CHANNELS
let ident = (
"nixos".to_string(),
channel.to_owned(),
Expand Down
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
# inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
inputs.nixpkgs.url = "github:aforemny/nixpkgs/fix/elm-format";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixos-org-configurations.url = "github:NixOS/nixos-org-configurations";
inputs.nixos-org-configurations.flake = false;

outputs = { self
, nixpkgs
, flake-utils
, nixos-org-configurations
}:
flake-utils.lib.eachSystem
(with flake-utils.lib.system; [
Expand All @@ -26,17 +29,64 @@
let
pkgs = nixpkgs.legacyPackages.${system};
warnToUpgradeNix = pkgs.lib.warn "Please upgrade Nix to 2.7 or later.";
version = pkgs.lib.removeSuffix "\n" (builtins.readFile ./VERSION);
garbas marked this conversation as resolved.
Show resolved Hide resolved
allChannels = (import "${nixos-org-configurations}/channels.nix").channels;
filteredChannels =
pkgs.lib.filterAttrs
(n: v:
builtins.elem v.status ["beta" "stable" "rolling"] &&
pkgs.lib.hasPrefix "nixos-" n &&
v ? variant && v.variant == "primary"
)
allChannels;
channels =
builtins.map
(n: let v = filteredChannels.${n}; in
{
id = pkgs.lib.removePrefix "nixos-" n;
status = v.status;
jobset =
builtins.concatStringsSep
"/"
(pkgs.lib.init (pkgs.lib.splitString "/" v.job));
branch = n;
}
)
(builtins.attrNames filteredChannels);
defaultChannel =
builtins.head
(builtins.sort (e1: e2: ! (builtins.lessThan e1 e2))
(builtins.map
(pkgs.lib.removePrefix "nixos-")
(builtins.attrNames
(pkgs.lib.filterAttrs (_: v: v.status == "stable") filteredChannels)
)
)
);
nixosChannels = pkgs.runCommand "nixosChannels.json" {} ''
echo '${builtins.toJSON (builtins.map (c: c.id) channels)}' > $out
'';
in rec {

packages.default = packages.flake-info;
packages.flake-info = import ./flake-info { inherit pkgs; };
packages.frontend = import ./frontend { inherit pkgs; };
packages.frontend = import ./frontend { inherit pkgs channels version; };
packages.nixosChannels = nixosChannels;

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}";
export NIXOS_CHANNELS='${builtins.toJSON { inherit defaultChannel channels; }}';
export ELASTICSEARCH_MAPPING_SCHEMA_VERSION="${version}";
export PATH=$PWD/frontend/node_modules/.bin:$PATH

rm -rf frontend/node_modules
ln -sf ${packages.frontend.yarnPkg}/libexec/${(builtins.parseDrvName packages.frontend.name).name}/node_modules frontend/
echo "========================================================"
echo "= To develop the frontend run: cd frontend && yarn dev ="
echo "========================================================"
'';
};

Expand Down
17 changes: 6 additions & 11 deletions frontend/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ pkgs ? import <nixpkgs> { }
, version ? pkgs.lib.removeSuffix "\n" (builtins.readFile ../VERSION)
, channels
, version
}:
let
package = builtins.fromJSON (builtins.readFile ./package.json);
Expand Down Expand Up @@ -52,6 +53,9 @@ pkgs.stdenv.mkDerivation {
elm-analyse
]);

ELASTICSEARCH_MAPPING_SCHEMA_VERSION = version;
NIXOS_CHANNELS = builtins.toJSON channels;

configurePhase = pkgs.elmPackages.fetchElmDeps {
elmPackages = import ./elm-srcs.nix;
elmVersion = pkgs.elmPackages.elm.version;
Expand All @@ -66,7 +70,6 @@ pkgs.stdenv.mkDerivation {
buildPhase = ''
# Yarn writes cache directories etc to $HOME.
export HOME=$PWD/yarn_home
sed -i -e "s|process.env.ELASTICSEARCH_MAPPING_SCHEMA_VERSION|${version}|" src/index.js
yarn prod
'';

Expand All @@ -75,14 +78,6 @@ pkgs.stdenv.mkDerivation {
cp -R ./dist/* $out/
cp netlify.toml $out/
'';
shellHook = ''
rm -rf frontend/node_modules
ln -sf ${yarnPkg}/libexec/${package.name}/node_modules frontend/
export PATH=$PWD/frontend/node_modules/.bin:$PATH
export ELASTICSEARCH_MAPPING_SCHEMA_VERSION=${version}
echo "============================"
echo "= To develop the frontend run: cd frontend && yarn dev ="
echo "============================"
'';

passthru.yarnPkg = yarnPkg;
}
42 changes: 31 additions & 11 deletions frontend/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ import Html.Attributes
, id
, src
)
import Json.Decode
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 Search
exposing
( Msg(..)
, NixOSChannel
, decodeNixOSChannels
, defaultFlakeId
)
import Url


Expand All @@ -44,13 +51,16 @@ type alias Flags =
, elasticsearchUrl : String
, elasticsearchUsername : String
, elasticsearchPassword : String
, nixosChannels : Json.Decode.Value
}


type alias Model =
{ navKey : Browser.Navigation.Key
, route : Route.Route
, elasticsearch : Search.Options
, defaultNixOSChannel : String
, nixosChannels : List NixOSChannel
, page : Page
}

Expand All @@ -70,6 +80,13 @@ init :
-> ( Model, Cmd Msg )
init flags url navKey =
let
nixosChannels =
case Json.Decode.decodeValue decodeNixOSChannels flags.nixosChannels of
Ok c ->
c

Err _ ->
{ default = "", channels = [] }
model =
{ navKey = navKey
, elasticsearch =
Expand All @@ -78,6 +95,8 @@ init flags url navKey =
flags.elasticsearchUrl
flags.elasticsearchUsername
flags.elasticsearchPassword
, defaultNixOSChannel = nixosChannels.default
, nixosChannels = nixosChannels.channels
, page = NotFound
, route = Route.Home
}
Expand Down Expand Up @@ -127,6 +146,7 @@ attemptQuery (( model, _ ) as pair) =
, Cmd.map msg <|
makeRequest
model.elasticsearch
model.nixosChannels
searchModel.searchType
searchModel.channel
(Maybe.withDefault "" searchModel.query)
Expand Down Expand Up @@ -239,7 +259,7 @@ changeRouteTo currentModel url =
_ ->
Nothing
in
Page.Packages.init searchArgs modelPage
Page.Packages.init searchArgs currentModel.defaultNixOSChannel currentModel.nixosChannels modelPage
|> updateWith Packages PackagesMsg model
|> avoidReinit
|> attemptQuery
Expand All @@ -254,7 +274,7 @@ changeRouteTo currentModel url =
_ ->
Nothing
in
Page.Options.init searchArgs modelPage
Page.Options.init searchArgs currentModel.defaultNixOSChannel currentModel.nixosChannels modelPage
|> updateWith Options OptionsMsg model
|> avoidReinit
|> attemptQuery
Expand All @@ -269,7 +289,7 @@ changeRouteTo currentModel url =
_ ->
Nothing
in
Page.Flakes.init searchArgs modelPage
Page.Flakes.init searchArgs currentModel.defaultNixOSChannel currentModel.nixosChannels modelPage
|> updateWith Flakes FlakesMsg model
|> avoidReinit
|> attemptQuery
Expand Down Expand Up @@ -300,19 +320,19 @@ update msg model =
changeRouteTo model url

( HomeMsg subMsg, Home subModel ) ->
Page.Home.update subMsg subModel
Page.Home.update subMsg subModel model.nixosChannels
|> updateWith Home HomeMsg model

( PackagesMsg subMsg, Packages subModel ) ->
Page.Packages.update model.navKey subMsg subModel
Page.Packages.update model.navKey subMsg subModel model.nixosChannels
|> updateWith Packages PackagesMsg model

( OptionsMsg subMsg, Options subModel ) ->
Page.Options.update model.navKey subMsg subModel
Page.Options.update model.navKey subMsg subModel model.nixosChannels
|> updateWith Options OptionsMsg model

( FlakesMsg subMsg, Flakes subModel ) ->
Page.Flakes.update model.navKey subMsg subModel
Page.Flakes.update model.navKey subMsg subModel model.nixosChannels
|> updateWith Flakes FlakesMsg model

( _, _ ) ->
Expand Down Expand Up @@ -436,13 +456,13 @@ viewPage model =
div [] [ text "Welcome" ]

Packages packagesModel ->
Html.map (\m -> PackagesMsg m) <| Page.Packages.view packagesModel
Html.map (\m -> PackagesMsg m) <| Page.Packages.view model.nixosChannels packagesModel

Options optionsModel ->
Html.map (\m -> OptionsMsg m) <| Page.Options.view optionsModel
Html.map (\m -> OptionsMsg m) <| Page.Options.view model.nixosChannels optionsModel

Flakes flakesModel ->
Html.map (\m -> FlakesMsg m) <| Page.Flakes.view flakesModel
Html.map (\m -> FlakesMsg m) <| Page.Flakes.view model.nixosChannels flakesModel



Expand Down
Loading