Skip to content

Commit 42d326b

Browse files
committed
Sample environments test passing
1 parent 15c7d1c commit 42d326b

File tree

6 files changed

+27
-73
lines changed

6 files changed

+27
-73
lines changed

modules/base.nix

+1-41
Original file line numberDiff line numberDiff line change
@@ -29,49 +29,9 @@ with lib;
2929
default = {};
3030
};
3131

32-
builtShells = mkOption {
33-
type = types.attrsOf types.package;
34-
default = {};
35-
};
36-
3732
packages = mkOption {
38-
type = types.listOf types.package;
39-
default = [];
40-
example = literalExpression "[ pkgs.firefox pkgs.thunderbird ]";
41-
description = ''
42-
The set of packages that are symlinked into the environment.
43-
'';
44-
};
45-
46-
channels = mkOption {
47-
type = types.attrs;
33+
type = types.attrsOf types.package;
4834
default = {};
49-
description = ''
50-
Channels, passed through to UI metadata.
51-
'';
52-
};
53-
54-
labeledPackages = mkOption {
55-
type = types.listOf (types.submodule {
56-
options = {
57-
channel = mkOption rec {
58-
type = types.str;
59-
description = "Channel name";
60-
};
61-
attr = mkOption rec {
62-
type = types.str;
63-
description = "Attr name";
64-
};
65-
contents = mkOption rec {
66-
type = types.package;
67-
description = "Package";
68-
};
69-
};
70-
});
71-
default = [];
72-
description = ''
73-
Packages that are labeled with channels and attributes. Used to generate UI metadata.
74-
'';
7535
};
7636
};
7737

modules/shells/bash/module.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ with lib;
1414
};
1515

1616
config = mkIf config.shells.bash.enable {
17-
packages = [ (config.pkgs.callPackage ./. {}) ];
17+
packages = {
18+
"shells.bash" = config.pkgs.callPackage ./. {};
19+
};
1820
};
1921
}

modules/shells/fish/module.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ with lib;
1414
};
1515

1616
config = mkIf config.shells.fish.enable {
17-
packages = [(config.pkgs.callPackage ./. {})];
17+
packages = {
18+
"shells.fish" = config.pkgs.callPackage ./. {};
19+
};
1820
};
1921
}

modules/shells/zsh/module.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ with lib;
2020
};
2121

2222
config = mkIf config.shells.zsh.enable {
23-
packages = [ (config.pkgs.callPackage ./. {}) ];
23+
packages = {
24+
"shells.zsh" = config.pkgs.callPackage ./. {};
25+
};
2426
};
2527
}

nix/makeEnvironment.nix

+4-20
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ let
2727
passthru = old.passthru // {
2828
name = "kernels." + kernel.name;
2929

