From 4e0e76fab6a934874b096404ed7602648f6062d4 Mon Sep 17 00:00:00 2001 From: matthewcroughan Date: Sat, 6 Aug 2022 23:44:36 +0100 Subject: [PATCH 1/3] encourage NixOS configuration, nix-shell and discourage nix-env --- frontend/src/Page/Packages.elm | 127 ++++++++++++++++++++++++++++++--- frontend/src/Search.elm | 5 +- frontend/src/index.less | 4 -- 3 files changed, 119 insertions(+), 17 deletions(-) diff --git a/frontend/src/Page/Packages.elm b/frontend/src/Page/Packages.elm index b6f744d9..c72db49e 100644 --- a/frontend/src/Page/Packages.elm +++ b/frontend/src/Page/Packages.elm @@ -515,7 +515,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 +523,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 +537,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,25 +582,116 @@ 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" ] + [ 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" ] + [ text "$ nix-env -iA nixpkgs." + , strong [] [ text item.source.attr_name ] + ] + ] + , div + [ classList + [ ( "tab-pane", True ) + , ( "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" ] - [ text "nix-env -iA nixpkgs." + [ text "$ nix-shell -p " , strong [] [ text item.source.attr_name ] ] ] , div [ classList [ ( "tab-pane", True ) - , ( "active", List.member showInstallDetails [ Search.Unset, Search.FromNixOS, Search.FromFlake ] ) + , ( "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 ];" ] ] ] @@ -600,7 +705,7 @@ viewResultItem nixosChannels channel showInstallDetails show item = ] ] [ pre [ class "code-block" ] - [ text "nix build " + [ text "$ nix build " , strong [] [ text url ] , text "#" , em [] [ text item.source.attr_name ] diff --git a/frontend/src/Search.elm b/frontend/src/Search.elm index 8d2d0c5c..6fe3320d 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 dd42b9e7..5b81de19 100644 --- a/frontend/src/index.less +++ b/frontend/src/index.less @@ -6,10 +6,6 @@ background: #333; color: #fff; margin: 0; - - &:before { - content: "$ " - } } From 5ad5a4c2b2ef31bfe7c4d0bba602a481ddaeb10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sun, 7 Aug 2022 18:50:33 +0200 Subject: [PATCH 2/3] move $ prompt to .shell-command:before So that it's not selected when you select the whole code block --- frontend/src/Page/Packages.elm | 16 ++++++++-------- frontend/src/index.less | 4 ++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/frontend/src/Page/Packages.elm b/frontend/src/Page/Packages.elm index c72db49e..16e3c039 100644 --- a/frontend/src/Page/Packages.elm +++ b/frontend/src/Page/Packages.elm @@ -616,8 +616,8 @@ viewResultItem nixosChannels channel showInstallDetails show item = , class "tab-pane" , id "package-details-nixpkgs" ] - [ pre [ class "code-block" ] - [ text "$ nix-env -iA nixos." + [ pre [ class "code-block shell-command" ] + [ text "nix-env -iA nixos." , strong [] [ text item.source.attr_name ] ] ] @@ -638,8 +638,8 @@ viewResultItem nixosChannels channel showInstallDetails show item = , class "tab-pane" , id "package-details-nixpkgs" ] - [ pre [ class "code-block" ] - [ text "$ nix-env -iA nixpkgs." + [ pre [ class "code-block shell-command" ] + [ text "nix-env -iA nixpkgs." , strong [] [ text item.source.attr_name ] ] ] @@ -666,8 +666,8 @@ viewResultItem nixosChannels channel showInstallDetails show item = , class "tab-pane" , id "package-details-nixpkgs" ] - [ pre [ class "code-block" ] - [ text "$ nix-shell -p " + [ pre [ class "code-block shell-command" ] + [ text "nix-shell -p " , strong [] [ text item.source.attr_name ] ] ] @@ -704,8 +704,8 @@ viewResultItem nixosChannels channel showInstallDetails show item = , ( "active", True ) ] ] - [ pre [ class "code-block" ] - [ text "$ nix build " + [ pre [ class "code-block shell-command" ] + [ text "nix build " , strong [] [ text url ] , text "#" , em [] [ text item.source.attr_name ] diff --git a/frontend/src/index.less b/frontend/src/index.less index 5b81de19..e8a93f36 100644 --- a/frontend/src/index.less +++ b/frontend/src/index.less @@ -63,6 +63,10 @@ body { cursor: text; } +.shell-command:before { + content: "$ "; +} + #content { padding-bottom: 4rem; } From 6e63a5d5dc4cc68d3ce9314786495a31b12cd75b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sun, 7 Aug 2022 19:34:19 +0200 Subject: [PATCH 3/3] move long description before installation instructions --- frontend/src/Page/Packages.elm | 12 ++++++------ frontend/src/index.less | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/frontend/src/Page/Packages.elm b/frontend/src/Page/Packages.elm index 16e3c039..f94c8f65 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 ] @@ -716,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/index.less b/frontend/src/index.less index e8a93f36..c97e971c 100644 --- a/frontend/src/index.less +++ b/frontend/src/index.less @@ -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;