-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBuildNix.hs
89 lines (80 loc) · 3.06 KB
/
BuildNix.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{-# LANGUAGE QuasiQuotes #-}
-- |
-- Copyright : (c) Crown Copyright GCHQ
-- Description : The code for build.nix
module Bootstrap.Data.Bootstrappable.BuildNix (BuildNix (unBuildNix), buildNixFor) where
import Bootstrap.Data.Bootstrappable
( Bootstrappable (bootstrapContent, bootstrapName, bootstrapReason),
bootstrapContentNix,
)
import Bootstrap.Data.ProjectName (ProjectName)
import Bootstrap.Data.ProjectType
( HaskellOptions (HaskellOptions),
HaskellProjectType (HaskellProjectTypeBasic),
JavaOptions (JavaOptions),
ProjectType
( Elm,
Go,
Haskell,
Java,
Minimal,
Node,
Python,
Rust
),
SetUpGoBuild (SetUpGoBuild),
SetUpHaskellBuild (SetUpHaskellBuild),
SetUpJavaBuild (SetUpJavaBuild),
)
import Bootstrap.Nix.Expr (Expr (EFunc), FunctionArgs (FASet), IsNixExpr (toNixExpr), nix)
import Bootstrap.Nix.Expr.ReproducibleBuild
( ReproducibleBuildExpr (ReproducibleBuildExpr, rbeExpr, rbeRequirements),
reproducibleBuildRequirementIdentifier,
)
import Bootstrap.Nix.Expr.ReproducibleBuild.Go (reproducibleGoBuild)
import Bootstrap.Nix.Expr.ReproducibleBuild.Haskell (reproducibleHaskellBuild)
import Bootstrap.Nix.Expr.ReproducibleBuild.Java (reproducibleJavaBuild)
import Bootstrap.Nix.Expr.ReproducibleBuild.Rust (reproducibleRustBuild)
-- | A separate nix file defining reproducible builds for flake projects,
-- to save it all being kept in flake.nix
newtype BuildNix = BuildNix {unBuildNix :: ReproducibleBuildExpr}
deriving stock (Eq, Show)
instance Bootstrappable BuildNix where
bootstrapName = const "nix/build.nix"
bootstrapReason = const "This configures your reproducible project builds."
bootstrapContent = bootstrapContentNix
instance IsNixExpr BuildNix where
toNixExpr (BuildNix ReproducibleBuildExpr {..}) =
EFunc
(FASet $ reproducibleBuildRequirementIdentifier <$> rbeRequirements)
rbeExpr
-- | Gives a `BuildNix` (or `Nothing`) as appropriate for the project details
-- given.
buildNixFor :: ProjectName -> ProjectType -> Maybe BuildNix
buildNixFor flakeNixProjectName flakeNixProjectType =
BuildNix
<$> buildExprFor SrcDirParent flakeNixProjectName flakeNixProjectType
-- | The source directory for the build
data SrcDir
= -- | src = ./.;
SrcDirCurrent
| -- | src = ../.;
SrcDirParent
srcDirExpr :: SrcDir -> Expr
srcDirExpr = \case
SrcDirCurrent -> [nix|./.|]
SrcDirParent -> [nix|../.|]
buildExprFor :: SrcDir -> ProjectName -> ProjectType -> Maybe ReproducibleBuildExpr
buildExprFor srcDir projectName = \case
Minimal -> Nothing
Elm _ -> Nothing
Haskell (HaskellOptions _ (HaskellProjectTypeBasic (SetUpHaskellBuild True))) ->
Just . reproducibleHaskellBuild projectName $ srcDirExpr srcDir
Haskell _ -> Nothing
Node _ -> Nothing
Go (SetUpGoBuild True) -> Just $ reproducibleGoBuild projectName
Go _ -> Nothing
Java (JavaOptions _ _ (SetUpJavaBuild artefactId) jdk) -> Just $ reproducibleJavaBuild projectName artefactId jdk
Java _ -> Nothing
Python _ -> Nothing
Rust -> Just . reproducibleRustBuild $ srcDirExpr srcDir