30-
# channel = kernel.channel;
31-
channel = "codedown";
32-
3330
settings = removeNonDefaultSettings kernel.settingsSchema kernel.settings;
3431
settingsSchema = mapAttrs (_: v: removeAttrs v ["loc"]) kernel.settingsSchema;
3532
};
@@ -68,35 +65,22 @@ in
6865
symlinkJoin {
6966
inherit name;
7067
paths =
71-
attrValues (evaluated.config.builtKernels)
72-
++ attrValues (evaluated.config.builtLanguageServers)
68+
attrValues evaluated.config.builtKernels
69+
++ attrValues evaluated.config.builtLanguageServers
7370
++ lib.optionals (builtins.length exporters > 0) [(writeTextDir "lib/codedown/exporters.yaml" (lib.generators.toYAML {} exporters))]
74-
++ evaluated.config.packages
75-
++ map (x: x.contents) evaluated.config.labeledPackages
71+
++ attrValues evaluated.config.packages
7672
;
7773

7874
passthru = rec {
7975
inherit evaluated;
8076

81-
inherit channels;
82-
8377
ui_metadata = {
84-
channels = lib.mapAttrsToList (name: channel: channel // {
85-
name = name;
86-
}) evaluated.config.channels;
87-
8878
packages =
8979
(mapAttrs' (n: v: nameValuePair "exporters.${n}" (mkPackageUiMetadata v)) builtExporters)
9080
// (mapAttrs' (n: v: nameValuePair "kernels.${n}" (mkPackageUiMetadata v)) builtKernels)
9181
// (mapAttrs' (n: v: nameValuePair "language-servers.${n}" (mkPackageUiMetadata v)) builtLanguageServers)
92-
// (listToAttrs (map (pkg: nameValuePair pkg.name (mkPackageUiMetadata pkg)) evaluated.config.packages))
82+
// (mapAttrs' (n: v: nameValuePair n (mkPackageUiMetadata v)) evaluated.config.packages)
9383
;
94-
95-
other_packages = map (p: {
96-
channel = p.channel;
97-
attr = p.attr;
98-
meta = if p.contents ? "meta" then uiMetadata.chooseInterestingMeta p.contents else {};
99-
}) evaluated.config.labeledPackages;
10084
};
10185

10286
ui_metadata_yaml = writeText "ui-metadata.yaml" (lib.generators.toYAML {} ui_metadata);

tests/app/Spec/Tests/SampleEnvironments.hs

+13-9
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import Control.Monad
77
import Control.Monad.IO.Class
88
import Control.Monad.Logger
99
import Data.Aeson as A
10+
import qualified Data.List as L
11+
import qualified Data.Map as M
1012
import Data.String.Interpolate
11-
import qualified Data.Text as T
13+
import Data.Text as T
1214
import qualified Data.Yaml as Yaml
1315
import System.FilePath
1416
import Test.Sandwich as Sandwich
@@ -22,7 +24,7 @@ import UnliftIO.Directory
2224
tests :: TopSpec
2325
tests = describe "Sample environments" $ introduceBootstrapNixpkgs $ introduceJustBubblewrap $ do
2426
parallelN 4 $
25-
forM_ fileList $ \file -> do
27+
forM_ (L.sort fileList) $ \file -> do
2628
describe [i|#{file}|] $ do
2729
it "Builds" $ do
2830
let name = T.dropEnd 4 (T.pack file) -- Drop the .nix suffix
@@ -31,22 +33,24 @@ tests = describe "Sample environments" $ introduceBootstrapNixpkgs $ introduceJu
3133

3234
it "Has well-formed UI metadata" $ do
3335
let name = T.dropEnd 4 (T.pack file) -- Drop the .nix suffix
34-
envRoot <- testBuildUsingFlake [i|.\#sample_environment_#{name}.ui_metadata_yaml|]
35-
info [i|Got metadata YAML: #{envRoot}|]
3636

37-
NixHydrationResult {..} <- liftIO (Yaml.decodeFileEither envRoot) >>= \case
37+
envRoot <- testBuildUsingFlake [i|.\#sample_environment_#{name}|]
38+
39+
yamlPath <- testBuildUsingFlake [i|.\#sample_environment_#{name}.ui_metadata_yaml|]
40+
NixHydrationResult {..} <- liftIO (Yaml.decodeFileEither yamlPath) >>= \case
3841
Left err -> expectationFailure [i|Couldn't decode UI metadata YAML: #{err}|]
3942
Right x -> pure x
4043
info [i|packages: #{A.encode nixHydrationResultPackages}|]
4144

42-
forM_ nixHydrationResultPackages (validatePackage envRoot)
45+
forM_ (M.toList nixHydrationResultPackages) (\(n, v) -> validatePackage envRoot n v)
4346

44-
validatePackage :: (MonadLoggerIO m, MonadFail m) => FilePath -> NixPackage -> m ()
45-
validatePackage envRoot (NixPackage {nixPackageMeta=(NixMeta {..}), ..}) = do
46-
when ("shells." `T.isPrefixOf` nixPackageName) $ do
47+
validatePackage :: (MonadLoggerIO m, MonadFail m) => FilePath -> Text -> NixPackage -> m ()
48+
validatePackage envRoot attr (NixPackage {nixPackageMeta=(NixMeta {..}), ..}) = do
49+
when ("shells." `T.isPrefixOf` attr) $ do
4750
info [i|(#{nixPackageName}) Shell detected; checking it has a mainProgram|]
4851
shouldBeJust nixMetaMainProgram
4952
Just program <- return nixMetaMainProgram
53+
info [i|(#{nixPackageName}) Checking for #{envRoot </> "bin" </> program}|]
5054
doesPathExist (envRoot </> "bin" </> program) >>= (`shouldBe` True)
5155

5256

0 commit comments

Comments
 (0)