From f504a9fdd73a8572a7b6270dd6fd1ce54d3bb29f Mon Sep 17 00:00:00 2001 From: MatthewCroughan Date: Thu, 11 Aug 2022 14:35:57 +0100 Subject: [PATCH] encourage NixOS configuration, nix-shell and discourage nix-env (#514) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Naïm Favier --- frontend/src/Page/Packages.elm | 139 +++++++++++++++++++++++++++++---- frontend/src/Search.elm | 5 +- frontend/src/index.less | 20 ++--- 3 files changed, 135 insertions(+), 29 deletions(-) diff --git a/frontend/src/Page/Packages.elm b/frontend/src/Page/Packages.elm index b6f744d..f94c8f6 100644 --- a/frontend/src/Page/Packages.elm +++ b/frontend/src/Page/Packages.elm @@ -506,6 +506,11 @@ viewResultItem nixosChannels channel showInstallDetails show item = optionals (Just item.source.attr_name == show) [ div [ trapClick ] (div [] + (item.source.longDescription + |> Maybe.map (\desc -> [ p [] [ text desc ] ]) + |> Maybe.withDefault [] + ) + :: div [] [ h4 [] [ text "How to install " , em [] [ text item.source.attr_name ] @@ -515,7 +520,7 @@ viewResultItem nixosChannels channel showInstallDetails show item = Maybe.withDefault [ li [ classList - [ ( "active", List.member showInstallDetails [ Search.Unset, Search.FromNixOS, Search.FromFlake ] ) + [ ( "active", List.member showInstallDetails [ Search.Unset, Search.ViaNixOS, Search.FromFlake ] ) , ( "pull-right", True ) ] ] @@ -523,13 +528,13 @@ viewResultItem nixosChannels channel showInstallDetails show item = [ href "#" , Search.onClickStop <| SearchMsg <| - Search.ShowInstallDetails Search.FromNixOS + Search.ShowInstallDetails Search.ViaNixOS ] - [ text "On NixOS" ] + [ text "NixOS Configuration" ] ] , li [ classList - [ ( "active", showInstallDetails == Search.FromNixpkgs ) + [ ( "active", showInstallDetails == Search.ViaNixShell ) , ( "pull-right", True ) ] ] @@ -537,9 +542,23 @@ viewResultItem nixosChannels channel showInstallDetails show item = [ href "#" , Search.onClickStop <| SearchMsg <| - Search.ShowInstallDetails Search.FromNixpkgs + Search.ShowInstallDetails Search.ViaNixShell ] - [ text "On non-NixOS" ] + [ text "nix-shell" ] + ] + , li + [ classList + [ ( "active", showInstallDetails == Search.ViaNixEnv ) + , ( "pull-right", True ) + ] + ] + [ a + [ href "#" + , Search.onClickStop <| + SearchMsg <| + Search.ShowInstallDetails Search.ViaNixEnv + ] + [ text "nix-env" ] ] ] <| @@ -568,12 +587,63 @@ viewResultItem nixosChannels channel showInstallDetails show item = Maybe.withDefault [ div [ classList - [ ( "active", showInstallDetails == Search.FromNixpkgs ) + [ ( "tab-pane", True ) + , ( "active", showInstallDetails == Search.ViaNixEnv ) + ] + ] + [ p [] + [ strong [] [ text "Warning:" ] + , text """ + Using nix-env permanently modifies a + local profile of installed packages. + This must be cleaned up, updated and + maintained by the user, in the same + way as a traditional package + manager. Using nix-shell or a NixOS + configuration is recommended + instead. + """ + ] + ] + , div + [ classList + [ ( "active", showInstallDetails == Search.ViaNixEnv ) + ] + , class "tab-pane" + ] + [ p [] + [ strong [] [ text "On NixOS:" ] ] + ] + , div + [ classList + [ ( "active", showInstallDetails == Search.ViaNixEnv ) ] , class "tab-pane" , id "package-details-nixpkgs" ] - [ pre [ class "code-block" ] + [ pre [ class "code-block shell-command" ] + [ text "nix-env -iA nixos." + , strong [] [ text item.source.attr_name ] + ] + ] + , div [] [ p [] [] ] + , div + [ classList + [ ( "active", showInstallDetails == Search.ViaNixEnv ) + ] + , class "tab-pane" + ] + [ p [] + [ strong [] [ text "On Non NixOS:" ] ] + ] + , div + [ classList + [ ( "active", showInstallDetails == Search.ViaNixEnv ) + ] + , class "tab-pane" + , id "package-details-nixpkgs" + ] + [ pre [ class "code-block shell-command" ] [ text "nix-env -iA nixpkgs." , strong [] [ text item.source.attr_name ] ] @@ -581,12 +651,52 @@ viewResultItem nixosChannels channel showInstallDetails show item = , div [ classList [ ( "tab-pane", True ) - , ( "active", List.member showInstallDetails [ Search.Unset, Search.FromNixOS, Search.FromFlake ] ) + , ( "active", showInstallDetails == Search.ViaNixShell ) + ] + ] + [ p [] + [ text """ + A nix-shell will temporarily modify + your $PATH environment variable. + This can be used to try a piece of + software before deciding to + permanently install it. + """ + ] + ] + , div + [ classList + [ ( "active", showInstallDetails == Search.ViaNixShell ) + ] + , class "tab-pane" + , id "package-details-nixpkgs" + ] + [ pre [ class "code-block shell-command" ] + [ text "nix-shell -p " + , strong [] [ text item.source.attr_name ] + ] + ] + , div + [ classList + [ ( "tab-pane", True ) + , ( "active", List.member showInstallDetails [ Search.Unset, Search.ViaNixOS, Search.FromFlake ] ) + ] + ] + [ p [] + [ text "Add the following Nix code to your NixOS Configuration, usually located in " + , strong [] [ text "/etc/nixos/configuration.nix" ] + ] + ] + , div + [ classList + [ ( "tab-pane", True ) + , ( "active", List.member showInstallDetails [ Search.Unset, Search.ViaNixOS, Search.FromFlake ] ) ] ] [ pre [ class "code-block" ] - [ text <| "nix-env -iA nixos." + [ text <| " environment.systemPackages = [\n pkgs." , strong [] [ text item.source.attr_name ] + , text <| " \n ];" ] ] ] @@ -599,7 +709,7 @@ viewResultItem nixosChannels channel showInstallDetails show item = , ( "active", True ) ] ] - [ pre [ class "code-block" ] + [ pre [ class "code-block shell-command" ] [ text "nix build " , strong [] [ text url ] , text "#" @@ -611,12 +721,7 @@ viewResultItem nixosChannels channel showInstallDetails show item = <| Maybe.map Tuple.first item.source.flakeUrl ] - :: ((item.source.longDescription - |> Maybe.map (\desc -> [ p [] [ text desc ] ]) - |> Maybe.withDefault [] - ) - ++ maintainersAndPlatforms - ) + :: maintainersAndPlatforms ) ] diff --git a/frontend/src/Search.elm b/frontend/src/Search.elm index 8d2d0c5..6fe3320 100644 --- a/frontend/src/Search.elm +++ b/frontend/src/Search.elm @@ -384,8 +384,9 @@ type Msg a b type Details - = FromNixpkgs - | FromNixOS + = ViaNixShell + | ViaNixOS + | ViaNixEnv | FromFlake | Unset diff --git a/frontend/src/index.less b/frontend/src/index.less index dd42b9e..c97e971 100644 --- a/frontend/src/index.less +++ b/frontend/src/index.less @@ -6,10 +6,6 @@ background: #333; color: #fff; margin: 0; - - &:before { - content: "$ " - } } @@ -67,6 +63,10 @@ body { cursor: text; } +.shell-command:before { + content: "$ "; +} + #content { padding-bottom: 4rem; } @@ -388,8 +388,13 @@ header .navbar.navbar-static-top { margin: 2em 0 1em 1em; text-align: left; - // how to install a package + // long description of a package & > :nth-child(1) { + margin-top: 1em; + } + + // how to install a package + & > :nth-child(2) { h4 { font-size: 1.2em; @@ -417,11 +422,6 @@ header .navbar.navbar-static-top { } - // long description of a package - & > :nth-child(2) { - margin-top: 1em; - } - // maintainers and platforms & > :nth-child(3) { margin-top: 1em;